https://github.com/marmelab/react-admin/issues/4349#issuecomment-578594735
*/
<>
{record.quarantined_by && (
{/*
Button instead BooleanField for
consistent appearance and position in the column
*/}
)}
{record.safe_from_quarantine && (
)}
{!record.safe_from_quarantine && !record.quarantined_by && (
)}
>
);
};
export const QuarantineMediaButton = (props: ButtonProps) => {
const record = useRecordContext();
const translate = useTranslate();
const refresh = useRefresh();
const notify = useNotify();
const [create, { isLoading }] = useCreate();
const [deleteOne] = useDelete();
if (!record) return null;
const handleQuarantaine = () => {
create(
"quarantine_media",
{ data: record },
{
onSuccess: () => {
notify("resources.quarantine_media.action.send_success");
refresh();
},
onError: () =>
notify("resources.quarantine_media.action.send_failure", {
type: "error",
}),
}
);
};
const handleRemoveQuarantaine = () => {
deleteOne(
"quarantine_media",
{ id: record.id, previousData: record },
{
onSuccess: () => {
notify("resources.quarantine_media.action.send_success");
refresh();
},
onError: () =>
notify("resources.quarantine_media.action.send_failure", {
type: "error",
}),
}
);
};
return (
<>
{record.safe_from_quarantine && (
)}
{record.quarantined_by && (
)}
{!record.safe_from_quarantine && !record.quarantined_by && (
)}
>
);
};
export const ViewMediaButton = ({ media_id, label }) => {
const translate = useTranslate();
const url = getMediaUrl(media_id);
return (
{label}
);
};
export const MediaIDField = ({ source }) => {
const homeserver = storage.getItem("home_server");
const record = useRecordContext();
if (!record) return null;
const src = get(record, source)?.toString();
if (!src) return null;
return
;
};
export const MXCField = ({ source }) => {
const record = useRecordContext();
if (!record) return null;
const src = get(record, source)?.toString();
if (!src) return null;
const media_id = src.replace("mxc://", "");
return
;
};