Untitled

mail@pastecode.io avatar
unknown
jsx
5 days ago
690 B
3
Indexable
Never
const DeleteUser = () => {
  const {openConfirmationModal, closeConfirmationModal} = useConfirmationModal();
  const [isUserDeleting, setIsUserDeleting] = useState(false);
  
  const deleteUser = async () => {
    setIsUserDeleting(true);
    try {
      await API.deleteUser();
      closeConfirmationModal();
    } catch (e) {
  
    }
    setIsUserDeleting(false);
  }
  
  const onDeleteClick = () => {
    openConfirmationModal({
      title: 'Delete user',
      message: 'Are you sure want to delete this user?',
      actionButton: <Button loading={isUserDeleting} onClick={deleteUser}>Delete</Button> 
    });
  }
  
  return <Button onClick={onDeleteClick}>Delete user</Button>;
}