// @ts-nocheck
import { useMemo, useRef } from 'react';
import intl from 'react-intl-universal';
import classNames from 'classnames';
import { Classes } from '@blueprintjs/core';
import { getColumnWidth } from '@/utils';
import { AppToaster, If, Stack } from '@/components';
import { Align } from '@/constants';
import { CellTextSpan } from '@/components/Datatable/Cells';
import { useSalesByItemsContext } from './SalesByItemProvider';
import FinancialLoadingBar from '../FinancialLoadingBar';
import { Intent, Menu, MenuItem, ProgressBar, Text } from '@blueprintjs/core';
import {
useSalesByItemsCsvExport,
useSalesByItemsXlsxExport,
} from '@/hooks/query';
/**
* sales by items progress loading bar.
*/
export function SalesByItemsLoadingBar() {
const { isFetching } = useSalesByItemsContext();
return (
);
}
/**
* Retrieves the sales by items export menu.
* @returns {JSX.Element}
*/
export const SalesByItemsSheetExportMenu = () => {
const toastKey = useRef(null);
const commonToastConfig = {
isCloseButtonShown: true,
timeout: 2000,
};
const { query } = useSalesByItemsContext();
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 } = useSalesByItemsXlsxExport(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 } = useSalesByItemsCsvExport(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 (
);
};