Skip to content

Commit

Permalink
Allow to extend useEditController
Browse files Browse the repository at this point in the history
`useCreateController` accepts a onSuccess and a onFailure props, but `useEditController` don't
So, I made this PR to have the same behavior for both of them
  • Loading branch information
Kmaschta authored Nov 28, 2019
1 parent 7996e7d commit 803223e
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions packages/ra-core/src/controller/useEditController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ const useEditController = (props: EditProps): EditControllerProps => {
);

const save = useCallback(
(data: Partial<Record>, redirectTo = 'list') =>
(data: Partial<Record>, redirectTo = 'list', { onSuccess, onFailure } = {}) =>
update(
{ payload: { data } },
{
action: CRUD_UPDATE,
onSuccess: () => {
onSuccess: onSuccess ? onSuccess : () => {
notify(
successMessage || 'ra.notification.updated',
'info',
Expand All @@ -108,7 +108,7 @@ const useEditController = (props: EditProps): EditControllerProps => {
);
redirect(redirectTo, basePath, data.id, data);
},
onFailure: error =>
onFailure: onFailure ? onFailure : error =>
notify(
typeof error === 'string'
? error
Expand Down

0 comments on commit 803223e

Please sign in to comment.