mirror of
https://github.com/hexastack/hexabot
synced 2025-06-26 18:27:28 +00:00
Merge pull request #729 from Hexastack/728-optimize-usedialogs-logic
refactor(frontend): optimize useDialogs logic
This commit is contained in:
commit
6c8968b622
@ -32,7 +32,6 @@ export const AttachmentForm: FC<ComponentFormProps<AttachmentFormData>> = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper
|
<Wrapper
|
||||||
open={!!WrapperProps?.open}
|
|
||||||
onSubmit={() => {
|
onSubmit={() => {
|
||||||
data?.onChange?.(selected);
|
data?.onChange?.(selected);
|
||||||
rest.onSuccess?.();
|
rest.onSuccess?.();
|
||||||
|
|||||||
@ -32,7 +32,7 @@ export const FormDialog = ({
|
|||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog fullWidth {...rest}>
|
<Dialog open={!!rest?.open} fullWidth {...rest}>
|
||||||
<DialogTitle onClose={onCancel}>{title}</DialogTitle>
|
<DialogTitle onClose={onCancel}>{title}</DialogTitle>
|
||||||
<DialogContent>{children}</DialogContent>
|
<DialogContent>{children}</DialogContent>
|
||||||
{dialogActions}
|
{dialogActions}
|
||||||
|
|||||||
@ -98,11 +98,7 @@ export const MenuForm: FC<ComponentFormProps<MenuFormData>> = ({
|
|||||||
}, [reset, data?.row]);
|
}, [reset, data?.row]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper
|
<Wrapper onSubmit={handleSubmit(onSubmitForm)} {...WrapperProps}>
|
||||||
open={!!WrapperProps?.open}
|
|
||||||
onSubmit={handleSubmit(onSubmitForm)}
|
|
||||||
{...WrapperProps}
|
|
||||||
>
|
|
||||||
<form onSubmit={handleSubmit(onSubmitForm)}>
|
<form onSubmit={handleSubmit(onSubmitForm)}>
|
||||||
<ContentContainer>
|
<ContentContainer>
|
||||||
<ContentContainer flexDirection="row">
|
<ContentContainer flexDirection="row">
|
||||||
|
|||||||
@ -71,11 +71,7 @@ export const CategoryForm: FC<ComponentFormProps<ICategory>> = ({
|
|||||||
}, [data, reset]);
|
}, [data, reset]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper
|
<Wrapper onSubmit={handleSubmit(onSubmitForm)} {...WrapperProps}>
|
||||||
open={!!WrapperProps?.open}
|
|
||||||
onSubmit={handleSubmit(onSubmitForm)}
|
|
||||||
{...WrapperProps}
|
|
||||||
>
|
|
||||||
<form onSubmit={handleSubmit(onSubmitForm)}>
|
<form onSubmit={handleSubmit(onSubmitForm)}>
|
||||||
<ContentContainer>
|
<ContentContainer>
|
||||||
<ContentItem>
|
<ContentItem>
|
||||||
@ -93,5 +89,3 @@ export const CategoryForm: FC<ComponentFormProps<ICategory>> = ({
|
|||||||
</Wrapper>
|
</Wrapper>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
CategoryForm.displayName = "CategoryForm";
|
|
||||||
|
|||||||
@ -106,11 +106,7 @@ export const ContentTypeForm: FC<ComponentFormProps<IContentType>> = ({
|
|||||||
}, [data, reset]);
|
}, [data, reset]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper
|
<Wrapper onSubmit={handleSubmit(onSubmitForm)} {...WrapperProps}>
|
||||||
open={!!WrapperProps?.open}
|
|
||||||
onSubmit={handleSubmit(onSubmitForm)}
|
|
||||||
{...WrapperProps}
|
|
||||||
>
|
|
||||||
<form onSubmit={handleSubmit(onSubmitForm)}>
|
<form onSubmit={handleSubmit(onSubmitForm)}>
|
||||||
<ContentContainer>
|
<ContentContainer>
|
||||||
<ContentItem>
|
<ContentItem>
|
||||||
|
|||||||
@ -203,11 +203,7 @@ export const ContentForm: FC<ComponentFormProps<ContentFormData>> = ({
|
|||||||
}, [content, reset]);
|
}, [content, reset]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper
|
<Wrapper onSubmit={handleSubmit(onSubmitForm)} {...WrapperProps}>
|
||||||
open={!!WrapperProps?.open}
|
|
||||||
onSubmit={handleSubmit(onSubmitForm)}
|
|
||||||
{...WrapperProps}
|
|
||||||
>
|
|
||||||
<form onSubmit={handleSubmit(onSubmitForm)}>
|
<form onSubmit={handleSubmit(onSubmitForm)}>
|
||||||
<ContentContainer>
|
<ContentContainer>
|
||||||
{(contentType?.fields || []).map((contentField, index) => (
|
{(contentType?.fields || []).map((contentField, index) => (
|
||||||
|
|||||||
@ -53,7 +53,6 @@ export const ContentImportForm: FC<
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper
|
<Wrapper
|
||||||
open={!!WrapperProps?.open}
|
|
||||||
onSubmit={handleImportClick}
|
onSubmit={handleImportClick}
|
||||||
{...WrapperProps}
|
{...WrapperProps}
|
||||||
confirmButtonProps={{
|
confirmButtonProps={{
|
||||||
|
|||||||
@ -93,11 +93,7 @@ export const ContextVarForm: FC<ComponentFormProps<IContextVar>> = ({
|
|||||||
}, [data, reset]);
|
}, [data, reset]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper
|
<Wrapper onSubmit={handleSubmit(onSubmitForm)} {...WrapperProps}>
|
||||||
open={!!WrapperProps?.open}
|
|
||||||
onSubmit={handleSubmit(onSubmitForm)}
|
|
||||||
{...WrapperProps}
|
|
||||||
>
|
|
||||||
<form onSubmit={handleSubmit(onSubmitForm)}>
|
<form onSubmit={handleSubmit(onSubmitForm)}>
|
||||||
<ContentContainer>
|
<ContentContainer>
|
||||||
<ContentItem>
|
<ContentItem>
|
||||||
|
|||||||
@ -20,7 +20,7 @@ export const AttachmentViewerForm: FC<
|
|||||||
ComponentFormProps<AttachmentViewerFormData>
|
ComponentFormProps<AttachmentViewerFormData>
|
||||||
> = ({ data, Wrapper = Fragment, WrapperProps }) => {
|
> = ({ data, Wrapper = Fragment, WrapperProps }) => {
|
||||||
return (
|
return (
|
||||||
<Wrapper open={!!WrapperProps?.open} {...WrapperProps}>
|
<Wrapper {...WrapperProps}>
|
||||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||||
<img
|
<img
|
||||||
width="auto"
|
width="auto"
|
||||||
|
|||||||
@ -81,11 +81,7 @@ export const LabelForm: FC<ComponentFormProps<ILabel>> = ({
|
|||||||
}, [data, reset]);
|
}, [data, reset]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper
|
<Wrapper onSubmit={handleSubmit(onSubmitForm)} {...WrapperProps}>
|
||||||
open={!!WrapperProps?.open}
|
|
||||||
onSubmit={handleSubmit(onSubmitForm)}
|
|
||||||
{...WrapperProps}
|
|
||||||
>
|
|
||||||
<form onSubmit={handleSubmit(onSubmitForm)}>
|
<form onSubmit={handleSubmit(onSubmitForm)}>
|
||||||
<ContentContainer>
|
<ContentContainer>
|
||||||
<ContentItem>
|
<ContentItem>
|
||||||
|
|||||||
@ -82,11 +82,7 @@ export const LanguageForm: FC<ComponentFormProps<ILanguage>> = ({
|
|||||||
}, [data, reset]);
|
}, [data, reset]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper
|
<Wrapper onSubmit={handleSubmit(onSubmitForm)} {...WrapperProps}>
|
||||||
open={!!WrapperProps?.open}
|
|
||||||
onSubmit={handleSubmit(onSubmitForm)}
|
|
||||||
{...WrapperProps}
|
|
||||||
>
|
|
||||||
<form onSubmit={handleSubmit(onSubmitForm)}>
|
<form onSubmit={handleSubmit(onSubmitForm)}>
|
||||||
<ContentContainer>
|
<ContentContainer>
|
||||||
<ContentItem>
|
<ContentItem>
|
||||||
|
|||||||
@ -89,11 +89,7 @@ export const NlpEntityVarForm: FC<ComponentFormProps<INlpEntity>> = ({
|
|||||||
}, [data, reset]);
|
}, [data, reset]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper
|
<Wrapper onSubmit={handleSubmit(onSubmitForm)} {...WrapperProps}>
|
||||||
open={!!WrapperProps?.open}
|
|
||||||
onSubmit={handleSubmit(onSubmitForm)}
|
|
||||||
{...WrapperProps}
|
|
||||||
>
|
|
||||||
<form onSubmit={handleSubmit(onSubmitForm)}>
|
<form onSubmit={handleSubmit(onSubmitForm)}>
|
||||||
<ContentContainer>
|
<ContentContainer>
|
||||||
{!data ? (
|
{!data ? (
|
||||||
|
|||||||
@ -62,13 +62,8 @@ export const NlpSampleForm: FC<ComponentFormProps<INlpDatasetSample>> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper open={!!WrapperProps?.open} onSubmit={() => {}} {...WrapperProps}>
|
<Wrapper onSubmit={() => {}} {...WrapperProps}>
|
||||||
<form>
|
<NlpDatasetSample sample={data || undefined} submitForm={onSubmitForm} />
|
||||||
<NlpDatasetSample
|
|
||||||
sample={data || undefined}
|
|
||||||
submitForm={onSubmitForm}
|
|
||||||
/>
|
|
||||||
</form>
|
|
||||||
</Wrapper>
|
</Wrapper>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|||||||
@ -91,11 +91,7 @@ export const NlpValueForm: FC<
|
|||||||
}, [data, reset]);
|
}, [data, reset]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper
|
<Wrapper onSubmit={handleSubmit(onSubmitForm)} {...WrapperProps}>
|
||||||
open={!!WrapperProps?.open}
|
|
||||||
onSubmit={handleSubmit(onSubmitForm)}
|
|
||||||
{...WrapperProps}
|
|
||||||
>
|
|
||||||
<form onSubmit={handleSubmit(onSubmitForm)}>
|
<form onSubmit={handleSubmit(onSubmitForm)}>
|
||||||
<ContentContainer>
|
<ContentContainer>
|
||||||
<ContentItem>
|
<ContentItem>
|
||||||
|
|||||||
@ -83,7 +83,7 @@ export const PermissionsBody: FC<ComponentFormProps<IRole>> = ({
|
|||||||
},
|
},
|
||||||
onSuccess: () => {
|
onSuccess: () => {
|
||||||
modelRefetch();
|
modelRefetch();
|
||||||
toast.success(t("message.item_delete_success"));
|
toast.success(t("message.success_save"));
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
const { mutate: createPermission } = useCreate(EntityType.PERMISSION, {
|
const { mutate: createPermission } = useCreate(EntityType.PERMISSION, {
|
||||||
@ -117,7 +117,7 @@ export const PermissionsBody: FC<ComponentFormProps<IRole>> = ({
|
|||||||
}, [models]);
|
}, [models]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper open={!!WrapperProps?.open} onSubmit={() => {}} {...WrapperProps}>
|
<Wrapper onSubmit={() => {}} {...WrapperProps}>
|
||||||
<Typography fontWeight={700} sx={{ marginBottom: 2 }}>
|
<Typography fontWeight={700} sx={{ marginBottom: 2 }}>
|
||||||
{role?.name}
|
{role?.name}
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|||||||
@ -70,11 +70,7 @@ export const RoleForm: FC<ComponentFormProps<IRole>> = ({
|
|||||||
}, [data, reset]);
|
}, [data, reset]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper
|
<Wrapper onSubmit={handleSubmit(onSubmitForm)} {...WrapperProps}>
|
||||||
open={!!WrapperProps?.open}
|
|
||||||
onSubmit={handleSubmit(onSubmitForm)}
|
|
||||||
{...WrapperProps}
|
|
||||||
>
|
|
||||||
<form onSubmit={handleSubmit(onSubmitForm)}>
|
<form onSubmit={handleSubmit(onSubmitForm)}>
|
||||||
<ContentContainer>
|
<ContentContainer>
|
||||||
<ContentItem>
|
<ContentItem>
|
||||||
|
|||||||
@ -61,11 +61,7 @@ export const SubscriberForm: FC<ComponentFormProps<ISubscriber>> = ({
|
|||||||
}, [data, reset]);
|
}, [data, reset]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper
|
<Wrapper onSubmit={handleSubmit(onSubmitForm)} {...WrapperProps}>
|
||||||
open={!!WrapperProps?.open}
|
|
||||||
onSubmit={handleSubmit(onSubmitForm)}
|
|
||||||
{...WrapperProps}
|
|
||||||
>
|
|
||||||
<form onSubmit={handleSubmit(onSubmitForm)}>
|
<form onSubmit={handleSubmit(onSubmitForm)}>
|
||||||
<ContentContainer>
|
<ContentContainer>
|
||||||
<ContentItem>
|
<ContentItem>
|
||||||
|
|||||||
@ -82,11 +82,7 @@ export const TranslationForm: FC<ComponentFormProps<ITranslation>> = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper
|
<Wrapper onSubmit={handleSubmit(onSubmitForm)} {...WrapperProps}>
|
||||||
open={!!WrapperProps?.open}
|
|
||||||
onSubmit={handleSubmit(onSubmitForm)}
|
|
||||||
{...WrapperProps}
|
|
||||||
>
|
|
||||||
<form onSubmit={handleSubmit(onSubmitForm)}>
|
<form onSubmit={handleSubmit(onSubmitForm)}>
|
||||||
<ContentItem>
|
<ContentItem>
|
||||||
<FormLabel>{t("label.original_text")}</FormLabel>
|
<FormLabel>{t("label.original_text")}</FormLabel>
|
||||||
|
|||||||
@ -74,11 +74,7 @@ export const EditUserForm: FC<ComponentFormProps<EditUserFormData>> = ({
|
|||||||
}, [reset, data?.user]);
|
}, [reset, data?.user]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper
|
<Wrapper onSubmit={handleSubmit(onSubmitForm)} {...WrapperProps}>
|
||||||
open={!!WrapperProps?.open}
|
|
||||||
onSubmit={handleSubmit(onSubmitForm)}
|
|
||||||
{...WrapperProps}
|
|
||||||
>
|
|
||||||
<form onSubmit={handleSubmit(onSubmitForm)}>
|
<form onSubmit={handleSubmit(onSubmitForm)}>
|
||||||
<ContentContainer>
|
<ContentContainer>
|
||||||
<ContentItem>
|
<ContentItem>
|
||||||
|
|||||||
@ -62,11 +62,7 @@ export const InviteUserForm: FC<ComponentFormProps<undefined>> = ({
|
|||||||
sendInvitation(params);
|
sendInvitation(params);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper
|
<Wrapper onSubmit={handleSubmit(onSubmitForm)} {...WrapperProps}>
|
||||||
open={!!WrapperProps?.open}
|
|
||||||
onSubmit={handleSubmit(onSubmitForm)}
|
|
||||||
{...WrapperProps}
|
|
||||||
>
|
|
||||||
<form onSubmit={handleSubmit(onSubmitForm)}>
|
<form onSubmit={handleSubmit(onSubmitForm)}>
|
||||||
<ContentContainer>
|
<ContentContainer>
|
||||||
<ContentItem>
|
<ContentItem>
|
||||||
|
|||||||
@ -109,11 +109,7 @@ export const BlockEditForm: FC<ComponentFormProps<IBlock>> = ({
|
|||||||
}, [block, reset]);
|
}, [block, reset]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper
|
<Wrapper onSubmit={handleSubmit(onSubmitForm)} {...WrapperProps}>
|
||||||
open={!!WrapperProps?.open}
|
|
||||||
onSubmit={handleSubmit(onSubmitForm)}
|
|
||||||
{...WrapperProps}
|
|
||||||
>
|
|
||||||
<BlockFormProvider methods={methods} block={block || undefined}>
|
<BlockFormProvider methods={methods} block={block || undefined}>
|
||||||
<ContentContainer>
|
<ContentContainer>
|
||||||
<ContentItem display="flex" gap={5}>
|
<ContentItem display="flex" gap={5}>
|
||||||
|
|||||||
@ -39,7 +39,6 @@ export const BlockMoveForm: FC<ComponentFormProps<BlockMoveFormData>> = ({
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Wrapper
|
<Wrapper
|
||||||
open={!!WrapperProps?.open}
|
|
||||||
onSubmit={handleMove}
|
onSubmit={handleMove}
|
||||||
{...WrapperProps}
|
{...WrapperProps}
|
||||||
confirmButtonProps={{
|
confirmButtonProps={{
|
||||||
|
|||||||
@ -151,8 +151,9 @@ export interface DialogProviderProps {
|
|||||||
// form dialog
|
// form dialog
|
||||||
export interface FormDialogProps
|
export interface FormDialogProps
|
||||||
extends FormButtonsProps,
|
extends FormButtonsProps,
|
||||||
Omit<MuiDialogProps, "onSubmit">,
|
Omit<MuiDialogProps, "onSubmit" | "open">,
|
||||||
DialogExtraOptions {
|
DialogExtraOptions {
|
||||||
|
open?: boolean;
|
||||||
title?: string;
|
title?: string;
|
||||||
children?: React.ReactNode;
|
children?: React.ReactNode;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user