rcdexta / react-trello

Pluggable components to add a kanban board to your application
https://rcdexta.com/react-trello/
MIT License
2.19k stars 481 forks source link

Question: How to use onBeforeCardDelete? #426

Open spchaplin opened 3 years ago

spchaplin commented 3 years ago

Would someone please provide an example of how to use onBeforeCardDelete?

I'm not finding that it works that same as other event handlers like onCardAdd. The comment by dapi when the feature request was added seems to indicate that a custom card component may be required to use onBeforeCardDelete. Is this correct?

Many thanks!

raframil commented 1 year ago

This is probably too late but I will write if anyone has the same problem. Also should be a good idea to document this at Storybook.

You can do the following:

  const handleDelete = (cardId) => {
    console.log('here you can do whatever a request for example')
  };

  const beforeDelete = (handleDelete) => {
    const confirmation = confirm('You sure?');
    if (confirmation) {
      handleDelete();
    }
  };

<Board 
      onBeforeCardDelete={(handleDelete) => {
        return beforeDelete(handleDelete);
      }}
      onCardDelete={(cardId) => handleDelete(cardId)}
/>
lbtemp commented 7 months ago

Is there any chance we could get access to the "cardId" argument in beforeDelete ? This way we can run the request in the beforeDelete function, if the request is successful then we would be able to call handleDelete(), otherwise if an error occurs the card wouldn't be removed from the board