diff --git a/frontend/src/app-components/attachment/AttachmentDialog.tsx b/frontend/src/app-components/attachment/AttachmentDialog.tsx deleted file mode 100644 index 0ddc30ec..00000000 --- a/frontend/src/app-components/attachment/AttachmentDialog.tsx +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright © 2024 Hexastack. All rights reserved. - * - * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: - * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. - * 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 { Button, Dialog, DialogActions, DialogContent } from "@mui/material"; -import { GridEventListener } from "@mui/x-data-grid"; -import { FC, useEffect, useState } from "react"; - -import { DialogTitle } from "@/app-components/dialogs/DialogTitle"; -import { MediaLibrary } from "@/components/media-library"; -import { DialogControlProps } from "@/hooks/useDialog"; -import { useTranslate } from "@/hooks/useTranslate"; -import { IAttachment } from "@/types/attachment.types"; - -export type AttachmentDialogProps = DialogControlProps< - never, - IAttachment | null -> & { accept: string }; - -export const AttachmentDialog: FC = ({ - open, - closeDialog, - callback, - accept, - ...rest -}) => { - const { t } = useTranslate(); - const [selected, setSelected] = useState(null); - const handleSelection: GridEventListener<"rowClick"> = (data) => { - setSelected(data.row); - }; - - useEffect(() => { - if (!open) { - setSelected(null); - } - }, [open]); - - return ( - - - {t("title.media_library")} - - - - - - - - - ); -}; diff --git a/frontend/src/app-components/attachment/AttachmentForm.tsx b/frontend/src/app-components/attachment/AttachmentForm.tsx new file mode 100644 index 00000000..d7d8aa4a --- /dev/null +++ b/frontend/src/app-components/attachment/AttachmentForm.tsx @@ -0,0 +1,53 @@ +/* + * Copyright © 2025 Hexastack. All rights reserved. + * + * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: + * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. + * 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 { GridEventListener } from "@mui/x-data-grid"; +import { FC, Fragment, useState } from "react"; + +import { MediaLibrary } from "@/components/media-library"; +import { IAttachment } from "@/types/attachment.types"; +import { ComponentFormProps } from "@/types/common/dialogs.types"; + +export type AttachmentFormData = { + row?: undefined; + accept?: string; + onChange?: (data?: IAttachment | null) => void; +}; + +export const AttachmentForm: FC> = ({ + data, + Wrapper = Fragment, + WrapperProps, + ...rest +}) => { + const [selected, setSelected] = useState(null); + const handleSelection: GridEventListener<"rowClick"> = (data) => { + setSelected(data.row); + }; + + return ( + { + data?.onChange?.(selected); + rest.onSuccess?.(); + }} + {...WrapperProps} + confirmButtonProps={{ + ...WrapperProps?.confirmButtonProps, + disabled: !selected, + }} + > + + + ); +}; diff --git a/frontend/src/app-components/attachment/AttachmentFormDialog.tsx b/frontend/src/app-components/attachment/AttachmentFormDialog.tsx new file mode 100644 index 00000000..e541a6e1 --- /dev/null +++ b/frontend/src/app-components/attachment/AttachmentFormDialog.tsx @@ -0,0 +1,26 @@ +/* + * Copyright © 2025 Hexastack. All rights reserved. + * + * Licensed under the GNU Affero General Public License v3.0 (AGPLv3) with the following additional terms: + * 1. The name "Hexabot" is a trademark of Hexastack. You may not use this name in derivative works without express written permission. + * 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 { GenericFormDialog } from "@/app-components/dialogs"; +import { ComponentFormDialogProps } from "@/types/common/dialogs.types"; + +import { AttachmentForm, AttachmentFormData } from "./AttachmentForm"; + +export const AttachmentFormDialog = < + T extends AttachmentFormData = AttachmentFormData, +>( + props: ComponentFormDialogProps, +) => ( + + Form={AttachmentForm} + rowKey="row" + addText="title.media_library" + confirmButtonProps={{ value: "button.select" }} + {...props} + /> +); diff --git a/frontend/src/app-components/attachment/AttachmentThumbnail.tsx b/frontend/src/app-components/attachment/AttachmentThumbnail.tsx index 6075b67c..43a192c8 100644 --- a/frontend/src/app-components/attachment/AttachmentThumbnail.tsx +++ b/frontend/src/app-components/attachment/AttachmentThumbnail.tsx @@ -23,7 +23,7 @@ import { FC } from "react"; import { useDelete } from "@/hooks/crud/useDelete"; import { useGet } from "@/hooks/crud/useGet"; -import { useDialog } from "@/hooks/useDialog"; +import { useDialogs } from "@/hooks/useDialogs"; import useFormattedFileSize from "@/hooks/useFormattedFileSize"; import { useHasPermission } from "@/hooks/useHasPermission"; import { useToast } from "@/hooks/useToast"; @@ -32,7 +32,7 @@ import { EntityType } from "@/services/types"; import { IAttachment } from "@/types/attachment.types"; import { PermissionAction } from "@/types/permission.types"; -import { DeleteDialog } from "../dialogs"; +import { ConfirmDialogBody } from "../dialogs"; const AttachmentPreview = ({ attachment, @@ -85,8 +85,8 @@ const AttachmentThumbnail: FC = ({ }); const { toast } = useToast(); const { t } = useTranslate(); - const deleteDialogCtl = useDialog(false); - const { mutateAsync: deleteAttachment } = useDelete(EntityType.ATTACHMENT, { + const dialogs = useDialogs(); + const { mutate: deleteAttachment } = useDelete(EntityType.ATTACHMENT, { onError: () => { toast.error(t("message.internal_server_error")); }, @@ -121,12 +121,6 @@ const AttachmentThumbnail: FC = ({ hasPermission(EntityType.ATTACHMENT, PermissionAction.DELETE) && onChange ? ( <> - { - deleteAttachment(attachment.id); - }} - />