feat(client): redesign detail header with action chips + condensed meta
Replaces the inline "Source · email · phone" text strip with three primary action chips and a smaller meta line: Mail / Call / WhatsApp action buttons surface the most-used outbound contacts on a single tap. WhatsApp deep-link strips the leading + from the canonical E.164 number (or falls back to digit-only of the value). Meta line now reads "Country · Added MMM d, yyyy" using nationalityIso resolved through getCountryName(); date-fns formats createdAt. Portal Invite + GDPR Export buttons remain available but only render on sm+; on mobile they're reachable through the More sheet. Archive / Restore is now a small icon button in the top-right corner rather than a labeled button competing with the primary action chips. Destructive intent stays out of the main action flow; hover swaps to destructive color for archive (and stays neutral for restore). The previous source/preferred-contact-method/preferred-language/timezone fields no longer render in the header — they live on the Overview tab via the inline editor pattern (see client-tabs.tsx). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -2,7 +2,8 @@
|
|||||||
|
|
||||||
import { useState } from 'react';
|
import { useState } from 'react';
|
||||||
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
import { useMutation, useQueryClient } from '@tanstack/react-query';
|
||||||
import { Archive, RotateCcw, Mail, Phone } from 'lucide-react';
|
import { Archive, Mail, MessageCircle, Phone, RotateCcw } from 'lucide-react';
|
||||||
|
import { format } from 'date-fns';
|
||||||
|
|
||||||
import { Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import { Badge } from '@/components/ui/badge';
|
import { Badge } from '@/components/ui/badge';
|
||||||
@@ -12,31 +13,28 @@ import { DetailHeaderStrip } from '@/components/shared/detail-header-strip';
|
|||||||
import { PortalInviteButton } from '@/components/clients/portal-invite-button';
|
import { PortalInviteButton } from '@/components/clients/portal-invite-button';
|
||||||
import { GdprExportButton } from '@/components/clients/gdpr-export-button';
|
import { GdprExportButton } from '@/components/clients/gdpr-export-button';
|
||||||
import { apiFetch } from '@/lib/api/client';
|
import { apiFetch } from '@/lib/api/client';
|
||||||
|
import { cn } from '@/lib/utils';
|
||||||
|
import { getCountryName } from '@/lib/i18n/countries';
|
||||||
|
|
||||||
interface ClientDetailHeaderProps {
|
interface ClientDetailHeaderProps {
|
||||||
client: {
|
client: {
|
||||||
id: string;
|
id: string;
|
||||||
fullName: string;
|
fullName: string;
|
||||||
nationality?: string | null;
|
nationalityIso?: string | null;
|
||||||
preferredContactMethod?: string | null;
|
|
||||||
preferredLanguage?: string | null;
|
|
||||||
timezone?: string | null;
|
|
||||||
source?: string | null;
|
|
||||||
sourceDetails?: string | null;
|
|
||||||
archivedAt?: string | null;
|
archivedAt?: string | null;
|
||||||
contacts?: Array<{ channel: string; value: string; isPrimary: boolean; label?: string | null }>;
|
createdAt?: string;
|
||||||
|
contacts?: Array<{
|
||||||
|
channel: string;
|
||||||
|
value: string;
|
||||||
|
valueE164?: string | null;
|
||||||
|
isPrimary: boolean;
|
||||||
|
label?: string | null;
|
||||||
|
}>;
|
||||||
tags?: Array<{ id: string; name: string; color: string }>;
|
tags?: Array<{ id: string; name: string; color: string }>;
|
||||||
clientPortalEnabled?: boolean;
|
clientPortalEnabled?: boolean;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const SOURCE_LABELS: Record<string, string> = {
|
|
||||||
website: 'Website',
|
|
||||||
manual: 'Manual',
|
|
||||||
referral: 'Referral',
|
|
||||||
broker: 'Broker',
|
|
||||||
};
|
|
||||||
|
|
||||||
export function ClientDetailHeader({ client }: ClientDetailHeaderProps) {
|
export function ClientDetailHeader({ client }: ClientDetailHeaderProps) {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
const [archiveOpen, setArchiveOpen] = useState(false);
|
const [archiveOpen, setArchiveOpen] = useState(false);
|
||||||
@@ -62,19 +60,34 @@ export function ClientDetailHeader({ client }: ClientDetailHeaderProps) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const primaryEmail =
|
const primaryEmail =
|
||||||
client.contacts?.find((c) => c.channel === 'email' && c.isPrimary) ??
|
client.contacts?.find((c) => c.channel === 'email' && c.isPrimary)?.value ??
|
||||||
client.contacts?.find((c) => c.channel === 'email');
|
client.contacts?.find((c) => c.channel === 'email')?.value;
|
||||||
const primaryPhone =
|
const primaryPhoneContact =
|
||||||
client.contacts?.find((c) => c.channel === 'phone' && c.isPrimary) ??
|
client.contacts?.find((c) => c.channel === 'phone' && c.isPrimary) ??
|
||||||
client.contacts?.find((c) => c.channel === 'phone');
|
client.contacts?.find((c) => c.channel === 'phone');
|
||||||
|
const primaryPhone = primaryPhoneContact?.value;
|
||||||
|
// wa.me requires the E.164 number without the leading "+". Strip from the
|
||||||
|
// canonical E.164 form when available; otherwise strip non-digits from the
|
||||||
|
// display value as a best-effort fallback.
|
||||||
|
const whatsappNumber = primaryPhoneContact?.valueE164
|
||||||
|
? primaryPhoneContact.valueE164.replace(/^\+/, '')
|
||||||
|
: primaryPhoneContact?.value
|
||||||
|
? primaryPhoneContact.value.replace(/[^\d]/g, '')
|
||||||
|
: null;
|
||||||
|
|
||||||
|
const country = client.nationalityIso ? getCountryName(client.nationalityIso, 'en') : null;
|
||||||
|
const addedLabel = client.createdAt
|
||||||
|
? `Added ${format(new Date(client.createdAt), 'MMM d, yyyy')}`
|
||||||
|
: null;
|
||||||
|
const meta = [country, addedLabel].filter(Boolean) as string[];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<DetailHeaderStrip>
|
<DetailHeaderStrip>
|
||||||
<div className="flex items-start gap-3 flex-wrap">
|
<div className="flex items-start gap-3">
|
||||||
<div className="flex-1 min-w-0">
|
<div className="min-w-0 flex-1 space-y-2">
|
||||||
<div className="flex items-center gap-2 flex-wrap">
|
<div className="flex items-center gap-2 flex-wrap">
|
||||||
<h1 className="hidden sm:block text-2xl font-bold text-foreground truncate">
|
<h1 className="truncate text-lg font-bold text-foreground sm:text-2xl">
|
||||||
{client.fullName}
|
{client.fullName}
|
||||||
</h1>
|
</h1>
|
||||||
{isArchived && (
|
{isArchived && (
|
||||||
@@ -84,31 +97,71 @@ export function ClientDetailHeader({ client }: ClientDetailHeaderProps) {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="flex items-center gap-4 mt-2 flex-wrap text-sm text-muted-foreground">
|
{meta.length > 0 ? (
|
||||||
{client.source && (
|
<p className="text-xs text-muted-foreground sm:text-sm">{meta.join(' · ')}</p>
|
||||||
<span>
|
) : null}
|
||||||
Source:{' '}
|
|
||||||
<span className="text-foreground">
|
<div className="flex flex-wrap items-center gap-1.5 pt-1">
|
||||||
{SOURCE_LABELS[client.source] ?? client.source}
|
{primaryEmail ? (
|
||||||
</span>
|
<Button
|
||||||
</span>
|
asChild
|
||||||
)}
|
variant="outline"
|
||||||
{primaryEmail && (
|
size="sm"
|
||||||
<span className="flex items-center gap-1">
|
className="h-8 gap-1.5 px-2.5 [&_svg]:size-3.5"
|
||||||
<Mail className="h-3.5 w-3.5" />
|
>
|
||||||
{primaryEmail.value}
|
<a href={`mailto:${primaryEmail}`} aria-label={`Email ${primaryEmail}`}>
|
||||||
</span>
|
<Mail />
|
||||||
)}
|
Email
|
||||||
{primaryPhone && (
|
</a>
|
||||||
<span className="flex items-center gap-1">
|
</Button>
|
||||||
<Phone className="h-3.5 w-3.5" />
|
) : null}
|
||||||
{primaryPhone.value}
|
{primaryPhone ? (
|
||||||
</span>
|
<Button
|
||||||
)}
|
asChild
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
className="h-8 gap-1.5 px-2.5 [&_svg]:size-3.5"
|
||||||
|
>
|
||||||
|
<a href={`tel:${primaryPhone}`} aria-label={`Call ${primaryPhone}`}>
|
||||||
|
<Phone />
|
||||||
|
Call
|
||||||
|
</a>
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
|
{whatsappNumber ? (
|
||||||
|
<Button
|
||||||
|
asChild
|
||||||
|
variant="outline"
|
||||||
|
size="sm"
|
||||||
|
className="h-8 gap-1.5 px-2.5 [&_svg]:size-3.5"
|
||||||
|
>
|
||||||
|
<a
|
||||||
|
href={`https://wa.me/${whatsappNumber}`}
|
||||||
|
target="_blank"
|
||||||
|
rel="noopener noreferrer"
|
||||||
|
aria-label={`Message ${primaryPhone} on WhatsApp`}
|
||||||
|
>
|
||||||
|
<MessageCircle />
|
||||||
|
WhatsApp
|
||||||
|
</a>
|
||||||
|
</Button>
|
||||||
|
) : null}
|
||||||
|
{!isArchived && client.clientPortalEnabled !== false ? (
|
||||||
|
<div className="hidden sm:inline-flex">
|
||||||
|
<PortalInviteButton
|
||||||
|
clientId={client.id}
|
||||||
|
clientName={client.fullName}
|
||||||
|
defaultEmail={primaryEmail}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
) : null}
|
||||||
|
<div className="hidden sm:inline-flex">
|
||||||
|
<GdprExportButton clientId={client.id} />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{client.tags && client.tags.length > 0 && (
|
{client.tags && client.tags.length > 0 && (
|
||||||
<div className="flex flex-wrap gap-1 mt-2">
|
<div className="flex flex-wrap gap-1">
|
||||||
{client.tags.map((tag) => (
|
{client.tags.map((tag) => (
|
||||||
<TagBadge key={tag.id} name={tag.name} color={tag.color} />
|
<TagBadge key={tag.id} name={tag.name} color={tag.color} />
|
||||||
))}
|
))}
|
||||||
@@ -116,34 +169,21 @@ export function ClientDetailHeader({ client }: ClientDetailHeaderProps) {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Actions */}
|
{/* Top-right: archive/restore as a small icon button — destructive
|
||||||
<div className="flex flex-wrap items-center gap-2">
|
action sits out of the primary action flow. */}
|
||||||
{!isArchived && client.clientPortalEnabled !== false && (
|
<button
|
||||||
<PortalInviteButton
|
type="button"
|
||||||
clientId={client.id}
|
|
||||||
clientName={client.fullName}
|
|
||||||
defaultEmail={primaryEmail?.value}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
<GdprExportButton clientId={client.id} />
|
|
||||||
<Button
|
|
||||||
variant={isArchived ? 'outline' : 'outline'}
|
|
||||||
size="sm"
|
|
||||||
onClick={() => setArchiveOpen(true)}
|
onClick={() => setArchiveOpen(true)}
|
||||||
>
|
aria-label={isArchived ? 'Restore client' : 'Archive client'}
|
||||||
{isArchived ? (
|
title={isArchived ? 'Restore client' : 'Archive client'}
|
||||||
<>
|
className={cn(
|
||||||
<RotateCcw className="mr-1.5 h-3.5 w-3.5" />
|
'shrink-0 rounded-md p-1.5 text-muted-foreground/70 transition-colors',
|
||||||
Restore
|
'hover:bg-foreground/5 hover:text-foreground',
|
||||||
</>
|
isArchived ? 'hover:text-foreground' : 'hover:text-destructive',
|
||||||
) : (
|
|
||||||
<>
|
|
||||||
<Archive className="mr-1.5 h-3.5 w-3.5" />
|
|
||||||
Archive
|
|
||||||
</>
|
|
||||||
)}
|
)}
|
||||||
</Button>
|
>
|
||||||
</div>
|
{isArchived ? <RotateCcw className="size-4" /> : <Archive className="size-4" />}
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</DetailHeaderStrip>
|
</DetailHeaderStrip>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user