perf: invoice page refresh after apply (#2469)

* perf: 发票申请弹窗成功后刷新

* refactor: 组件内拿invoiceTab
This commit is contained in:
papapatrick
2024-08-22 12:24:33 +08:00
committed by GitHub
parent 225554f22c
commit 366fe0eada
3 changed files with 35 additions and 16 deletions

View File

@@ -31,6 +31,7 @@ import { InvoiceHeaderSingleForm } from './InvoiceHeaderForm';
import MyBox from '@fastgpt/web/components/common/MyBox';
import { getTeamInvoiceHeader } from '@/web/support/user/team/api';
import { useToast } from '@fastgpt/web/hooks/useToast';
import { useRouter } from 'next/router';
type chosenBillDataType = {
_id: string;
price: number;
@@ -50,6 +51,8 @@ const ApplyInvoiceModal = ({ onClose }: { onClose: () => void }) => {
needSpecialInvoice: undefined,
emailAddress: ''
});
const router = useRouter();
const {
isOpen: isOpenSettleModal,
onOpen: onOpenSettleModal,
@@ -94,7 +97,10 @@ const ApplyInvoiceModal = ({ onClose }: { onClose: () => void }) => {
manual: true,
successToast: t('common:common.submit_success'),
errorToast: t('common:common.Submit failed'),
onSuccess: () => onClose()
onSuccess: () => {
onClose();
router.reload();
}
}
);

View File

@@ -4,19 +4,20 @@ import dynamic from 'next/dynamic';
import { useState } from 'react';
import { useTranslation } from 'next-i18next';
import ApplyInvoiceModal from './ApplyInvoiceModal';
import { useRouter } from 'next/router';
const TabEnum = {
export const InvoiceTabEnum = {
bill: 'bill',
invoice: 'invoice',
invoiceHeader: 'voiceHeader'
invoiceHeader: 'invoiceHeader'
};
const BillTable = dynamic(() => import('./BillTable'));
const InvoiceHeaderForm = dynamic(() => import('./InvoiceHeaderForm'));
const InvoiceTable = dynamic(() => import('./InvoiceTable'));
const BillAndInvoice = () => {
const [currentTab, setCurrentTab] = useState(TabEnum.bill);
const [isOpenInvoiceModal, setIsOpenInvoiceModal] = useState(false);
const router = useRouter();
const invoiceTab = (router.query.invoiceTab as string) || InvoiceTabEnum.bill;
const { t } = useTranslation();
return (
<>
@@ -24,17 +25,24 @@ const BillAndInvoice = () => {
<Flex justifyContent={'space-between'} alignItems={'center'} pb={'0.75rem'}>
<FillRowTabs
list={[
{ label: t('common:support.wallet.bill_tag.bill'), value: TabEnum.bill },
{ label: t('common:support.wallet.bill_tag.invoice'), value: TabEnum.invoice },
{ label: t('common:support.wallet.bill_tag.bill'), value: InvoiceTabEnum.bill },
{ label: t('common:support.wallet.bill_tag.invoice'), value: InvoiceTabEnum.invoice },
{
label: t('common:support.wallet.bill_tag.default_header'),
value: TabEnum.invoiceHeader
value: InvoiceTabEnum.invoiceHeader
}
]}
value={currentTab}
onChange={setCurrentTab}
value={invoiceTab}
onChange={(e) => {
router.replace({
query: {
currentTab: router.query.currentTab,
invoiceTab: e
}
});
}}
></FillRowTabs>
{currentTab !== TabEnum.invoiceHeader && (
{invoiceTab !== InvoiceTabEnum.invoiceHeader && (
<Button variant={'primary'} px="0" onClick={() => setIsOpenInvoiceModal(true)}>
<Flex alignItems={'center'} px={'20px'}>
<Box px={'1.25rem'} py={'0.5rem'}>
@@ -45,11 +53,17 @@ const BillAndInvoice = () => {
)}
</Flex>
<Box h={'100%'}>
{currentTab === TabEnum.bill && <BillTable />}
{currentTab === TabEnum.invoice && <InvoiceTable />}
{currentTab === TabEnum.invoiceHeader && <InvoiceHeaderForm />}
{invoiceTab === InvoiceTabEnum.bill && <BillTable />}
{invoiceTab === InvoiceTabEnum.invoice && <InvoiceTable />}
{invoiceTab === InvoiceTabEnum.invoiceHeader && <InvoiceHeaderForm />}
</Box>
{isOpenInvoiceModal && <ApplyInvoiceModal onClose={() => setIsOpenInvoiceModal(false)} />}
{isOpenInvoiceModal && (
<ApplyInvoiceModal
onClose={() => {
setIsOpenInvoiceModal(false);
}}
/>
)}
</Box>
</>
);

View File

@@ -20,7 +20,6 @@ const BillAndInvoice = dynamic(() => import('./components/bill/BillAndInvoice'))
const InformTable = dynamic(() => import('./components/InformTable'));
const ApiKeyTable = dynamic(() => import('./components/ApiKeyTable'));
const Individuation = dynamic(() => import('./components/Individuation'));
enum TabEnum {
'info' = 'info',
'promotion' = 'promotion',