refactor RoomDirectory
This commit is contained in:
parent
add25e7281
commit
04b653fe6c
@ -14,6 +14,7 @@ import {
|
|||||||
TextField,
|
TextField,
|
||||||
TopToolbar,
|
TopToolbar,
|
||||||
useCreate,
|
useCreate,
|
||||||
|
useDataProvider,
|
||||||
useListContext,
|
useListContext,
|
||||||
useNotify,
|
useNotify,
|
||||||
useTranslate,
|
useTranslate,
|
||||||
@ -28,12 +29,11 @@ const RoomDirectoryPagination = () => (
|
|||||||
<Pagination rowsPerPageOptions={[100, 500, 1000, 2000]} />
|
<Pagination rowsPerPageOptions={[100, 500, 1000, 2000]} />
|
||||||
);
|
);
|
||||||
|
|
||||||
export const RoomDirectoryDeleteButton = props => {
|
export const RoomDirectoryDeleteButton = () => {
|
||||||
const translate = useTranslate();
|
const translate = useTranslate();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<DeleteButton
|
<DeleteButton
|
||||||
{...props}
|
|
||||||
label="resources.room_directory.action.erase"
|
label="resources.room_directory.action.erase"
|
||||||
redirect={false}
|
redirect={false}
|
||||||
mutationMode="pessimistic"
|
mutationMode="pessimistic"
|
||||||
@ -49,9 +49,8 @@ export const RoomDirectoryDeleteButton = props => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const RoomDirectoryBulkDeleteButton = props => (
|
export const RoomDirectoryBulkDeleteButton = () => (
|
||||||
<BulkDeleteButton
|
<BulkDeleteButton
|
||||||
{...props}
|
|
||||||
label="resources.room_directory.action.erase"
|
label="resources.room_directory.action.erase"
|
||||||
mutationMode="pessimistic"
|
mutationMode="pessimistic"
|
||||||
confirmTitle="resources.room_directory.action.title"
|
confirmTitle="resources.room_directory.action.title"
|
||||||
@ -66,29 +65,30 @@ export const RoomDirectoryBulkSaveButton = () => {
|
|||||||
const notify = useNotify();
|
const notify = useNotify();
|
||||||
const refresh = useRefresh();
|
const refresh = useRefresh();
|
||||||
const unselectAll = useUnselectAll("rooms");
|
const unselectAll = useUnselectAll("rooms");
|
||||||
const { createMany, isloading } = useMutation();
|
const dataProvider = useDataProvider();
|
||||||
|
const { mutate, isloading } = useMutation(
|
||||||
const handleSend = values => {
|
() =>
|
||||||
createMany(
|
dataProvider.createMany("room_directory", {
|
||||||
["room_directory", "createMany", { ids: selectedIds, data: {} }],
|
ids: selectedIds,
|
||||||
{
|
data: {},
|
||||||
onSuccess: data => {
|
}),
|
||||||
notify("resources.room_directory.action.send_success");
|
{
|
||||||
unselectAll();
|
onSuccess: () => {
|
||||||
refresh();
|
notify("resources.room_directory.action.send_success");
|
||||||
},
|
unselectAll();
|
||||||
onError: error =>
|
refresh();
|
||||||
notify("resources.room_directory.action.send_failure", {
|
},
|
||||||
type: "error",
|
onError: () =>
|
||||||
}),
|
notify("resources.room_directory.action.send_failure", {
|
||||||
}
|
type: "error",
|
||||||
);
|
}),
|
||||||
};
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<Button
|
||||||
label="resources.room_directory.action.create"
|
label="resources.room_directory.action.create"
|
||||||
onClick={handleSend}
|
onClick={mutate}
|
||||||
disabled={isloading}
|
disabled={isloading}
|
||||||
>
|
>
|
||||||
<FolderSharedIcon />
|
<FolderSharedIcon />
|
||||||
@ -107,11 +107,11 @@ export const RoomDirectorySaveButton = () => {
|
|||||||
"room_directory",
|
"room_directory",
|
||||||
{ data: { id: record.id } },
|
{ data: { id: record.id } },
|
||||||
{
|
{
|
||||||
onSuccess: data => {
|
onSuccess: () => {
|
||||||
notify("resources.room_directory.action.send_success");
|
notify("resources.room_directory.action.send_success");
|
||||||
refresh();
|
refresh();
|
||||||
},
|
},
|
||||||
onError: error =>
|
onError: () =>
|
||||||
notify("resources.room_directory.action.send_failure", {
|
notify("resources.room_directory.action.send_failure", {
|
||||||
type: "error",
|
type: "error",
|
||||||
}),
|
}),
|
||||||
|
@ -55,7 +55,7 @@ const RoomPagination = () => (
|
|||||||
<Pagination rowsPerPageOptions={[10, 25, 50, 100, 500, 1000]} />
|
<Pagination rowsPerPageOptions={[10, 25, 50, 100, 500, 1000]} />
|
||||||
);
|
);
|
||||||
|
|
||||||
const RoomTitle = props => {
|
const RoomTitle = () => {
|
||||||
const record = useRecordContext();
|
const record = useRecordContext();
|
||||||
const translate = useTranslate();
|
const translate = useTranslate();
|
||||||
var name = "";
|
var name = "";
|
||||||
@ -70,23 +70,18 @@ const RoomTitle = props => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const RoomShowActions = ({ data, resource }) => {
|
const RoomShowActions = () => {
|
||||||
|
const record = useRecordContext();
|
||||||
var roomDirectoryStatus = "";
|
var roomDirectoryStatus = "";
|
||||||
if (data) {
|
if (record) {
|
||||||
roomDirectoryStatus = data.public;
|
roomDirectoryStatus = record.public;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TopToolbar>
|
<TopToolbar>
|
||||||
{roomDirectoryStatus === false && (
|
{roomDirectoryStatus === false && <RoomDirectorySaveButton />}
|
||||||
<RoomDirectorySaveButton record={data} />
|
{roomDirectoryStatus === true && <RoomDirectoryDeleteButton />}
|
||||||
)}
|
|
||||||
{roomDirectoryStatus === true && (
|
|
||||||
<RoomDirectoryDeleteButton record={data} />
|
|
||||||
)}
|
|
||||||
<DeleteButton
|
<DeleteButton
|
||||||
record={data}
|
|
||||||
resource={resource}
|
|
||||||
mutationMode="pessimistic"
|
mutationMode="pessimistic"
|
||||||
confirmTitle="resources.rooms.action.erase.title"
|
confirmTitle="resources.rooms.action.erase.title"
|
||||||
confirmContent="resources.rooms.action.erase.content"
|
confirmContent="resources.rooms.action.erase.content"
|
||||||
@ -95,7 +90,7 @@ const RoomShowActions = ({ data, resource }) => {
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const RoomShow = props => {
|
export const RoomShow = () => {
|
||||||
const translate = useTranslate();
|
const translate = useTranslate();
|
||||||
return (
|
return (
|
||||||
<Show actions={<RoomShowActions />} title={<RoomTitle />}>
|
<Show actions={<RoomShowActions />} title={<RoomTitle />}>
|
||||||
|
Loading…
Reference in New Issue
Block a user