mirror of
https://github.com/hexastack/hexabot
synced 2024-12-02 00:54:56 +00:00
fix: blockForm reset values
This commit is contained in:
parent
3c5a45fca5
commit
d4c3e59e62
@ -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,24 +69,25 @@ const BlockDialog: FC<BlockDialogProps> = ({
|
||||
toast.success(t("message.success_save"));
|
||||
},
|
||||
});
|
||||
const methods = useForm<IBlockAttributes>({
|
||||
defaultValues: {
|
||||
name: block?.name || "",
|
||||
patterns: block?.patterns || [],
|
||||
trigger_labels: block?.trigger_labels || [],
|
||||
trigger_channels: block?.trigger_channels || [],
|
||||
options: block?.options || {
|
||||
typing: 0,
|
||||
content: {
|
||||
display: OutgoingMessageFormat.list,
|
||||
top_element_style: "compact",
|
||||
limit: 2,
|
||||
},
|
||||
assignTo: block?.options?.assignTo,
|
||||
const DEFAULT_VALUES = {
|
||||
name: block?.name || "",
|
||||
patterns: block?.patterns || [],
|
||||
trigger_labels: block?.trigger_labels || [],
|
||||
trigger_channels: block?.trigger_channels || [],
|
||||
options: block?.options || {
|
||||
typing: 0,
|
||||
content: {
|
||||
display: OutgoingMessageFormat.list,
|
||||
top_element_style: "compact",
|
||||
limit: 2,
|
||||
},
|
||||
assign_labels: block?.assign_labels || [],
|
||||
message: block?.message || [""],
|
||||
assignTo: block?.options?.assignTo,
|
||||
},
|
||||
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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user