Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customising the message that appears after the delete operation in DeleteWithConfirmButton #9837

Open
ethembynkr opened this issue May 9, 2024 · 4 comments · May be fixed by #9868
Open

Comments

@ethembynkr
Copy link

ethembynkr commented May 9, 2024

Is your feature request related to a problem? Please describe.
I want to customise the notification message that appears to the DeleteWithConfirmButton component after the delete operation is successful. (Only for some pages.) I can give the message using notify in the onSuccess method of the MutationOptions prop, but this time confirm is not turned off.

Describe the solution you'd like
Is it possible to add a new prop to customise the notify message that appears after the delete operation is successful in the DeleteWithConfirmButton component?

{ onSuccessMessage =  'ra.notification.deleted' } = props;

onSuccess: () => {
  setOpen(false);
  notify(onSuccessMessage, {
    type: 'info',
    messageArgs: { smart_count: 1 },
    undoable: mutationMode === 'undoable',
  });
  unselect([record.id]);
  redirect(redirectTo, resource);
}

Or you can get props named handleSuccess, handleError and call them in the default onSuccess and onError methods in useDeleteWithConfirmController.

{ handleSuccess, handleError } = props;

onSuccess: () => {
  ...
 if (typeof handleSuccess === 'function') {
  handleSuccess();
 }
},
onError: () => {
  ...
 if (typeof handleError === 'function') {
  handleError();
 }
}

Describe alternatives you've considered
I can rewrite DeleteWithConfirmButton and useDeleteWithConfirmController components but it will be very costly for me.

Additional context
image

@fzaninotto
Copy link
Member

Hi, and thanks for your suggestion.

You can already override the success side effects with the mutationOptions.onSuccess prop, as in the screenshot you pasted in the "Additional context" section. This is also the way to customize the notification text in the Edit view (see https://marmelab.com/react-admin/Create.html#changing-the-notification-message). If this option doesn't work, please elaborate on the reproduction.

We won't offer an additional prop to do something you can already do with mutationOptions.

@ethembynkr
Copy link
Author

ethembynkr commented May 10, 2024

Hi, thank you for your answer.

I can customise the notification text with mutationOptions in DeleteWithConfirmButton component, but in this case the confirm dialog does not close.

I made a demo that shows this case. Please select and delete a record on the post page or delete a record on the edit page. You will see that the Confirm dialogue does not close.

You can access the demo here

image

@fzaninotto
Copy link
Member

Understood, thanks for the reproduction.

You're right: there is no easy way to do what you ask without rewriting significant parts of the controller. So we need to expose an option to let users override the message (something like successNotification) in useDeleteWithConfirmController and the associated buttons.

I'm marking this as an enhancement. We'll welcome a PR implementing this feature.

@ethembynkr
Copy link
Author

@fzaninotto I opened a PR for this feature. Can you review it?

#9868

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants