modal-content.tsx 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import { useState, Dispatch, SetStateAction } from 'react'
  2. import { useTranslation, Trans } from 'react-i18next'
  3. import getMeta from '../../../../utils/meta'
  4. import LeaveModalForm, { LeaveModalFormProps } from './modal-form'
  5. import OLButton from '@/features/ui/components/ol/ol-button'
  6. import {
  7. OLModalBody,
  8. OLModalFooter,
  9. OLModalHeader,
  10. OLModalTitle,
  11. } from '@/features/ui/components/ol/ol-modal'
  12. const WRITEFULL_SUPPORT_EMAIL = 'support@writefull.com'
  13. type LeaveModalContentProps = {
  14. handleHide: () => void
  15. inFlight: boolean
  16. setInFlight: Dispatch<SetStateAction<boolean>>
  17. }
  18. function LeaveModalContentBlock({
  19. setInFlight,
  20. isFormValid,
  21. setIsFormValid,
  22. }: LeaveModalFormProps) {
  23. const { t } = useTranslation()
  24. const { isOverleaf } = getMeta('ol-ExposedSettings')
  25. const hasPassword = getMeta('ol-hasPassword')
  26. if (isOverleaf && !hasPassword) {
  27. return (
  28. <p>
  29. <b>
  30. <a href="/user/password/reset">{t('delete_acct_no_existing_pw')}</a>
  31. </b>
  32. </p>
  33. )
  34. }
  35. return (
  36. <>
  37. <LeaveModalForm
  38. setInFlight={setInFlight}
  39. isFormValid={isFormValid}
  40. setIsFormValid={setIsFormValid}
  41. />
  42. <p>
  43. <Trans
  44. i18nKey="to_delete_your_writefull_account"
  45. values={{ email: WRITEFULL_SUPPORT_EMAIL }}
  46. shouldUnescape
  47. tOptions={{ interpolation: { escapeValue: true } }}
  48. components={{
  49. // eslint-disable-next-line jsx-a11y/anchor-has-content
  50. a: <a href={`mailto:${WRITEFULL_SUPPORT_EMAIL}`} />,
  51. }}
  52. />
  53. </p>
  54. </>
  55. )
  56. }
  57. function LeaveModalContent({
  58. handleHide,
  59. inFlight,
  60. setInFlight,
  61. }: LeaveModalContentProps) {
  62. const { t } = useTranslation()
  63. const [isFormValid, setIsFormValid] = useState(false)
  64. return (
  65. <>
  66. <OLModalHeader closeButton>
  67. <OLModalTitle>{t('delete_account')}</OLModalTitle>
  68. </OLModalHeader>
  69. <OLModalBody>
  70. <p>
  71. <Trans
  72. i18nKey="delete_account_warning_message_3"
  73. components={{ strong: <strong /> }}
  74. />
  75. </p>
  76. <LeaveModalContentBlock
  77. setInFlight={setInFlight}
  78. isFormValid={isFormValid}
  79. setIsFormValid={setIsFormValid}
  80. />
  81. </OLModalBody>
  82. <OLModalFooter>
  83. <OLButton disabled={inFlight} onClick={handleHide} variant="secondary">
  84. {t('cancel')}
  85. </OLButton>
  86. <OLButton
  87. form="leave-form"
  88. type="submit"
  89. variant="danger"
  90. disabled={inFlight || !isFormValid}
  91. >
  92. {inFlight ? <>{t('deleting')}…</> : t('delete')}
  93. </OLButton>
  94. </OLModalFooter>
  95. </>
  96. )
  97. }
  98. export default LeaveModalContent