From ec0fc14b6836ab7eb510b02d6463f33133935066 Mon Sep 17 00:00:00 2001 From: Manuel Stahl Date: Wed, 24 Apr 2024 10:13:56 +0200 Subject: [PATCH] Use custom data provider method for "delete_media" This is not a REST endpoint, so it's better to use a custom method, see https://marmelab.com/react-admin/DataProviders.html#adding-custom-methods Change-Id: I256286949e77b998f759f671b2d4e9790f8ca39c --- src/components/media.tsx | 51 ++++++++++++++++++------------------- src/i18n/de.ts | 32 +++++++++++------------ src/i18n/en.ts | 32 +++++++++++------------ src/i18n/fa.ts | 32 +++++++++++------------ src/i18n/fr.ts | 32 +++++++++++------------ src/i18n/index.d.ts | 32 +++++++++++------------ src/i18n/it.ts | 32 +++++++++++------------ src/i18n/zh.ts | 32 +++++++++++------------ src/synapse/dataProvider.ts | 49 +++++++++++++++++++++++++++-------- 9 files changed, 175 insertions(+), 149 deletions(-) diff --git a/src/components/media.tsx b/src/components/media.tsx index 29fc204..893b1af 100644 --- a/src/components/media.tsx +++ b/src/components/media.tsx @@ -21,15 +21,18 @@ import { Toolbar, ToolbarProps, useCreate, + useDataProvider, useDelete, useNotify, useRecordContext, useRefresh, useTranslate, } from "react-admin"; +import { useMutation } from "react-query"; import { Link } from "react-router-dom"; import { dateParser } from "./date"; +import { DeleteMediaParams, SynapseDataProvider } from "../synapse/dataProvider"; import { getMediaUrl } from "../synapse/synapse"; const DeleteMediaDialog = ({ open, onClose, onSubmit }) => { @@ -37,7 +40,7 @@ const DeleteMediaDialog = ({ open, onClose, onSubmit }) => { const DeleteMediaToolbar = (props: ToolbarProps) => ( - } /> + } /> @@ -46,21 +49,21 @@ const DeleteMediaDialog = ({ open, onClose, onSubmit }) => { return ( - {translate("resources.delete_media.action.send")} + {translate("delete_media.action.send")} - {translate("resources.delete_media.helper.send")} + {translate("delete_media.helper.send")} } onSubmit={onSubmit}> { @@ -81,34 +84,30 @@ export const DeleteMediaButton = (props: ButtonProps) => { const theme = useTheme(); const [open, setOpen] = useState(false); const notify = useNotify(); - const [deleteOne, { isLoading }] = useDelete(); + const dataProvider = useDataProvider(); + const { mutate: deleteMedia, isLoading } = useMutation( + (values: DeleteMediaParams) => dataProvider.deleteMedia(values), + { + onSuccess: () => { + notify("delete_media.action.send_success"); + closeDialog(); + }, + onError: () => { + notify("delete_media.action.send_failure", { + type: "error", + }); + }, + } + ); const openDialog = () => setOpen(true); const closeDialog = () => setOpen(false); - const deleteMedia = (values: { before_ts: string; size_gt: number; keep_profiles: boolean }) => { - deleteOne( - "delete_media", - // needs meta.before_ts, meta.size_gt and meta.keep_profiles - { meta: values }, - { - onSuccess: () => { - notify("resources.delete_media.action.send_success"); - closeDialog(); - }, - onError: () => - notify("resources.delete_media.action.send_failure", { - type: "error", - }), - } - ); - }; - return ( <>