import { DownloadIcon, FilePenLineIcon } from "lucide-react"; import { ColorBadge } from "@/components"; import { useCustomLocalization } from "@/lib/hooks"; import { cn } from "@/lib/utils"; import { Button, Card, CardContent, CardFooter, CardHeader, CardTitle, Separator, Tabs, TabsContent, TabsList, TabsTrigger, Tooltip, TooltipContent, TooltipTrigger, } from "@/ui"; import { useToast } from "@/ui/use-toast"; import { formatDateToYYYYMMDD } from "@shared/utilities/helpers"; import { t } from "i18next"; import { useCallback, useMemo } from "react"; import { useNavigate } from "react-router-dom"; import { useQuotes } from "../hooks"; import { DownloadQuoteDialog } from "./DownloadQuoteDialog"; import { QuotePDFPreview } from "./QuotePDFPreview"; import { QuoteSentToEditor, QuoteStatusEditor } from "./editors"; type QuoteResumeProps = { quoteId?: string; className?: string; }; export const QuoteResume = ({ quoteId, className }: QuoteResumeProps) => { const navigate = useNavigate(); const { toast } = useToast(); const { useOne, useSetStatus, useSentTo, useDownloader, getQuotePDFFilename } = useQuotes(); const { data, status } = useOne(quoteId); const { mutate: setStatusMutation } = useSetStatus(quoteId); const { mutate: sentToMutation } = useSentTo(quoteId); const { download, ...downloadProps } = useDownloader(); const { formatCurrency, formatNumber } = useCustomLocalization({ locale: data?.lang_code || "ES", }); /*const currency_symbol = useMemo(() => { const currencyOrError = data ? CurrencyData.createFromCode(data?.currency_code) : CurrencyData.createDefaultCode(); return currencyOrError.isSuccess ? currencyOrError.object.symbol : ""; }, [data]);*/ const totals = useMemo(() => { return data ? { subtotal_price: formatCurrency(data.subtotal_price), discount: formatNumber(data.discount), discount_price: formatCurrency(data.discount_price), tax: formatNumber(data.tax), tax_price: formatCurrency(data.tax_price), total_price: formatCurrency(data.total_price), } : { subtotal_price: "0,00 €", discount: "0", discount_price: "0,00 €", tax: "0", tax_price: "0,00 €", total_price: "0,00 €", }; }, [data]); const allowToSent = useMemo(() => data?.status === "accepted" && !data?.date_sent, [data]); const isSent = useMemo(() => data?.status === "accepted" && data?.date_sent, [data]); const handleOnChangeStatus = (_: string, newStatus: string) => { setStatusMutation( { newStatus }, { onSuccess: () => { toast({ description: t("quotes.quote_status_editor.toast_status_changed"), }); }, } ); }; const handleOnSentTo = (_: string) => { sentToMutation( { sent_date: formatDateToYYYYMMDD(new Date()) }, { onSuccess: () => { toast({ description: t("quotes.quote_sent_to_editor.toast_status_changed"), }); }, } ); }; const handleFinishDownload = useCallback(() => { toast({ description: t("quotes.downloading_dialog.toast_success"), }); }, [toast]); const handleDownload = useCallback(() => { if (data) download(data.id, getQuotePDFFilename(data)); }, [data]); if (status === "error") { return null; } if (status !== "success") { return null; } if (!data) { return ( Select a quote ); } return ( <> {t("quotes.list.resume.title")} {allowToSent && !isSent && ( <> > )} {!isSent && ( <> { e.preventDefault(); navigate(`/quotes/edit/${data.id}`, { relative: "path" }); }} > {t("quotes.list.columns.actions.edit")} > )} {t("quotes.list.resume.download_quote")} {t("quotes.list.resume.download_quote")} {/* {t("common.more")} {t("common.more")} {t("quotes.list.preview.download_quote")} */} {t("quotes.list.resume.tabs.resume")} {t("quotes.list.resume.tabs.preview")} {t("quotes.list.resume.quote_information")} {t("quotes.form_fields.reference.label")} {data.reference} {t("quotes.form_fields.date.label")} {new Date(data.date).toLocaleDateString()} {t("quotes.form_fields.customer_reference.label")} {data.customer_reference} {t("quotes.list.resume.customer_information")} {data.customer_information} {t("quotes.list.resume.price_information")} {t("quotes.form_fields.subtotal_price.label")} {totals.subtotal_price} {t("quotes.form_fields.discount_value.label", { value: totals.discount })} {totals.discount_price} {t("quotes.form_fields.tax_value.label", { value: totals.tax })} {totals.tax_price} {t("quotes.form_fields.total_price.label")} {totals.total_price} > ); };
Select a quote