import { formatRelative } from "date-fns"; import { RecordContextProvider, useListContext, useTranslate } from "ra-core"; import { type MouseEvent, useCallback } from "react"; import { Link } from "react-router"; import { ReferenceField } from "@/components/ds/admin/reference-field"; import { TextField } from "@/components/ds/admin/text-field"; import { Checkbox } from "@/components/ds/ui/checkbox"; import { Skeleton } from "@/components/ds/ui/skeleton"; import { useIsMobile } from "@/hooks/use-mobile"; import { Status } from "../misc/Status"; import type { Contact } from "../types"; import { Avatar } from "./Avatar"; import { TagsList } from "./TagsList"; export const ContactListContent = () => { const { data: contacts, error, isPending, onToggleItem, selectedIds, } = useListContext(); const isSmall = useIsMobile(); const translate = useTranslate(); // StopPropagation does not work for some reason on Checkbox, this handler is a workaround const handleLinkClick = useCallback(function handleLinkClick( e: MouseEvent, ) { if (e.target instanceof HTMLButtonElement) { e.preventDefault(); } }, []); if (isPending) { return ; } if (error) { return null; } const now = Date.now(); return (
{contacts.map((contact) => ( onToggleItem(contact.id)} />
{`${contact.first_name} ${contact.last_name ?? ""}`}
{contact.title} {contact.title && contact.company_id != null && ` ${translate("crm.contact.field.at")} `} {contact.company_id != null && ( )} {contact.nb_tasks ? ` - ${translate("common.tasks", { count: contact.nb_tasks, })}` : ""}   
{contact.last_seen && (
{!isSmall && `${translate("resources.contacts.fields.last_seen").toLowerCase()} `} {formatRelative(contact.last_seen, now)}{" "}
)}
))} {contacts.length === 0 && (
{translate("crm.contact.empty.title")}
)}
); };