modal-content.tsx 2.6 KB

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