react-trello icon indicating copy to clipboard operation
react-trello copied to clipboard

Question: How to use onBeforeCardDelete?

Open spchaplin opened this issue 4 years ago • 2 comments

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!

spchaplin avatar Jan 16 '21 01:01 spchaplin

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)}
/>

raframil avatar Oct 21 '22 00:10 raframil

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

lbtemp avatar Feb 18 '24 06:02 lbtemp