Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(frontend): category dialog #662

Merged
merged 26 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
407581a
refactor: dialog system (partial)
marrouchi Jan 31, 2025
7348386
fix: resolve file conflicts
yassinedorbozgithub Jan 31, 2025
735e783
feat(frontend): add useDialog
yassinedorbozgithub Feb 1, 2025
c689399
refactor(frontend): update categories pages
yassinedorbozgithub Feb 2, 2025
51c3a88
refactor(frontend): update visual editor categories pages
yassinedorbozgithub Feb 3, 2025
2ba5c66
fix(frontend): apply feedback updates
yassinedorbozgithub Feb 3, 2025
d3c8ff5
fix(frontend): remove unused comments
yassinedorbozgithub Feb 3, 2025
7d93792
Merge branch 'main' into refactor/category-dialog
yassinedorbozgithub Feb 3, 2025
89f0811
fix(frontend): add retrocompatibility for dialog close button
yassinedorbozgithub Feb 3, 2025
7ef81e7
fix(frontend): update dialog close button
yassinedorbozgithub Feb 3, 2025
fce6320
fix(frontend): include minor updates
yassinedorbozgithub Feb 3, 2025
0681893
fix(frontend): add input error attribute
yassinedorbozgithub Feb 3, 2025
5c5db5b
Merge branch 'main' into refactor/category-dialog
yassinedorbozgithub Feb 4, 2025
0b19f45
fix(frontend): apply feedback updates
yassinedorbozgithub Feb 4, 2025
658bfbc
fix(frontend): apply feedback updates
yassinedorbozgithub Feb 4, 2025
dfff8ca
fix(frontend): update categoryForm to use mutate
yassinedorbozgithub Feb 4, 2025
b7351e5
fix(frontend): remove submitAsync function
yassinedorbozgithub Feb 4, 2025
72ffde9
fix(frontend): include minor changes
yassinedorbozgithub Feb 4, 2025
2962540
fix(frontend): update variable name
yassinedorbozgithub Feb 4, 2025
1398250
fix(frontend): include minor changes
yassinedorbozgithub Feb 4, 2025
7a19ba6
fix(frontend): add disabled attribute for category delete button
yassinedorbozgithub Feb 4, 2025
64707c5
fix(frontend): add feedback updates
yassinedorbozgithub Feb 4, 2025
268dd68
fix(frontend): add dialog extra props
yassinedorbozgithub Feb 4, 2025
5197e57
fix(frontend): update confirm dialog first prop type
yassinedorbozgithub Feb 4, 2025
33ce8cc
fix(frontend): remove unnecessary useMemo
yassinedorbozgithub Feb 4, 2025
a6d2fae
fix(frontend): update DialogActions padding
yassinedorbozgithub Feb 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 42 additions & 0 deletions frontend/src/app-components/buttons/FormButtons.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* 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 CheckIcon from "@mui/icons-material/Check";
import CloseIcon from "@mui/icons-material/Close";
import { Button } from "@mui/material";

import { useTranslate } from "@/hooks/useTranslate";
import { FormButtonsProps } from "@/types/common/dialogs.types";

export const FormButtons = <T,>({
marrouchi marked this conversation as resolved.
Show resolved Hide resolved
onCancel,
onConfirm,
}: FormButtonsProps<T>) => {
const { t } = useTranslate();

return (
<>
marrouchi marked this conversation as resolved.
Show resolved Hide resolved
<Button
type="submit"
variant="contained"
onClick={onConfirm}
marrouchi marked this conversation as resolved.
Show resolved Hide resolved
startIcon={<CheckIcon />}
>
{t("button.submit")}
</Button>
<Button
color="error"
variant="outlined"
onClick={onCancel}
startIcon={<CloseIcon />}
>
{t("button.cancel")}
</Button>
</>
);
};
20 changes: 14 additions & 6 deletions frontend/src/app-components/dialogs/DialogTitle.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

import CloseIcon from "@mui/icons-material/Close";
import {
IconButton,
DialogTitle as MuiDialogTitle,
Typography,
styled,
DialogTitle as MuiDialogTitle,
IconButton,
} from "@mui/material";

