Skip to content

Commit

Permalink
Merge pull request #727 from Hexastack/714-refactor-visual-editor-dia…
Browse files Browse the repository at this point in the history
…logs

refactor(frontend): update BlockEdit and BlockMove dialogs
  • Loading branch information
marrouchi authored Feb 10, 2025
2 parents 455c594 + e954e3e commit 46f3975
Show file tree
Hide file tree
Showing 16 changed files with 513 additions and 550 deletions.
63 changes: 0 additions & 63 deletions frontend/src/app-components/dialogs/DeleteDialog.tsx

This file was deleted.

86 changes: 0 additions & 86 deletions frontend/src/app-components/dialogs/MoveDialog.tsx

This file was deleted.

1 change: 0 additions & 1 deletion frontend/src/app-components/dialogs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

export * from "./confirm/ConfirmDialog";
export * from "./confirm/ConfirmDialogBody";
export * from "./DeleteDialog";
export * from "./DialogTitle";
export * from "./FormDialog";
export * from "./GenericFormDialog";
Expand Down
51 changes: 22 additions & 29 deletions frontend/src/components/inbox/components/AttachmentViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -21,42 +20,36 @@ import {
StdOutgoingAttachmentMessage,
} from "@/types/message.types";

import { AttachmentViewerFormDialog } from "./AttachmentViewerFormDialog";

interface AttachmentInterface {
name?: string;
url?: string;
}

const componentMap: { [key in FileType]: FC<AttachmentInterface> } = {
[FileType.image]: ({ url }: AttachmentInterface) => {
const dialogCtl = useDialog(false);
const dialogs = useDialogs();

if (url)
return (
<>
<Dialog {...dialogCtl}>
<DialogTitle onClose={dialogCtl.closeDialog}>Image</DialogTitle>
<DialogContent>
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
width="auto"
height={800}
style={{ objectFit: "contain", cursor: "pointer" }}
alt={url}
src={url}
onClick={dialogCtl.openDialog}
/>
</DialogContent>
</Dialog>
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
width="auto"
height={200}
style={{ objectFit: "contain", cursor: "pointer" }}
alt={url}
src={url}
onClick={dialogCtl.openDialog}
/>
</>
// eslint-disable-next-line @next/next/no-img-element
<img
width="auto"
height={200}
style={{ objectFit: "contain", cursor: "pointer" }}
alt={url}
src={url}
onClick={() =>
dialogs.open(
AttachmentViewerFormDialog,
{ url },
{
hasButtons: false,
},
)
}
/>
);

return (
Expand Down
37 changes: 37 additions & 0 deletions frontend/src/components/inbox/components/AttachmentViewerForm.tsx
Original file line number Diff line number Diff line change
@@ -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<AttachmentViewerFormData>
> = ({ data, Wrapper = Fragment, WrapperProps }) => {
return (
<Wrapper open={!!WrapperProps?.open} {...WrapperProps}>
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
width="auto"
height={800}
style={{
cursor: "pointer",
objectFit: "contain",
}}
alt={data?.url}
src={data?.url}
/>
</Wrapper>
);
};
Original file line number Diff line number Diff line change
@@ -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<T>,
) => (
<GenericFormDialog<T>
Form={AttachmentViewerForm}
rowKey="row"
addText="label.image"
{...props}
/>
);
Loading

0 comments on commit 46f3975

Please sign in to comment.