Disable save button while submitting form in settings (#5352)

as per title
This commit is contained in:
Marie
2024-05-10 18:18:39 +02:00
committed by GitHub
parent ae0e31abc7
commit 72521d5554
4 changed files with 26 additions and 19 deletions

View File

@ -39,11 +39,12 @@ export const SettingsNewObject = () => {
resolver: zodResolver(newObjectFormSchema),
});
const canSave = formConfig.formState.isValid;
const handleSave = async () => {
const formValues = formConfig.getValues();
const canSave =
formConfig.formState.isValid && !formConfig.formState.isSubmitting;
const handleSave = async (
formValues: SettingsDataModelNewObjectFormValues,
) => {
try {
const { data: response } = await createOneObjectMetadataItem(
settingsCreateObjectInputSchema.parse(formValues),
@ -81,7 +82,7 @@ export const SettingsNewObject = () => {
<SaveAndCancelButtons
isSaveDisabled={!canSave}
onCancel={() => navigate(settingsObjectsPagePath)}
onSave={handleSave}
onSave={formConfig.handleSubmit(handleSave)}
/>
</SettingsHeaderContainer>
<Section>