-
-
Notifications
You must be signed in to change notification settings - Fork 208
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2879 from metabrainz/dont-delete-my-stuff-ffs
Show a confirmation modal before deletion
- Loading branch information
Showing
3 changed files
with
145 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import NiceModal, { useModal } from "@ebay/nice-modal-react"; | ||
import * as React from "react"; | ||
|
||
type ConfirmationModalProps = { | ||
body?: JSX.Element; | ||
}; | ||
|
||
export default NiceModal.create((props: ConfirmationModalProps) => { | ||
const modal = useModal(); | ||
const closeModal = React.useCallback(() => { | ||
modal.hide(); | ||
document?.body?.classList?.remove("modal-open"); | ||
setTimeout(modal.remove, 200); | ||
}, [modal]); | ||
|
||
const { body } = props; | ||
|
||
const onCancel = () => { | ||
modal.reject(); | ||
closeModal(); | ||
}; | ||
const onConfirm = () => { | ||
modal.resolve(); | ||
closeModal(); | ||
}; | ||
|
||
return ( | ||
<div | ||
id="ConfirmationModal" | ||
className={`modal fade ${modal.visible ? "in" : ""}`} | ||
tabIndex={-1} | ||
role="dialog" | ||
aria-labelledby="confirmationModalLabel" | ||
data-backdrop="static" | ||
> | ||
<div className="modal-dialog modal-sm" role="document"> | ||
<div className="modal-content"> | ||
<div className="modal-header"> | ||
<button | ||
type="button" | ||
className="close" | ||
data-dismiss="modal" | ||
aria-label="Close" | ||
> | ||
<span aria-hidden="true">×</span> | ||
</button> | ||
<h4 className="modal-title" id="confirmationModalLabel"> | ||
Confirm this action | ||
</h4> | ||
</div> | ||
|
||
<div className="modal-body"> | ||
{body || <>Do you confirm this action?</>} | ||
</div> | ||
|
||
<div className="modal-footer"> | ||
<button | ||
type="button" | ||
className="btn btn-default" | ||
data-dismiss="modal" | ||
onClick={onCancel} | ||
> | ||
Cancel | ||
</button> | ||
<button | ||
type="button" | ||
className="btn btn-danger" | ||
onClick={onConfirm} | ||
data-dismiss="modal" | ||
> | ||
Confirm | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters