From 605e2b2a81814a8ef27aaae2b9aba44267f7e76c Mon Sep 17 00:00:00 2001 From: Darcy Ye Date: Wed, 26 Jul 2023 10:05:04 +0800 Subject: [PATCH] fix(console): should reset the form every time close CreateTenantModal (#4244) --- .../console/src/components/CreateTenantModal/index.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/console/src/components/CreateTenantModal/index.tsx b/packages/console/src/components/CreateTenantModal/index.tsx index be9cdd4bd..466fd8935 100644 --- a/packages/console/src/components/CreateTenantModal/index.tsx +++ b/packages/console/src/components/CreateTenantModal/index.tsx @@ -49,8 +49,10 @@ function CreateTenantModal({ isOpen, onClose, skipPlanSelection = false }: Props const { t } = useTranslation(undefined, { keyPrefix: 'admin_console' }); const [tenantData, setTenantData] = useState(); const theme = useTheme(); + + const defaultValues = { tag: TenantTag.Development }; const methods = useForm({ - defaultValues: { tag: TenantTag.Development }, + defaultValues, }); const { @@ -67,7 +69,6 @@ function CreateTenantModal({ isOpen, onClose, skipPlanSelection = false }: Props void trySafe(async () => { const { name, tag } = data; const newTenant = await cloudApi.post('/api/tenants', { body: { name, tag } }); - reset(); onClose(newTenant); }); }; @@ -85,6 +86,9 @@ function CreateTenantModal({ isOpen, onClose, skipPlanSelection = false }: Props isOpen={isOpen} className={modalStyles.content} overlayClassName={modalStyles.overlay} + onAfterClose={() => { + reset(defaultValues); + }} onRequestClose={() => { onClose(); }}