From c77410798078a74881c2cfa289c05c42deb78a2e Mon Sep 17 00:00:00 2001 From: Darcy Ye Date: Tue, 13 Jun 2023 12:21:34 +0800 Subject: [PATCH] fix(console): set RHF default value (#4027) --- .../TenantSettings/TenantBasicSettings/index.tsx | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/packages/console/src/pages/TenantSettings/TenantBasicSettings/index.tsx b/packages/console/src/pages/TenantSettings/TenantBasicSettings/index.tsx index 2bb59b260..7c38219c8 100644 --- a/packages/console/src/pages/TenantSettings/TenantBasicSettings/index.tsx +++ b/packages/console/src/pages/TenantSettings/TenantBasicSettings/index.tsx @@ -16,6 +16,12 @@ import ProfileForm from './ProfileForm'; import * as styles from './index.module.scss'; import { type TenantSettingsForm } from './types.js'; +const tenantProfileToForm = (tenant?: TenantInfo): TenantSettingsForm => { + return { + profile: { name: tenant?.name ?? 'My project', tag: tenant?.tag ?? TenantTag.Development }, + }; +}; + function TenantBasicSettings() { const { api: cloudApi, @@ -36,7 +42,9 @@ function TenantBasicSettings() { } }, [requestError]); - const methods = useForm(); + const methods = useForm({ + defaultValues: tenantProfileToForm(currentTenant), + }); const { watch, reset, @@ -45,8 +53,7 @@ function TenantBasicSettings() { } = methods; useEffect(() => { - const { name, tag } = currentTenant ?? { name: 'My project', tag: TenantTag.Development }; - reset({ profile: { name, tag } }); + reset(tenantProfileToForm(currentTenant)); }, [currentTenant, reset]); const saveData = async (data: { name?: string; tag?: TenantTag }) => {