From 8da5959d90d0421ffdbcd8fc9e5638890e2bfa85 Mon Sep 17 00:00:00 2001 From: "MSI\\2Fi" Date: Tue, 10 Dec 2024 16:35:56 +0800 Subject: [PATCH] Add loading when import load of invoice information --- .../InvoiceSearch/InvoiceSearch.tsx | 61 +++++++++++++------ .../InvoiceSearch/InvoiceSearchLoading.tsx | 6 +- 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/src/components/InvoiceSearch/InvoiceSearch.tsx b/src/components/InvoiceSearch/InvoiceSearch.tsx index 1accede..6216c62 100644 --- a/src/components/InvoiceSearch/InvoiceSearch.tsx +++ b/src/components/InvoiceSearch/InvoiceSearch.tsx @@ -21,6 +21,7 @@ import { uniq } from "lodash"; import CreateInvoiceModal from "./CreateInvoiceModal"; import { ProjectResult } from "@/app/api/projects"; import { IMPORT_INVOICE, IMPORT_RECEIPT } from "@/middleware"; +import InvoiceSearchLoading from "./InvoiceSearchLoading"; @@ -41,13 +42,17 @@ type invoiceListRow = Partial< } >; +interface SubComponents { + Loading: typeof InvoiceSearchLoading; +} + type SearchQuery = Partial>; type SearchParamNames = keyof SearchQuery; type SearchQuery2 = Partial>; type SearchParamNames2 = keyof SearchQuery2; -const InvoiceSearch: React.FC = ({ invoices, projects, abilities }) => { +const InvoiceSearch: React.FC & SubComponents = ({ invoices, projects, abilities }) => { console.log(abilities) const { t } = useTranslation("Invoice"); @@ -96,18 +101,22 @@ const InvoiceSearch: React.FC = ({ invoices, projects, abilities }) => { return; } + setLoading(true) const formData = new FormData(); formData.append('multipartFileList', file); const response = await importIssuedInovice(formData); + // response: status, message, projectList, emptyRowList, invoiceList if (response.status) { successDialog(t("Import Success"), t).then(() => { + setLoading(false) window.location.reload(); }); } else { handleImportError(response); + setLoading(false) } } catch (err) { console.log(err); @@ -177,6 +186,7 @@ const InvoiceSearch: React.FC = ({ invoices, projects, abilities }) => { const formData = new FormData(); formData.append('multipartFileList', file); + setLoading(true) const response = await importReceivedInovice(formData) console.log(response) @@ -185,6 +195,7 @@ const InvoiceSearch: React.FC = ({ invoices, projects, abilities }) => { successDialog(t("Import Success"), t).then(() => { window.location.reload() }) + setLoading(false) }else{ if (response.emptyRowList.length >= 1){ errorDialogWithContent(t("Import Fail"), @@ -220,6 +231,7 @@ const InvoiceSearch: React.FC = ({ invoices, projects, abilities }) => { window.location.reload() }) } + setLoading(false) } }catch(error){ console.log(error) @@ -423,10 +435,14 @@ const InvoiceSearch: React.FC = ({ invoices, projects, abilities }) => { return importRight } + const [loading, setLoading] = React.useState(false); + return ( <> - + {loading && } + { + !loading && isAddInvoiceRightExist() && = ({ invoices, projects, abilities }) => { } { + !loading && // tabIndex == 0 && = ({ invoices, projects, abilities }) => { onReset={onReset} /> } + + + { + !loading && + <> + + + + + {t('Total Issued Amount (HKD)')}: + {moneyFormatter.format(filteredIvoices.reduce((acc, current) => (acc + current.issuedAmount), 0))} + + + {t('Total Received Amount (HKD)')}: + {moneyFormatter.format(filteredIvoices.reduce((acc, current) => (acc + current.receivedAmount), 0))} + + + + + + } + - - - - - {t('Total Issued Amount (HKD)')}: - {moneyFormatter.format(filteredIvoices.reduce((acc, current) => (acc + current.issuedAmount), 0))} - - - {t('Total Received Amount (HKD)')}: - {moneyFormatter.format(filteredIvoices.reduce((acc, current) => (acc + current.receivedAmount), 0))} - - - - - { + !loading && // tabIndex == 0 && items={filteredIvoices} @@ -586,4 +611,6 @@ const InvoiceSearch: React.FC = ({ invoices, projects, abilities }) => { ); }; +InvoiceSearch.Loading = InvoiceSearchLoading; + export default InvoiceSearch; diff --git a/src/components/InvoiceSearch/InvoiceSearchLoading.tsx b/src/components/InvoiceSearch/InvoiceSearchLoading.tsx index e2cc58d..e2b1400 100644 --- a/src/components/InvoiceSearch/InvoiceSearchLoading.tsx +++ b/src/components/InvoiceSearch/InvoiceSearchLoading.tsx @@ -5,7 +5,7 @@ import Stack from "@mui/material/Stack"; import React from "react"; // Can make this nicer -export const SalarySearchLoading: React.FC = () => { +export const InvoiceSearchLoading: React.FC = () => { return ( <> @@ -23,7 +23,7 @@ export const SalarySearchLoading: React.FC = () => { - Salary + @@ -37,4 +37,4 @@ export const SalarySearchLoading: React.FC = () => { ); }; -export default SalarySearchLoading; +export default InvoiceSearchLoading;