| 1 | import { useDispatch } from "react-redux"; |
| 2 | import styled from "styled-components"; |
| 3 | import { Button, SecondaryButton } from ".."; |
| 4 | import { setDialogMessage, setShowDialog } from "../../redux/slices/uiSlice"; |
| 5 | |
| 6 | interface ConfirmationDialogProps { |
| 7 | onConfirm: () => void; |
| 8 | onCancel?: () => void; |
| 9 | text: string; |
| 10 | title?: string; |
| 11 | hideCancelButton?: boolean; |
| 12 | confirmText?: string; |
| 13 | } |
| 14 | |
| 15 | function ConfirmationDialog(props: ConfirmationDialogProps) { |
| 16 | const dispatch = useDispatch(); |
| 17 | |
| 18 | return ( |
| 19 | <div className="p-4 pt-0"> |
| 20 | <h1 className="mb-1 text-center text-xl"> |
| 21 | {props.title ?? "Confirmation"} |
| 22 | </h1> |
| 23 | <p className="text-center text-base" style={{ whiteSpace: "pre-wrap" }}> |
| 24 | {props.text} |
| 25 | </p> |
| 26 | |
| 27 | <div className="w/1/2 flex justify-end gap-2"> |
| 28 | {!!props.hideCancelButton || ( |
| 29 | <SecondaryButton |
| 30 | className="text-lightgray" |
| 31 | onClick={() => { |
| 32 | dispatch(setShowDialog(false)); |
| 33 | dispatch(setDialogMessage(undefined)); |
| 34 | props.onCancel?.(); |
| 35 | }} |
| 36 | > |
| 37 | Cancel |
| 38 | </SecondaryButton> |
| 39 | )} |
| 40 | <Button |
| 41 | onClick={() => { |
| 42 | props.onConfirm(); |
| 43 | dispatch(setShowDialog(false)); |
| 44 | dispatch(setDialogMessage(undefined)); |
| 45 | }} |
| 46 | > |
| 47 | {props.confirmText ?? "Confirm"} |
| 48 | </Button> |
| 49 | </div> |
| 50 | </div> |
| 51 | ); |
| 52 | } |
| 53 | |
| 54 | export default ConfirmationDialog; |