fix: blockForm reset values

This commit is contained in:
yassinedorbozgithub 2024-11-26 12:18:27 +01:00
parent 3c5a45fca5
commit d4c3e59e62

View File

@ -35,7 +35,7 @@ import { useTranslate } from "@/hooks/useTranslate";
import { EntityType } from "@/services/types";
import { OutgoingMessageFormat } from "@/types/message.types";
import { IBlockAttributes, IBlock } from "../../types/block.types";
import { IBlock, IBlockAttributes } from "../../types/block.types";
import BlockFormProvider from "./form/BlockFormProvider";
import { MessageForm } from "./form/MessageForm";
@ -69,8 +69,7 @@ const BlockDialog: FC<BlockDialogProps> = ({
toast.success(t("message.success_save"));
},
});
const methods = useForm<IBlockAttributes>({
defaultValues: {
const DEFAULT_VALUES = {
name: block?.name || "",
patterns: block?.patterns || [],
trigger_labels: block?.trigger_labels || [],
@ -86,7 +85,9 @@ const BlockDialog: FC<BlockDialogProps> = ({
},
assign_labels: block?.assign_labels || [],
message: block?.message || [""],
},
} as IBlockAttributes;
const methods = useForm<IBlockAttributes>({
defaultValues: DEFAULT_VALUES,
});
const {
reset,
@ -114,10 +115,8 @@ const BlockDialog: FC<BlockDialogProps> = ({
}, [open, reset]);
useEffect(() => {
if (block) {
reset({
name: block.name,
});
if (block && open) {
reset(DEFAULT_VALUES);
} else {
reset();
}