Skip to content

Commit

Permalink
Fix bulk accept and delete in demo
Browse files Browse the repository at this point in the history
  • Loading branch information
fzaninotto committed Jul 31, 2019
1 parent 73b4fa1 commit 0d8a864
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 37 deletions.
48 changes: 29 additions & 19 deletions examples/demo/src/reviews/BulkAcceptButton.js
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@
import React from 'react';
import PropTypes from 'prop-types';
import ThumbUp from '@material-ui/icons/ThumbUp';
import { Button, useMutation, UPDATE_MANY } from 'react-admin';

const options = {
undoable: true,
onSuccess: {
notification: {
body: 'resources.reviews.notification.approved_success',
level: 'info',
},
redirectTo: '/reviews',
},
onFailure: {
notification: {
body: 'resources.reviews.notification.approved_error',
level: 'warning',
},
},
};
import {
Button,
useMutation,
useNotify,
useRedirect,
useUnselectAll,
UPDATE_MANY,
} from 'react-admin';

const BulkAcceptButton = ({ selectedIds }) => {
const notify = useNotify();
const redirect = useRedirect();
const unselectAll = useUnselectAll('reviews');
const [approve, { loading }] = useMutation(
{
type: UPDATE_MANY,
resource: 'reviews',
payload: { ids: selectedIds, data: { status: 'accepted' } },
},
options
{
undoable: true,
onSuccess: () => {
notify(
'resources.reviews.notification.approved_success',
'info',
{},
true
);
redirect('/reviews');
unselectAll();
},
onFailure: () =>
notify(
'resources.reviews.notification.approved_error',
'warning'
),
}
);

return (
Expand Down
47 changes: 29 additions & 18 deletions examples/demo/src/reviews/BulkRejectButton.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,43 @@
import React from 'react';
import PropTypes from 'prop-types';
import ThumbDown from '@material-ui/icons/ThumbDown';
import { Button, useMutation, UPDATE_MANY } from 'react-admin';
import {
Button,
useMutation,
useNotify,
useRedirect,
useUnselectAll,
UPDATE_MANY,
} from 'react-admin';

const options = {
undoable: true,
onSuccess: {
notification: {
body: 'resources.reviews.notification.approved_success',
level: 'info',
},
redirectTo: '/reviews',
},
onFailure: {
notification: {
body: 'resources.reviews.notification.approved_error',
level: 'warning',
},
},
};
const BulkRejectButton = ({ selectedIds }) => {
const notify = useNotify();
const redirect = useRedirect();
const unselectAll = useUnselectAll('reviews');
const [reject, { loading }] = useMutation(
{
type: UPDATE_MANY,
resource: 'reviews',
payload: { ids: selectedIds, data: { status: 'rejected' } },
},
options
{
undoable: true,
onSuccess: () => {
notify(
'resources.reviews.notification.approved_success',
'info',
{},
true
);
redirect('/reviews');
unselectAll();
},
onFailure: () =>
notify(
'resources.reviews.notification.approved_error',
'warning'
),
}
);

return (
Expand Down

0 comments on commit 0d8a864

Please sign in to comment.