mirror of
https://github.com/hexastack/hexabot
synced 2025-02-22 20:38:32 +00:00
refactor(frontend): remove old resources
This commit is contained in:
parent
95a4182b8f
commit
90a7c55646
@ -1,63 +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 ErrorIcon from "@mui/icons-material/Error";
|
||||
import {
|
||||
Button,
|
||||
Dialog,
|
||||
DialogActions,
|
||||
DialogContent,
|
||||
Grid,
|
||||
Typography,
|
||||
} from "@mui/material";
|
||||
|
||||
import { DialogTitle } from "@/app-components/dialogs/DialogTitle";
|
||||
import { DialogControl } from "@/hooks/useDialog";
|
||||
import { useTranslate } from "@/hooks/useTranslate";
|
||||
|
||||
export type DeleteDialogProps<T = string> = DialogControl<T>;
|
||||
export const DeleteDialog = <T extends any = string>({
|
||||
open,
|
||||
callback,
|
||||
closeDialog: closeFunction,
|
||||
}: DeleteDialogProps<T>) => {
|
||||
const { t } = useTranslate();
|
||||
|
||||
return (
|
||||
<Dialog open={open} fullWidth onClose={closeFunction}>
|
||||
<DialogTitle onClose={closeFunction}>{t("title.warning")}</DialogTitle>
|
||||
<DialogContent>
|
||||
<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>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<Button
|
||||
variant="contained"
|
||||
color="error"
|
||||
onClick={() => {
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
}}
|
||||
autoFocus
|
||||
>
|
||||
{t("button.yes")}
|
||||
</Button>
|
||||
<Button variant="outlined" onClick={closeFunction}>
|
||||
{t("button.no")}
|
||||
</Button>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
@ -1,86 +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,
|
||||
Grid,
|
||||
MenuItem,
|
||||
Select,
|
||||
} from "@mui/material";
|
||||
import { FC, useState } from "react";
|
||||
|
||||
import { DialogTitle } from "@/app-components/dialogs/DialogTitle";
|
||||
import { DialogControl } from "@/hooks/useDialog";
|
||||
import { useTranslate } from "@/hooks/useTranslate";
|
||||
import { ICategory } from "@/types/category.types";
|
||||
|
||||
export interface MoveDialogProps extends DialogControl<string> {
|
||||
categories: ICategory[];
|
||||
callback?: (newCategoryId?: string) => Promise<void>;
|
||||
openDialog: (data?: string) => void;
|
||||
}
|
||||
|
||||
export const MoveDialog: FC<MoveDialogProps> = ({
|
||||
open,
|
||||
callback,
|
||||
closeDialog,
|
||||
categories,
|
||||
}: MoveDialogProps) => {
|
||||
const { t } = useTranslate();
|
||||
const [selectedCategoryId, setSelectedCategoryId] = useState<string>("");
|
||||
const handleMove = async () => {
|
||||
if (selectedCategoryId && callback) {
|
||||
await callback(selectedCategoryId);
|
||||
closeDialog();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open={open} fullWidth onClose={closeDialog}>
|
||||
<DialogTitle onClose={closeDialog}>
|
||||
{t("message.select_category")}
|
||||
</DialogTitle>
|
||||
<DialogContent>
|
||||
<Grid container direction="column" gap={2}>
|
||||
<Grid item>
|
||||
<Select
|
||||
value={selectedCategoryId}
|
||||
onChange={(e) => setSelectedCategoryId(e.target.value as string)}
|
||||
fullWidth
|
||||
displayEmpty
|
||||
>
|
||||
<MenuItem value="" disabled>
|
||||
{t("label.category")}
|
||||
</MenuItem>
|
||||
{categories.map((category) => (
|
||||
<MenuItem key={category.id} value={category.id}>
|
||||
{category.label}
|
||||
</MenuItem>
|
||||
))}
|
||||
</Select>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</DialogContent>
|
||||
<DialogActions>
|
||||
<Button
|
||||
variant="contained"
|
||||
onClick={handleMove}
|
||||
disabled={!selectedCategoryId}
|
||||
>
|
||||
{t("button.move")}
|
||||
</Button>
|
||||
<Button variant="outlined" onClick={closeDialog}>
|
||||
{t("button.cancel")}
|
||||
</Button>
|
||||
</DialogActions>
|
||||
</Dialog>
|
||||
);
|
||||
};
|
@ -8,7 +8,6 @@
|
||||
|
||||
export * from "./confirm/ConfirmDialog";
|
||||
export * from "./confirm/ConfirmDialogBody";
|
||||
export * from "./DeleteDialog";
|
||||
export * from "./DialogTitle";
|
||||
export * from "./FormDialog";
|
||||
export * from "./GenericFormDialog";
|
||||
|
@ -1,43 +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 { DialogProps } from "@mui/material";
|
||||
import { useState } from "react";
|
||||
|
||||
export type DialogControlProps<T, C = never> = Omit<
|
||||
DialogControl<T, C>,
|
||||
"openDialog"
|
||||
>;
|
||||
export type DialogControl<T = null, C = never> = DialogProps & {
|
||||
data?: T;
|
||||
callback?: (data?: C) => void;
|
||||
openDialog: (data?: T) => void;
|
||||
closeDialog: () => void;
|
||||
};
|
||||
|
||||
export const useDialog = <T,>(initialState: boolean): DialogControl<T> => {
|
||||
const [open, setOpen] = useState(initialState);
|
||||
const [data, setData] = useState<T | undefined>(undefined);
|
||||
const openDialog = (data?: T) => {
|
||||
if (data) setData(data);
|
||||
setOpen(true);
|
||||
};
|
||||
const closeDialog = (event?: React.MouseEvent | Event, reason?: string) => {
|
||||
if (reason !== "backdropClick") {
|
||||
setOpen(false);
|
||||
}
|
||||
};
|
||||
|
||||
return { open, openDialog, closeDialog, data };
|
||||
};
|
||||
|
||||
export const getDisplayDialogs = <T,>({
|
||||
open,
|
||||
closeDialog,
|
||||
data,
|
||||
}: DialogControl<T>): DialogControlProps<T> => ({ open, closeDialog, data });
|
Loading…
Reference in New Issue
Block a user