"use client"; import { RiCalendarCheckLine, RiLoader4Line } from "@remixicon/react"; import { useQueryClient } from "@tanstack/react-query"; import { installmentAnticipationsQueryKey, useInstallmentAnticipations, } from "@/features/transactions/hooks/use-installment-anticipations"; import { Button } from "@/shared/components/ui/button"; import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger, } from "@/shared/components/ui/dialog"; import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle, } from "@/shared/components/ui/empty"; import { useControlledState } from "@/shared/hooks/use-controlled-state"; import { AnticipationCard } from "../../shared/anticipation-card"; interface AnticipationHistoryDialogProps { trigger?: React.ReactNode; seriesId: string; lancamentoName: string; open?: boolean; onOpenChange?: (open: boolean) => void; onViewLancamento?: (transactionId: string) => void; } export function AnticipationHistoryDialog({ trigger, seriesId, lancamentoName, open, onOpenChange, onViewLancamento, }: AnticipationHistoryDialogProps) { const queryClient = useQueryClient(); const [dialogOpen, setDialogOpen] = useControlledState( open, false, onOpenChange, ); const { data: anticipations = [], isLoading, isError, refetch, } = useInstallmentAnticipations(seriesId, dialogOpen); const handleCanceled = () => { void queryClient.invalidateQueries({ queryKey: installmentAnticipationsQueryKey(seriesId), }); }; return ( {trigger && {trigger}} Histórico de Antecipações {lancamentoName}
{isLoading ? (
Carregando histórico...
) : isError ? ( Não foi possível carregar O histórico de antecipações não pôde ser carregado agora. ) : anticipations.length === 0 ? ( Nenhuma antecipação registrada As antecipações realizadas para esta compra parcelada aparecerão aqui. ) : ( anticipations.map((anticipation) => ( )) )}
{!isLoading && anticipations.length > 0 && (
{anticipations.length}{" "} {anticipations.length === 1 ? "antecipação encontrada" : "antecipações encontradas"}
)}
); }