Fix control update
Signed-off-by: Sacha Al Himdani <sacha@getprobo.com>
This commit is contained in:
@@ -18,6 +18,7 @@ import { useFormWithSchema } from "/hooks/useFormWithSchema";
|
|||||||
import { z } from "zod";
|
import { z } from "zod";
|
||||||
import { useMutationWithToasts } from "/hooks/useMutationWithToasts";
|
import { useMutationWithToasts } from "/hooks/useMutationWithToasts";
|
||||||
import { ControlledSelect } from "/components/form/ControlledField";
|
import { ControlledSelect } from "/components/form/ControlledField";
|
||||||
|
import { useEffect, useMemo } from "react";
|
||||||
|
|
||||||
type Props = {
|
type Props = {
|
||||||
children: ReactNode;
|
children: ReactNode;
|
||||||
@@ -91,16 +92,23 @@ export function FrameworkControlDialog(props: Props) {
|
|||||||
successMessage: __("Control created successfully."),
|
successMessage: __("Control created successfully."),
|
||||||
errorMessage: __("Failed to create control. Please try again."),
|
errorMessage: __("Failed to create control. Please try again."),
|
||||||
});
|
});
|
||||||
const { control, handleSubmit, register, reset, watch } = useFormWithSchema(schema, {
|
|
||||||
defaultValues: {
|
const defaultValues = useMemo(() => ({
|
||||||
name: frameworkControl?.name ?? "",
|
name: frameworkControl?.name ?? "",
|
||||||
description: frameworkControl?.description ?? "",
|
description: frameworkControl?.description ?? "",
|
||||||
sectionTitle: frameworkControl?.sectionTitle ?? "",
|
sectionTitle: frameworkControl?.sectionTitle ?? "",
|
||||||
status: frameworkControl?.status ?? "INCLUDED",
|
status: frameworkControl?.status ?? "INCLUDED",
|
||||||
exclusionJustification: frameworkControl?.exclusionJustification ?? "",
|
exclusionJustification: frameworkControl?.exclusionJustification ?? "",
|
||||||
},
|
}), [frameworkControl]);
|
||||||
|
|
||||||
|
const { control, handleSubmit, register, reset, watch } = useFormWithSchema(schema, {
|
||||||
|
defaultValues,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
reset(defaultValues);
|
||||||
|
}, [defaultValues, reset]);
|
||||||
|
|
||||||
const statusValue = watch("status");
|
const statusValue = watch("status");
|
||||||
const showExclusionJustification = statusValue === "EXCLUDED";
|
const showExclusionJustification = statusValue === "EXCLUDED";
|
||||||
|
|
||||||
@@ -147,7 +155,7 @@ export function FrameworkControlDialog(props: Props) {
|
|||||||
<Breadcrumb
|
<Breadcrumb
|
||||||
items={[
|
items={[
|
||||||
__("Controls"),
|
__("Controls"),
|
||||||
control ? __("Edit Control") : __("New Control"),
|
frameworkControl ? __("Edit Control") : __("New Control"),
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user