0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-16 20:26:19 -05:00

fix(console): set RHF default value (#4027)

This commit is contained in:
Darcy Ye 2023-06-13 12:21:34 +08:00 committed by GitHub
parent 2c21832793
commit c774107980
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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<TenantSettingsForm>();
const methods = useForm<TenantSettingsForm>({
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 }) => {