ConfirmModal.tsx 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. import type { FC } from 'react';
  2. import React from 'react';
  3. import { useTranslation } from 'next-i18next';
  4. import {
  5. Modal, ModalHeader, ModalBody, ModalFooter,
  6. } from 'reactstrap';
  7. type ConfirmModalProps = {
  8. isModalOpen: boolean
  9. warningMessage: string
  10. supplymentaryMessage: string | null
  11. confirmButtonTitle: string
  12. onConfirm?: () => Promise<void>
  13. onCancel?: () => void
  14. };
  15. export const ConfirmModal: FC<ConfirmModalProps> = (props: ConfirmModalProps) => {
  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. {
  36. props.supplymentaryMessage != null && (
  37. <>
  38. <br />
  39. <br />
  40. <span className="text-warning">
  41. <>
  42. <span className="material-symbols-outlined">error</span>
  43. {props.supplymentaryMessage}
  44. </>
  45. </span>
  46. </>
  47. )
  48. }
  49. </ModalBody>
  50. <ModalFooter>
  51. <button
  52. type="button"
  53. className="btn btn-outline-secondary"
  54. onClick={onCancel}
  55. >
  56. {t('Cancel')}
  57. </button>
  58. <button
  59. type="button"
  60. className="btn btn-outline-primary ms-3"
  61. onClick={onConfirm}
  62. >
  63. {props.confirmButtonTitle ?? t('Confirm')}
  64. </button>
  65. </ModalFooter>
  66. </Modal>
  67. );
  68. };