From 12fd65b774ec50859aa0ca85a122534c6a2205e7 Mon Sep 17 00:00:00 2001 From: yassinedorbozgithub Date: Sun, 9 Feb 2025 01:32:32 +0100 Subject: [PATCH] refactor(frontend): update AttachmentViewer dialog --- .../inbox/components/AttachmentViewer.tsx | 51 ++++++++----------- .../inbox/components/AttachmentViewerForm.tsx | 37 ++++++++++++++ .../components/AttachmentViewerFormDialog.tsx | 28 ++++++++++ 3 files changed, 87 insertions(+), 29 deletions(-) create mode 100644 frontend/src/components/inbox/components/AttachmentViewerForm.tsx create mode 100644 frontend/src/components/inbox/components/AttachmentViewerFormDialog.tsx diff --git a/frontend/src/components/inbox/components/AttachmentViewer.tsx b/frontend/src/components/inbox/components/AttachmentViewer.tsx index 67fd3110..a38d5ed2 100644 --- a/frontend/src/components/inbox/components/AttachmentViewer.tsx +++ b/frontend/src/components/inbox/components/AttachmentViewer.tsx @@ -7,11 +7,10 @@ */ import DownloadIcon from "@mui/icons-material/Download"; -import { Box, Button, Dialog, DialogContent, Typography } from "@mui/material"; +import { Box, Button, Typography } from "@mui/material"; import { FC } from "react"; -import { DialogTitle } from "@/app-components/dialogs"; -import { useDialog } from "@/hooks/useDialog"; +import { useDialogs } from "@/hooks/useDialogs"; import { useGetAttachmentMetadata } from "@/hooks/useGetAttachmentMetadata"; import { useTranslate } from "@/hooks/useTranslate"; import { @@ -21,6 +20,8 @@ import { StdOutgoingAttachmentMessage, } from "@/types/message.types"; +import { AttachmentViewerFormDialog } from "./AttachmentViewerFormDialog"; + interface AttachmentInterface { name?: string; url?: string; @@ -28,35 +29,27 @@ interface AttachmentInterface { const componentMap: { [key in FileType]: FC } = { [FileType.image]: ({ url }: AttachmentInterface) => { - const dialogCtl = useDialog(false); + const dialogs = useDialogs(); if (url) return ( - <> - - Image - - {/* eslint-disable-next-line @next/next/no-img-element */} - {url} - - - {/* eslint-disable-next-line @next/next/no-img-element */} - {url} - + // eslint-disable-next-line @next/next/no-img-element + {url} + dialogs.open( + AttachmentViewerFormDialog, + { url }, + { + hasButtons: false, + }, + ) + } + /> ); return ( diff --git a/frontend/src/components/inbox/components/AttachmentViewerForm.tsx b/frontend/src/components/inbox/components/AttachmentViewerForm.tsx new file mode 100644 index 00000000..de97482a --- /dev/null +++ b/frontend/src/components/inbox/components/AttachmentViewerForm.tsx @@ -0,0 +1,37 @@ +/* + * 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 { FC, Fragment } from "react"; + +import { ComponentFormProps } from "@/types/common/dialogs.types"; + +export type AttachmentViewerFormData = { + row?: never; + url?: string; + name?: string; +}; + +export const AttachmentViewerForm: FC< + ComponentFormProps +> = ({ data, Wrapper = Fragment, WrapperProps }) => { + return ( + + {/* eslint-disable-next-line @next/next/no-img-element */} + {data?.url} + + ); +}; diff --git a/frontend/src/components/inbox/components/AttachmentViewerFormDialog.tsx b/frontend/src/components/inbox/components/AttachmentViewerFormDialog.tsx new file mode 100644 index 00000000..a858269c --- /dev/null +++ b/frontend/src/components/inbox/components/AttachmentViewerFormDialog.tsx @@ -0,0 +1,28 @@ +/* + * 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 { + AttachmentViewerForm, + AttachmentViewerFormData, +} from "./AttachmentViewerForm"; + +export const AttachmentViewerFormDialog = < + T extends AttachmentViewerFormData = AttachmentViewerFormData, +>( + props: ComponentFormDialogProps, +) => ( + + Form={AttachmentViewerForm} + rowKey="row" + addText="label.image" + {...props} + /> +);