// @ts-nocheck import React, { useRef } from 'react'; import classNames from 'classnames'; import { Classes, Intent, Menu, MenuItem, ProgressBar, Text, } from '@blueprintjs/core'; import { useARAgingSummaryContext } from './ARAgingSummaryProvider'; import { AppToaster, If, Stack, FormattedMessage as T } from '@/components'; import FinancialLoadingBar from '../FinancialLoadingBar'; import { agingSummaryDynamicColumns } from '../AgingSummary/dynamicColumns'; import { useARAgingSheetCsvExport, useARAgingSheetXlsxExport, } from '@/hooks/query'; /** * Retrieve AR aging summary columns. */ export const useARAgingSummaryColumns = () => { const { ARAgingSummary: { table }, } = useARAgingSummaryContext(); return agingSummaryDynamicColumns(table.columns, table.rows); }; /** * A/R aging summary sheet loading bar. */ export function ARAgingSummarySheetLoadingBar() { const { isARAgingFetching } = useARAgingSummaryContext(); return ( ); } /** * A/R aging summary export menu. * @returns {JSX.Element} */ export function ARAgingSummaryExportMenu() { const toastKey = useRef(null); const commonToastConfig = { isCloseButtonShown: true, timeout: 2000, }; const { query } = useARAgingSummaryContext(); const openProgressToast = (amount: number) => { return ( The report has been exported successfully. = 100, })} intent={amount < 100 ? Intent.PRIMARY : Intent.SUCCESS} value={amount / 100} /> ); }; // Export the report to xlsx. const { mutateAsync: xlsxExport } = useARAgingSheetXlsxExport(query, { onDownloadProgress: (xlsxExportProgress: number) => { if (!toastKey.current) { toastKey.current = AppToaster.show({ message: openProgressToast(xlsxExportProgress), ...commonToastConfig, }); } else { AppToaster.show( { message: openProgressToast(xlsxExportProgress), ...commonToastConfig, }, toastKey.current, ); } }, }); // Export the report to csv. const { mutateAsync: csvExport } = useARAgingSheetCsvExport(query, { onDownloadProgress: (xlsxExportProgress: number) => { if (!toastKey.current) { toastKey.current = AppToaster.show({ message: openProgressToast(xlsxExportProgress), ...commonToastConfig, }); } else { AppToaster.show( { message: openProgressToast(xlsxExportProgress), ...commonToastConfig, }, toastKey.current, ); } }, }); // Handle csv export button click. const handleCsvExportBtnClick = () => { csvExport(); }; // Handle xlsx export button click. const handleXlsxExportBtnClick = () => { xlsxExport(); }; return ( ); }