/* eslint-disable react-refresh/only-export-components */ import { useGetIdentity, useGetList, useTranslate } from "ra-core"; import { useEffect, useState } from "react"; import { Button } from "@/components/ds/ui/button"; import { Dialog, DialogContent, DialogTitle } from "@/components/ds/ui/dialog"; import type { Deal } from "../types"; import { DealCardContent } from "./DealCard"; export const DealArchivedList = () => { const { identity } = useGetIdentity(); const translate = useTranslate(); const { data: archivedLists, total, isPending, } = useGetList("deals", { pagination: { page: 1, perPage: 1000 }, sort: { field: "archived_at", order: "DESC" }, filter: { "archived_at@not.is": null }, }); const [openDialog, setOpenDialog] = useState(false); useEffect(() => { if (!isPending && total === 0) { setOpenDialog(false); } }, [isPending, total]); useEffect(() => { setOpenDialog(false); }, [archivedLists]); if (!identity || isPending || !total || !archivedLists) return null; // Group archived lists by date const archivedListsByDate: { [date: string]: Deal[] } = archivedLists.reduce( (acc, deal) => { const date = new Date(deal.archived_at).toDateString(); if (!acc[date]) { acc[date] = []; } acc[date].push(deal); return acc; }, {} as { [date: string]: Deal[] }, ); return (