Update dataProvider hooks

Change-Id: Ic19f7a6ad97b1392c96c91a19e76b8983c9d0fd2
This commit is contained in:
dklimpel 2023-02-08 09:24:02 +01:00 committed by Manuel Stahl
parent 51def5775d
commit a222af273f
5 changed files with 35 additions and 27 deletions

View File

@ -50,7 +50,7 @@ const ServerNoticeDialog = ({ open, loading, onClose, onSend }) => {
<SimpleForm <SimpleForm
toolbar={<ServerNoticeToolbar />} toolbar={<ServerNoticeToolbar />}
redirect={false} redirect={false}
save={onSend} onSubmit={onSend}
> >
<TextInput <TextInput
source="body" source="body"
@ -71,14 +71,15 @@ export const ServerNoticeButton = () => {
const record = useRecordContext(); const record = useRecordContext();
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const notify = useNotify(); const notify = useNotify();
const [create, { isloading }] = useCreate("servernotices"); const [create, { isloading }] = useCreate();
const handleDialogOpen = () => setOpen(true); const handleDialogOpen = () => setOpen(true);
const handleDialogClose = () => setOpen(false); const handleDialogClose = () => setOpen(false);
const handleSend = values => { const handleSend = values => {
create( create(
{ payload: { data: { id: record.id, ...values } } }, "servernotices",
{ data: { id: record.id, ...values } },
{ {
onSuccess: () => { onSuccess: () => {
notify("resources.servernotices.action.send_success"); notify("resources.servernotices.action.send_success");

View File

@ -53,7 +53,7 @@ export const DestinationReconnectButton = props => {
const record = useRecordContext(); const record = useRecordContext();
const refresh = useRefresh(); const refresh = useRefresh();
const notify = useNotify(); const notify = useNotify();
const [handleReconnect, { isLoading }] = useDelete("destinations"); const [handleReconnect, { isLoading }] = useDelete();
// Reconnect is not required if no error has occurred. (`failure_ts`) // Reconnect is not required if no error has occurred. (`failure_ts`)
if (!record || !record.failure_ts) return null; if (!record || !record.failure_ts) return null;
@ -63,7 +63,8 @@ export const DestinationReconnectButton = props => {
e.stopPropagation(); e.stopPropagation();
handleReconnect( handleReconnect(
{ payload: { id: record.id } }, "destinations",
{ id: record.id },
{ {
onSuccess: () => { onSuccess: () => {
notify("ra.notification.updated", { notify("ra.notification.updated", {

View File

@ -17,7 +17,7 @@ export const DeviceRemoveButton = props => {
const refresh = useRefresh(); const refresh = useRefresh();
const notify = useNotify(); const notify = useNotify();
const [removeDevice, { isLoading }] = useDelete("devices"); const [removeDevice, { isLoading }] = useDelete();
if (!record) return null; if (!record) return null;
@ -26,7 +26,8 @@ export const DeviceRemoveButton = props => {
const handleConfirm = () => { const handleConfirm = () => {
removeDevice( removeDevice(
{ payload: { id: record.id, user_id: record.user_id } }, "devices",
{ id: record.id, meta: { user_id: record.user_id } },
{ {
onSuccess: () => { onSuccess: () => {
notify("resources.devices.action.erase.success"); notify("resources.devices.action.erase.success");

View File

@ -97,14 +97,15 @@ export const DeleteMediaButton = props => {
const theme = useTheme(); const theme = useTheme();
const [open, setOpen] = useState(false); const [open, setOpen] = useState(false);
const notify = useNotify(); const notify = useNotify();
const [deleteOne, { isLoading }] = useDelete("delete_media"); const [deleteOne, { isLoading }] = useDelete();
const handleDialogOpen = () => setOpen(true); const handleDialogOpen = () => setOpen(true);
const handleDialogClose = () => setOpen(false); const handleDialogClose = () => setOpen(false);
const handleSend = values => { const handleSend = values => {
deleteOne( deleteOne(
{ payload: { ...values } }, "delete_media",
{ id: values.id },
{ {
onSuccess: () => { onSuccess: () => {
notify("resources.delete_media.action.send_success"); notify("resources.delete_media.action.send_success");
@ -151,14 +152,15 @@ export const ProtectMediaButton = props => {
const translate = useTranslate(); const translate = useTranslate();
const refresh = useRefresh(); const refresh = useRefresh();
const notify = useNotify(); const notify = useNotify();
const [create, { loading }] = useCreate("protect_media"); const [create, { isLoading }] = useCreate();
const [deleteOne] = useDelete("protect_media"); const [deleteOne] = useDelete();
if (!record) return null; if (!record) return null;
const handleProtect = () => { const handleProtect = () => {
create( create(
{ payload: { data: record } }, "protect_media",
{ data: record },
{ {
onSuccess: () => { onSuccess: () => {
notify("resources.protect_media.action.send_success"); notify("resources.protect_media.action.send_success");
@ -174,7 +176,8 @@ export const ProtectMediaButton = props => {
const handleUnprotect = () => { const handleUnprotect = () => {
deleteOne( deleteOne(
{ payload: { ...record } }, "protect_media",
{ id: record.id },
{ {
onSuccess: () => { onSuccess: () => {
notify("resources.protect_media.action.send_success"); notify("resources.protect_media.action.send_success");
@ -219,7 +222,7 @@ export const ProtectMediaButton = props => {
arrow arrow
> >
<div> <div>
<Button onClick={handleUnprotect} disabled={loading}> <Button onClick={handleUnprotect} disabled={isLoading}>
<LockIcon /> <LockIcon />
</Button> </Button>
</div> </div>
@ -232,7 +235,7 @@ export const ProtectMediaButton = props => {
})} })}
> >
<div> <div>
<Button onClick={handleProtect} disabled={loading}> <Button onClick={handleProtect} disabled={isLoading}>
<LockOpenIcon /> <LockOpenIcon />
</Button> </Button>
</div> </div>
@ -247,14 +250,15 @@ export const QuarantineMediaButton = props => {
const translate = useTranslate(); const translate = useTranslate();
const refresh = useRefresh(); const refresh = useRefresh();
const notify = useNotify(); const notify = useNotify();
const [create, { loading }] = useCreate("quarantine_media"); const [create, { isLoading }] = useCreate();
const [deleteOne] = useDelete("quarantine_media"); const [deleteOne] = useDelete();
if (!record) return null; if (!record) return null;
const handleQuarantaine = () => { const handleQuarantaine = () => {
create( create(
{ payload: { data: record } }, "quarantine_media",
{ data: record },
{ {
onSuccess: () => { onSuccess: () => {
notify("resources.quarantine_media.action.send_success"); notify("resources.quarantine_media.action.send_success");
@ -270,7 +274,8 @@ export const QuarantineMediaButton = props => {
const handleRemoveQuarantaine = () => { const handleRemoveQuarantaine = () => {
deleteOne( deleteOne(
{ payload: { ...record } }, "quarantine_media",
{ id: record.id },
{ {
onSuccess: () => { onSuccess: () => {
notify("resources.quarantine_media.action.send_success"); notify("resources.quarantine_media.action.send_success");
@ -306,7 +311,7 @@ export const QuarantineMediaButton = props => {
})} })}
> >
<div> <div>
<Button onClick={handleRemoveQuarantaine} disabled={loading}> <Button onClick={handleRemoveQuarantaine} disabled={isLoading}>
<BlockIcon color="error" /> <BlockIcon color="error" />
</Button> </Button>
</div> </div>
@ -319,7 +324,7 @@ export const QuarantineMediaButton = props => {
})} })}
> >
<div> <div>
<Button onClick={handleQuarantaine} disabled={loading}> <Button onClick={handleQuarantaine} disabled={isLoading}>
<BlockIcon /> <BlockIcon />
</Button> </Button>
</div> </div>

View File

@ -98,7 +98,7 @@ const resourceMap = {
}), }),
delete: params => ({ delete: params => ({
endpoint: `/_synapse/admin/v2/users/${encodeURIComponent( endpoint: `/_synapse/admin/v2/users/${encodeURIComponent(
params.user_id params.meta.user_id
)}/devices/${params.id}`, )}/devices/${params.id}`,
}), }),
}, },
@ -184,9 +184,9 @@ const resourceMap = {
delete: params => ({ delete: params => ({
endpoint: `/_synapse/admin/v1/media/${localStorage.getItem( endpoint: `/_synapse/admin/v1/media/${localStorage.getItem(
"home_server" "home_server"
)}/delete?before_ts=${params.before_ts}&size_gt=${ )}/delete?before_ts=${params.meta.before_ts}&size_gt=${
params.size_gt params.meta.size_gt
}&keep_profiles=${params.keep_profiles}`, }&keep_profiles=${params.meta.keep_profiles}`,
method: "POST", method: "POST",
}), }),
}, },
@ -197,7 +197,7 @@ const resourceMap = {
method: "POST", method: "POST",
}), }),
delete: params => ({ delete: params => ({
endpoint: `/_synapse/admin/v1/media/unprotect/${params.media_id}`, endpoint: `/_synapse/admin/v1/media/unprotect/${params.id}`,
method: "POST", method: "POST",
}), }),
}, },
@ -212,7 +212,7 @@ const resourceMap = {
delete: params => ({ delete: params => ({
endpoint: `/_synapse/admin/v1/media/unquarantine/${localStorage.getItem( endpoint: `/_synapse/admin/v1/media/unquarantine/${localStorage.getItem(
"home_server" "home_server"
)}/${params.media_id}`, )}/${params.id}`,
method: "POST", method: "POST",
}), }),
}, },