ConfirmModal.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. import type { FC } from 'react';
  2. import React from 'react';
  3. import { useTranslation } from 'next-i18next';
  4. import { Modal, ModalBody, ModalFooter, ModalHeader } from 'reactstrap';
  5. type ConfirmModalProps = {
  6. isModalOpen: boolean;
  7. warningMessage: string;
  8. supplymentaryMessage: string | null;
  9. confirmButtonTitle: string;
  10. onConfirm?: () => Promise<void>;
  11. onCancel?: () => void;
  12. };
  13. export const ConfirmModal: FC<ConfirmModalProps> = (
  14. props: ConfirmModalProps,
  15. ) => {
  16. const { t } = useTranslation();
  17. const onCancel = () => {
  18. if (props.onCancel != null) {
  19. props.onCancel();
  20. }
  21. };
  22. const onConfirm = () => {
  23. if (props.onConfirm != null) {
  24. props.onConfirm();
  25. }
  26. };
  27. return (
  28. <Modal isOpen={props.isModalOpen} toggle={onCancel}>
  29. <ModalHeader tag="h4" toggle={onCancel} className="text-danger">
  30. <span className="material-symbols-outlined me-1">warning</span>
  31. {t('Warning')}
  32. </ModalHeader>
  33. <ModalBody>
  34. {props.warningMessage}
  35. {props.supplymentaryMessage != null && (
  36. <>
  37. <br />
  38. <br />
  39. <span className="text-warning">
  40. <>
  41. <span className="material-symbols-outlined">error</span>
  42. {props.supplymentaryMessage}
  43. </>
  44. </span>
  45. </>
  46. )}
  47. </ModalBody>
  48. <ModalFooter>
  49. <button
  50. type="button"
  51. className="btn btn-outline-secondary"
  52. onClick={onCancel}
  53. >
  54. {t('Cancel')}
  55. </button>
  56. <button
  57. type="button"
  58. className="btn btn-outline-primary ms-3"
  59. onClick={onConfirm}
  60. >
  61. {props.confirmButtonTitle ?? t('Confirm')}
  62. </button>
  63. </ModalFooter>
  64. </Modal>
  65. );
  66. };