import { Avatar, Badge, Box, Card, Divider, Group, Stack, Text, } from "@mantine/core"; import { AtSign, Phone, ShieldAlert, UserRound } from "lucide-react"; import type { CustomerAccount } from "@/types/customer"; import { formatDate, humanize } from "./format"; /** First letters of the person's name; falls back to the login initial. */ function initials(account: CustomerAccount): string { const letters = [account.firstName, account.lastName] .map((n) => n?.trim()?.[0]) .filter(Boolean) .join(""); return (letters || account.username?.[0] || "?").toUpperCase(); } /** A labelled value; rendered only when there is something to show. */ function Field({ icon, label, value, after, }: { icon: React.ReactNode; label: string; value?: string | null; after?: React.ReactNode; }) { if (!value?.trim()) return null; return ( {icon} {label} {value} {after} ); } /** * One portal login belonging to a customer. * * Distinct from the contact details on the Overview tab: those are the business * contact info on the company row, this is the credential someone actually * signs in with โ€” the two drift apart routinely, and staff answering "the * customer can't log in" need this one. */ export function AccountCard({ account }: { account: CustomerAccount }) { const name = `${account.firstName ?? ""} ${account.lastName ?? ""}`.trim() || account.username || "Unnamed account"; // No IAM row at all โ€” the profile points at a user that is gone. Treated as a // fault rather than a status: nothing below it can be trusted, so the card // says so once, loudly, instead of drawing empty credential fields. const orphaned = account.username === null; return ( {initials(account)} {name} {account.isPrimaryContact && ( Primary contact )} {account.jobTitle && ( {account.jobTitle} )} {orphaned ? ( } > No IAM account ) : ( <> {account.isActive ? "Active" : "Inactive"} {account.status && ( {humanize(account.status)} )} {/* Created but never activated by its owner โ€” usually the actual answer to "they say they never got in". */} {account.hasSetPassword === false && ( Password never set )} )} {account.onboardingCompleted ? ( Onboarding submitted ) : ( Onboarding {account.onboardingStep ? ` ยท ${humanize(account.onboardingStep)}` : " in progress"} )} {!orphaned && ( <> } label="Username" value={account.username} /> } label="Email" value={account.email} /> } label="Phone" value={account.phoneNumber} after={ account.phoneVerified === false ? ( Unverified ) : undefined } /> )} Created {formatDate(account.createdAt)} ); } export default AccountCard;