diff --git a/src/components/dialogs/network-modifications/limit-sets/limit-sets-tabular-modification-form.tsx b/src/components/dialogs/network-modifications/limit-sets/limit-sets-tabular-modification-form.tsx index a5ff0c581e..6f32039338 100644 --- a/src/components/dialogs/network-modifications/limit-sets/limit-sets-tabular-modification-form.tsx +++ b/src/components/dialogs/network-modifications/limit-sets/limit-sets-tabular-modification-form.tsx @@ -193,13 +193,16 @@ export function LimitSetsTabularModificationForm({ dataFetching }: Readonly { - clearErrors(MODIFICATIONS_TABLE); - tableRef.current?.replace([]); + const resetFileStateOnTypeChange = useCallback(() => { setValue(CSV_FILENAME, undefined); setSelectedFile(undefined); setFileErrorMessage(undefined); - }, [clearErrors, setValue]); + }, [setValue]); + + const resetFormStateOnTypeChange = useCallback(() => { + clearErrors(MODIFICATIONS_TABLE); + tableRef.current?.replace([]); + }, [clearErrors]); const csvFilename = getValues(CSV_FILENAME); @@ -225,7 +228,8 @@ export function LimitSetsTabularModificationForm({ dataFetching }: Readonly hasNonEmptyRows(getValues(MODIFICATIONS_TABLE))} - resetOnConfirmation={handleChangeType} + resetOnChange={resetFileStateOnTypeChange} + resetOnConfirmation={resetFormStateOnTypeChange} message="changeTypeMessage" validateButtonLabel="button.changeType" /> diff --git a/src/components/dialogs/network-modifications/tabular/tabular-form.tsx b/src/components/dialogs/network-modifications/tabular/tabular-form.tsx index 276952d74b..427fabfab6 100644 --- a/src/components/dialogs/network-modifications/tabular/tabular-form.tsx +++ b/src/components/dialogs/network-modifications/tabular/tabular-form.tsx @@ -413,14 +413,17 @@ export function TabularForm({ dataFetching, dialogMode }: Readonly { - clearErrors(MODIFICATIONS_TABLE); - tableRef.current?.replace([]); + const resetFileStateOnTypeChange = useCallback(() => { setValue(CSV_FILENAME, undefined); - setValue(TABULAR_PROPERTIES, []); setSelectedFile(undefined); setFileErrorMessage(undefined); setFileWarningMessage(undefined); + }, [setValue]); + + const resetFormStateOnTypeChange = useCallback(() => { + clearErrors(MODIFICATIONS_TABLE); + tableRef.current?.replace([]); + setValue(TABULAR_PROPERTIES, []); }, [clearErrors, setValue]); const equipmentTypeField = ( @@ -433,7 +436,8 @@ export function TabularForm({ dataFetching, dialogMode }: Readonly hasNonEmptyRows(getValues(MODIFICATIONS_TABLE))} - resetOnConfirmation={handleChangeType} + resetOnChange={resetFileStateOnTypeChange} + resetOnConfirmation={resetFormStateOnTypeChange} message="changeTypeMessage" validateButtonLabel="button.changeType" />