mirror of
https://github.com/hexastack/hexabot
synced 2025-02-23 21:04:15 +00:00
fix: reset form
This commit is contained in:
parent
8112b80f94
commit
9e029674e1
@ -6,7 +6,6 @@
|
|||||||
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
* 2. All derivative works must include clear attribution to the original creator and software, Hexastack and Hexabot, in a prominent location (e.g., in the software's "About" section, documentation, and README file).
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import AddIcon from "@mui/icons-material/Add";
|
import AddIcon from "@mui/icons-material/Add";
|
||||||
import { Button, Dialog, DialogActions, DialogContent } from "@mui/material";
|
import { Button, Dialog, DialogActions, DialogContent } from "@mui/material";
|
||||||
import { FC, useEffect } from "react";
|
import { FC, useEffect } from "react";
|
||||||
@ -53,30 +52,34 @@ export const ContentTypeDialog: FC<ContentTypeDialogProps> = ({
|
|||||||
name: "fields",
|
name: "fields",
|
||||||
control,
|
control,
|
||||||
});
|
});
|
||||||
|
const CloseAndReset = () => {
|
||||||
|
closeDialog();
|
||||||
|
reset();
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (open) reset();
|
||||||
|
}, [open, reset]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (data) {
|
if (data) {
|
||||||
reset({
|
reset({
|
||||||
name: data.name,
|
name: data.name,
|
||||||
fields: data.fields,
|
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
reset();
|
reset();
|
||||||
}
|
}
|
||||||
}, [data, reset]);
|
}, [data, reset]);
|
||||||
|
|
||||||
const { mutateAsync: createContentType } = useCreate(
|
const { mutate: createContentType } = useCreate(EntityType.CONTENT_TYPE, {
|
||||||
EntityType.CONTENT_TYPE,
|
onError: (error) => {
|
||||||
{
|
toast.error(error);
|
||||||
onError: (error) => {
|
|
||||||
toast.error(error);
|
|
||||||
},
|
|
||||||
onSuccess: () => {
|
|
||||||
closeDialog();
|
|
||||||
toast.success(t("message.success_save"));
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
);
|
onSuccess: () => {
|
||||||
|
closeDialog();
|
||||||
|
toast.success(t("message.success_save"));
|
||||||
|
},
|
||||||
|
});
|
||||||
const { mutateAsync: updateContentType } = useUpdate(
|
const { mutateAsync: updateContentType } = useUpdate(
|
||||||
EntityType.CONTENT_TYPE,
|
EntityType.CONTENT_TYPE,
|
||||||
{
|
{
|
||||||
@ -98,9 +101,9 @@ export const ContentTypeDialog: FC<ContentTypeDialogProps> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog open={open} fullWidth onClose={closeDialog}>
|
<Dialog open={open} fullWidth onClose={CloseAndReset}>
|
||||||
<form onSubmit={handleSubmit(onSubmitForm)}>
|
<form onSubmit={handleSubmit(onSubmitForm)}>
|
||||||
<DialogTitle onClose={closeDialog}>
|
<DialogTitle onClose={CloseAndReset}>
|
||||||
{data ? t("title.edit_content_type") : t("title.new_content_type")}
|
{data ? t("title.edit_content_type") : t("title.new_content_type")}
|
||||||
</DialogTitle>
|
</DialogTitle>
|
||||||
<DialogContent>
|
<DialogContent>
|
||||||
|
Loading…
Reference in New Issue
Block a user