const StyledDialogTitle = styled(Typography)(() => ({
Expand All @@ -24,12 +24,20 @@ export const DialogTitle = ({
onClose,
}: {
children: React.ReactNode;
onClose?: () => void;
onClose?:
| ((event: {}, reason: "backdropClick" | "escapeKeyDown") => void)
| undefined;
}) => (
<MuiDialogTitle>
<StyledDialogTitle>{children}</StyledDialogTitle>
<IconButton size="small" aria-label="close" onClick={onClose}>
<CloseIcon />
</IconButton>
{onClose && (
<IconButton
size="small"
aria-label="close"
onClick={(e) => onClose(e, "backdropClick")}
>
<CloseIcon />
</IconButton>
)}
</MuiDialogTitle>
);
36 changes: 36 additions & 0 deletions frontend/src/app-components/dialogs/FormDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 { Dialog, DialogActions, DialogContent } from "@mui/material";

import { DialogTitle } from "@/app-components/dialogs";
import { FormDialogProps } from "@/types/common/dialogs.types";

import { FormButtons } from "../buttons/FormButtons";

export const FormDialog = <T,>({
title,
children,
onConfirm,
...rest
}: FormDialogProps<T>) => {
return (
<Dialog fullWidth {...rest}>
<DialogTitle onClose={() => rest.onClose?.({}, "backdropClick")}>
marrouchi marked this conversation as resolved.
Show resolved Hide resolved
{title}
</DialogTitle>
<DialogContent>{children}</DialogContent>
<DialogActions>
<FormButtons<T>
onCancel={() => rest.onClose?.({}, "backdropClick")}
onConfirm={onConfirm}
/>
</DialogActions>
</Dialog>
);
};
56 changes: 56 additions & 0 deletions frontend/src/app-components/dialogs/confirm/ConfirmDialog.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* 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 { Button, Dialog, DialogActions, DialogContent } from "@mui/material";
import { FC, ReactNode } from "react";

import { ConfirmOptions, DialogProps } from "@/types/common/dialogs.types";

import { DialogTitle } from "../DialogTitle";

import { useDialogLoadingButton } from "./hooks/useDialogLoadingButton";

export interface ConfirmDialogPayload extends ConfirmOptions {
msg: ReactNode;
}

export interface ConfirmDialogProps
extends DialogProps<ConfirmDialogPayload, boolean> {}

export const ConfirmDialog: FC<ConfirmDialogProps> = ({ payload, ...rest }) => {
const cancelButtonProps = useDialogLoadingButton(() => rest.onClose(false));
const okButtonProps = useDialogLoadingButton(() => rest.onClose(true));

return (
<Dialog
maxWidth="sm"
fullWidth
{...rest}
onClose={() => rest.onClose(false)}
>
<DialogTitle onClose={() => rest.onClose(false)}>
{payload.title}
</DialogTitle>
<DialogContent>{payload.msg}</DialogContent>
<DialogActions>
<Button
color={payload.severity || "error"}
variant="contained"
disabled={!open}
autoFocus
{...okButtonProps}
>
{payload.okText}
</Button>
<Button variant="outlined" disabled={!open} {...cancelButtonProps}>
{payload.cancelText}
</Button>
</DialogActions>
</Dialog>
);
};
27 changes: 27 additions & 0 deletions frontend/src/app-components/dialogs/confirm/ConfirmDialogBody.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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 ErrorIcon from "@mui/icons-material/Error";
import { Grid, Typography } from "@mui/material";

import { useTranslate } from "@/hooks/useTranslate";

export const ConfirmDialogBody = () => {
const { t } = useTranslate();

return (
<Grid container gap={1}>
<Grid item height="28px">
<ErrorIcon sx={{ fontSize: "28px" }} color="error" />
</Grid>
<Grid item alignSelf="center">
<Typography>{t("message.item_delete_confirm")}</Typography>
marrouchi marked this conversation as resolved.
Show resolved Hide resolved
</Grid>
</Grid>
);
};
Original file line number Diff line number Diff line change
@@ -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 { useState } from "react";

export const useDialogLoadingButton = (onClose: () => Promise<void>) => {
const [loading, setLoading] = useState(false);
const handleClick = async () => {
try {
setLoading(true);
await onClose();
} finally {
setLoading(false);
}
};

return {
onClick: handleClick,
loading,
};
};
3 changes: 3 additions & 0 deletions frontend/src/app-components/dialogs/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
* 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).
*/

export * from "./confirm/ConfirmDialog";
export * from "./confirm/ConfirmDialogBody";
export * from "./DeleteDialog";
export * from "./DialogTitle";
export * from "./FormDialog";
export * from "./layouts/ContentContainer";
export * from "./layouts/ContentItem";
113 changes: 0 additions & 113 deletions frontend/src/components/categories/CategoryDialog.tsx

This file was deleted.

Loading