// @ts-nocheck
import React, { useRef } from 'react';
import classNames from 'classnames';
import {
Button,
Classes,
Intent,
Menu,
MenuItem,
ProgressBar,
Text,
} from '@blueprintjs/core';
import {
FormattedMessage as T,
Icon,
If,
Stack,
AppToaster,
} from '@/components';
import { useGeneralLedgerContext } from './GeneralLedgerProvider';
import FinancialLoadingBar from '../FinancialLoadingBar';
import { FinancialComputeAlert } from '../FinancialReportPage';
import {
useGeneralLedgerSheetCsvExport,
useGeneralLedgerSheetXlsxExport,
} from '@/hooks/query';
/**
* General ledger sheet alerts.
*/
export function GeneralLedgerSheetAlerts() {
const { generalLedger, isLoading, sheetRefresh } = useGeneralLedgerContext();
// Handle refetch the report sheet.
const handleRecalcReport = () => {
sheetRefresh();
};
// Can't display any error if the report is loading.
if (isLoading) {
return null;
}
// Can't continue if the cost compute job is not running.
if (!generalLedger.meta.is_cost_compute_running) {
return null;
}
return (
);
}
/**
* General ledger sheet loading bar.
*/
export function GeneralLedgerSheetLoadingBar() {
const { isFetching } = useGeneralLedgerContext();
return (
);
}
/**
* Renders the G/L sheet export menu.
* @returns {JSX.Element}
*/
export const GeneralLedgerSheetExportMenu = () => {
const toastKey = useRef(null);
const commonToastConfig = {
isCloseButtonShown: true,
timeout: 2000,
};
const { httpQuery } = useGeneralLedgerContext();
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 } = useGeneralLedgerSheetXlsxExport(
httpQuery,
{
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 } = useGeneralLedgerSheetCsvExport(httpQuery, {
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 (
);
};