import { formatDistance } from "date-fns"; import { FileText } from "lucide-react"; import { useGetIdentity, useGetList, useLocaleState, useTranslate, } from "ra-core"; import ReactMarkdown from "react-markdown"; import remarkGfm from "remark-gfm"; import { ReferenceField } from "@/components/ds/admin/reference-field"; import { TextField } from "@/components/ds/admin/text-field"; import { Card, CardContent } from "@/components/ds/ui/card"; import { getDateFnsLocale } from "@/i18n/date-fns"; import type { Contact, ContactNote } from "../types"; export const LatestNotes = () => { const { identity } = useGetIdentity(); const translate = useTranslate(); const [locale] = useLocaleState(); const dateFnsLocale = getDateFnsLocale(locale); const { data: contactNotesData, isPending: contactNotesLoading } = useGetList( "contactNotes", { pagination: { page: 1, perPage: 5 }, sort: { field: "date", order: "DESC" }, filter: { sales_id: identity?.id }, }, { enabled: Number.isInteger(identity?.id) }, ); const { data: dealNotesData, isPending: dealNotesLoading } = useGetList( "dealNotes", { pagination: { page: 1, perPage: 5 }, sort: { field: "date", order: "DESC" }, filter: { sales_id: identity?.id }, }, { enabled: Number.isInteger(identity?.id) }, ); if (contactNotesLoading || dealNotesLoading) { return null; } // TypeScript guards if (!contactNotesData || !dealNotesData) { return null; } const allNotes = ([] as any[]) .concat( contactNotesData.map((note) => ({ ...note, type: "contactNote", })), dealNotesData.map((note) => ({ ...note, type: "dealNote" })), ) .sort((a, b) => new Date(b.date).valueOf() - new Date(a.date).valueOf()) .slice(0, 5); return (