From 366fe0eadaebfae600cd9ed10e8050f721eb6184 Mon Sep 17 00:00:00 2001 From: papapatrick <109422393+Patrickill@users.noreply.github.com> Date: Thu, 22 Aug 2024 12:24:33 +0800 Subject: [PATCH] perf: invoice page refresh after apply (#2469) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * perf: 发票申请弹窗成功后刷新 * refactor: 组件内拿invoiceTab --- .../components/bill/ApplyInvoiceModal.tsx | 8 +++- .../components/bill/BillAndInvoice.tsx | 42 ++++++++++++------- projects/app/src/pages/account/index.tsx | 1 - 3 files changed, 35 insertions(+), 16 deletions(-) diff --git a/projects/app/src/pages/account/components/bill/ApplyInvoiceModal.tsx b/projects/app/src/pages/account/components/bill/ApplyInvoiceModal.tsx index 2d313e39fb..d820bf1792 100644 --- a/projects/app/src/pages/account/components/bill/ApplyInvoiceModal.tsx +++ b/projects/app/src/pages/account/components/bill/ApplyInvoiceModal.tsx @@ -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(); + } } ); diff --git a/projects/app/src/pages/account/components/bill/BillAndInvoice.tsx b/projects/app/src/pages/account/components/bill/BillAndInvoice.tsx index 7f0c2d58c3..5b04ce9d27 100644 --- a/projects/app/src/pages/account/components/bill/BillAndInvoice.tsx +++ b/projects/app/src/pages/account/components/bill/BillAndInvoice.tsx @@ -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 = () => { { + router.replace({ + query: { + currentTab: router.query.currentTab, + invoiceTab: e + } + }); + }} > - {currentTab !== TabEnum.invoiceHeader && ( + {invoiceTab !== InvoiceTabEnum.invoiceHeader && (