- Added support for deduplication of orders based on the `email_message_id`, preventing duplicate entries during email intake. - Introduced the `displayContactName` utility to sanitize and format contact names, improving the display of order details by removing extraneous whitespace. - Updated relevant order-related components to utilize the new utility for consistent contact name rendering. - Enhanced tests to cover the new deduplication logic and the functionality of the `displayContactName` utility, ensuring robust behavior in various scenarios.
30 lines
1.3 KiB
TypeScript
30 lines
1.3 KiB
TypeScript
import { clsx, type ClassValue } from "clsx"
|
|
import { twMerge } from "tailwind-merge"
|
|
|
|
export function cn(...inputs: ClassValue[]) {
|
|
return twMerge(clsx(inputs))
|
|
}
|
|
|
|
/**
|
|
* Sanitise an order's `contact_name` for display.
|
|
*
|
|
* The field is populated by an LLM during email intake and historically
|
|
* contains incidental whitespace from the model output (newlines, trailing
|
|
* spaces, lone "\n" strings, etc.). The list-page render uses a
|
|
* truthy-check on the raw field, so a stray "\n" produces a dangling
|
|
* separator dot with no actual name — visually a "miss" even though
|
|
* the field is non-empty.
|
|
*
|
|
* This helper trims, normalises internal whitespace, and returns ""
|
|
* for any falsy / whitespace-only input. The caller can then keep the
|
|
* existing `displayContact && <span>...</span>` pattern and get a
|
|
* clean render. Search/export code that wants the raw value should keep
|
|
* reading `order.contact_name` directly.
|
|
*/
|
|
export function displayContactName(raw: string | null | undefined): string {
|
|
if (typeof raw !== "string") return "";
|
|
// Collapse any whitespace run (including \n) to a single space, then
|
|
// trim. Mirrors the kind of clean the AI insights post-processor does
|
|
// for names — it's cheap and deterministic.
|
|
return raw.replace(/\s+/g, " ").trim();
|
|
}
|