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

Support promises for callbacks like onDelete #117

Open
CarlosNZ opened this issue Sep 4, 2024 Discussed in #116 · 5 comments
Open

Support promises for callbacks like onDelete #117

CarlosNZ opened this issue Sep 4, 2024 Discussed in #116 · 5 comments
Assignees
Labels
should do user request Requested by user

Comments

@CarlosNZ
Copy link
Owner

CarlosNZ commented Sep 4, 2024

Discussed in #116

Originally posted by yaswanthmaddula-sureify September 5, 2024
I would like to have confirmation modal, if user tries to delete certain important keys in the json. As the onDelete callback is synchronous as of now, the only way for me to achieve this is using window.confirm(). It would be useful if there is a way like promises to support such usecases.

@CarlosNZ CarlosNZ added user request Requested by user should do labels Sep 4, 2024
@CarlosNZ
Copy link
Owner Author

CarlosNZ commented Sep 4, 2024

Yes, this is a good point. A confirmation modal is a pretty typical use case, so would be good to handle this.

I think the best way would be to make the actual internal onDelete method available from the update function, so you can call it yourself once the confirmation is approved. I'll have a play around and see what I can do.

Thanks for the suggestion.

@CarlosNZ CarlosNZ self-assigned this Sep 4, 2024
@CarlosNZ
Copy link
Owner Author

CarlosNZ commented Sep 4, 2024

@yaswanthmaddula-sureify the Update functions do currently support async methods, so if you can get your confirmation to be await-able, then it will work. For example:

onDelete={
  async () => {
    const response = await getUserConfirmation("Are you sure?")
    if (respose !== "CONFIRM") return false
  }
}

I know that doesn't work that well with most React libraries which don't return a Promise from a confirmation dialog, however here is a way of doing it that should work, though I haven't tried it myself: https://daveteu.medium.com/react-custom-confirmation-box-458cceba3f7b

@yaswanthmaddula-sureify
Copy link

yaswanthmaddula-sureify commented Sep 5, 2024

Okay, I think that will work then. Thanks.

@CarlosNZ
Copy link
Owner Author

CarlosNZ commented Sep 5, 2024

Let me know if you get it working. If it's too fiddly to implement, I might still look at improving this.

@CarlosNZ
Copy link
Owner Author

CarlosNZ commented Nov 2, 2024

@yaswanthmaddula-sureify -- here's another library that allows you to await a confirmation: https://github.com/palerdot/use-async-confirm

Looks quite useful, thought haven't personally tried it yet.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
should do user request Requested by user
Projects
None yet
Development

No branches or pull requests

2 participants