ConfirmModal.tsx 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import React, { FC } from 'react';
  2. import {
  3. Modal, ModalHeader, ModalBody, ModalFooter,
  4. } from 'reactstrap';
  5. import { useTranslation } from 'next-i18next';
  6. import { TFunctionResult } from 'i18next';
  7. type ConfirmModalProps = {
  8. isModalOpen: boolean
  9. warningMessage: TFunctionResult
  10. supplymentaryMessage: TFunctionResult | null
  11. confirmButtonTitle: TFunctionResult
  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} className="">
  29. <ModalHeader tag="h4" toggle={onCancel} className="bg-danger">
  30. <i className="icon-fw icon-question" />
  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. <i className="icon-exclamation icon-fw"></i>
  42. {props.supplymentaryMessage}
  43. </span>
  44. </>
  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 ml-3"
  59. onClick={onConfirm}
  60. >
  61. {props.confirmButtonTitle ?? t('Confirm')}
  62. </button>
  63. </ModalFooter>
  64. </Modal>
  65. );
  66. };