Merge pull request #585 from Hexastack/fix/remove-delete-operation-media-library

fix: remove delete opearation
This commit is contained in:
Med Marrouchi 2025-01-20 14:32:42 +01:00 committed by GitHub
commit 8c14320239
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -12,24 +12,15 @@ import { Box, Grid, Paper } from "@mui/material";
import { GridColDef, GridEventListener } from "@mui/x-data-grid"; import { GridColDef, GridEventListener } from "@mui/x-data-grid";
import AttachmentThumbnail from "@/app-components/attachment/AttachmentThumbnail"; import AttachmentThumbnail from "@/app-components/attachment/AttachmentThumbnail";
import { DeleteDialog } from "@/app-components/dialogs/DeleteDialog";
import { FilterTextfield } from "@/app-components/inputs/FilterTextfield"; import { FilterTextfield } from "@/app-components/inputs/FilterTextfield";
import {
ActionColumnLabel,
useActionColumns,
} from "@/app-components/tables/columns/getColumns";
import { renderHeader } from "@/app-components/tables/columns/renderHeader"; import { renderHeader } from "@/app-components/tables/columns/renderHeader";
import { DataGrid } from "@/app-components/tables/DataGrid"; import { DataGrid } from "@/app-components/tables/DataGrid";
import { useDelete } from "@/hooks/crud/useDelete";
import { useFind } from "@/hooks/crud/useFind"; import { useFind } from "@/hooks/crud/useFind";
import { useDialog } from "@/hooks/useDialog";
import useFormattedFileSize from "@/hooks/useFormattedFileSize"; import useFormattedFileSize from "@/hooks/useFormattedFileSize";
import { useSearch } from "@/hooks/useSearch"; import { useSearch } from "@/hooks/useSearch";
import { useToast } from "@/hooks/useToast";
import { useTranslate } from "@/hooks/useTranslate"; import { useTranslate } from "@/hooks/useTranslate";
import { PageHeader } from "@/layout/content/PageHeader"; import { PageHeader } from "@/layout/content/PageHeader";
import { EntityType } from "@/services/types"; import { EntityType } from "@/services/types";
import { PermissionAction } from "@/types/permission.types";
import { TFilterStringFields } from "@/types/search.types"; import { TFilterStringFields } from "@/types/search.types";
import { getDateTimeFormatter } from "@/utils/date"; import { getDateTimeFormatter } from "@/utils/date";
@ -46,8 +37,6 @@ type MediaLibraryProps = {
export const MediaLibrary = ({ onSelect, accept }: MediaLibraryProps) => { export const MediaLibrary = ({ onSelect, accept }: MediaLibraryProps) => {
const { t } = useTranslate(); const { t } = useTranslate();
const { toast } = useToast();
const deleteDialogCtl = useDialog<string>(false);
const formatFileSize = useFormattedFileSize(); const formatFileSize = useFormattedFileSize();
const { onSearch, searchPayload } = useSearch<IAttachment>({ const { onSearch, searchPayload } = useSearch<IAttachment>({
$iLike: ["name"], $iLike: ["name"],
@ -77,26 +66,6 @@ export const MediaLibrary = ({ onSelect, accept }: MediaLibraryProps) => {
}, },
}, },
); );
const { mutateAsync: deleteCategory } = useDelete(EntityType.ATTACHMENT, {
onError: () => {
toast.error(t("message.internal_server_error"));
},
onSuccess: () => {
deleteDialogCtl.closeDialog();
toast.success(t("message.item_delete_success"));
},
});
const actionColumns = useActionColumns<IAttachment>(
EntityType.ATTACHMENT,
[
{
label: ActionColumnLabel.Delete,
action: (row) => deleteDialogCtl.openDialog(row.id),
requires: [PermissionAction.DELETE],
},
],
t("label.operations"),
);
const columns: GridColDef<IAttachment>[] = [ const columns: GridColDef<IAttachment>[] = [
{ field: "id", headerName: "ID" }, { field: "id", headerName: "ID" },
{ {
@ -169,17 +138,10 @@ export const MediaLibrary = ({ onSelect, accept }: MediaLibraryProps) => {
valueGetter: (params) => valueGetter: (params) =>
t("datetime.updated_at", getDateTimeFormatter(params)), t("datetime.updated_at", getDateTimeFormatter(params)),
}, },
actionColumns,
]; ];
return ( return (
<Grid container gap={3} flexDirection="column"> <Grid container gap={3} flexDirection="column">
<DeleteDialog
{...deleteDialogCtl}
callback={() => {
if (deleteDialogCtl?.data) deleteCategory(deleteDialogCtl.data);
}}
/>
<PageHeader title={t("title.media_library")} icon={DriveFolderUploadIcon}> <PageHeader title={t("title.media_library")} icon={DriveFolderUploadIcon}>
<Grid <Grid
justifyContent="flex-end" justifyContent="flex-end"