2022-04-08 07:00:31 -04:00
|
|
|
import { useState, Dispatch, SetStateAction } from 'react'
|
|
|
|
import { useTranslation, Trans } from 'react-i18next'
|
2022-04-08 07:01:21 -04:00
|
|
|
import getMeta from '../../../../utils/meta'
|
|
|
|
import LeaveModalForm, { LeaveModalFormProps } from './modal-form'
|
2024-05-15 10:31:00 -04:00
|
|
|
import OLButton from '@/features/ui/components/ol/ol-button'
|
2024-05-14 11:53:25 -04:00
|
|
|
import {
|
|
|
|
OLModalBody,
|
|
|
|
OLModalFooter,
|
|
|
|
OLModalHeader,
|
|
|
|
OLModalTitle,
|
2024-05-15 10:31:00 -04:00
|
|
|
} from '@/features/ui/components/ol/ol-modal'
|
2022-04-08 07:00:31 -04:00
|
|
|
|
|
|
|
type LeaveModalContentProps = {
|
|
|
|
handleHide: () => void
|
|
|
|
inFlight: boolean
|
|
|
|
setInFlight: Dispatch<SetStateAction<boolean>>
|
|
|
|
}
|
|
|
|
|
2022-04-08 07:01:21 -04:00
|
|
|
function LeaveModalContentBlock({
|
|
|
|
setInFlight,
|
|
|
|
isFormValid,
|
|
|
|
setIsFormValid,
|
|
|
|
}: LeaveModalFormProps) {
|
|
|
|
const { t } = useTranslation()
|
2024-06-18 06:01:37 -04:00
|
|
|
const { isOverleaf } = getMeta('ol-ExposedSettings')
|
|
|
|
const hasPassword = getMeta('ol-hasPassword')
|
2022-04-08 07:01:21 -04:00
|
|
|
|
2022-04-22 09:49:26 -04:00
|
|
|
if (isOverleaf && !hasPassword) {
|
2022-04-08 07:01:21 -04:00
|
|
|
return (
|
|
|
|
<p>
|
|
|
|
<b>
|
|
|
|
<a href="/user/password/reset">{t('delete_acct_no_existing_pw')}</a>
|
|
|
|
</b>
|
|
|
|
</p>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return (
|
|
|
|
<LeaveModalForm
|
|
|
|
setInFlight={setInFlight}
|
|
|
|
isFormValid={isFormValid}
|
|
|
|
setIsFormValid={setIsFormValid}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-04-08 07:00:31 -04:00
|
|
|
function LeaveModalContent({
|
|
|
|
handleHide,
|
|
|
|
inFlight,
|
|
|
|
setInFlight,
|
|
|
|
}: LeaveModalContentProps) {
|
|
|
|
const { t } = useTranslation()
|
|
|
|
const [isFormValid, setIsFormValid] = useState(false)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
2024-05-14 11:53:25 -04:00
|
|
|
<OLModalHeader closeButton>
|
|
|
|
<OLModalTitle>{t('delete_account')}</OLModalTitle>
|
|
|
|
</OLModalHeader>
|
2022-04-08 07:00:31 -04:00
|
|
|
|
2024-05-14 11:53:25 -04:00
|
|
|
<OLModalBody>
|
2022-04-08 07:00:31 -04:00
|
|
|
<p>
|
|
|
|
<Trans
|
|
|
|
i18nKey="delete_account_warning_message_3"
|
2023-10-30 06:29:56 -04:00
|
|
|
components={{ strong: <strong /> }}
|
2022-04-08 07:00:31 -04:00
|
|
|
/>
|
|
|
|
</p>
|
2022-04-08 07:01:21 -04:00
|
|
|
<LeaveModalContentBlock
|
2022-04-08 07:00:31 -04:00
|
|
|
setInFlight={setInFlight}
|
|
|
|
isFormValid={isFormValid}
|
|
|
|
setIsFormValid={setIsFormValid}
|
|
|
|
/>
|
2024-05-14 11:53:25 -04:00
|
|
|
</OLModalBody>
|
2022-04-08 07:00:31 -04:00
|
|
|
|
2024-05-14 11:53:25 -04:00
|
|
|
<OLModalFooter>
|
2024-06-06 11:37:47 -04:00
|
|
|
<OLButton disabled={inFlight} onClick={handleHide} variant="secondary">
|
2022-04-08 07:00:31 -04:00
|
|
|
{t('cancel')}
|
2024-05-15 10:31:00 -04:00
|
|
|
</OLButton>
|
2022-04-08 07:00:31 -04:00
|
|
|
|
2024-05-15 10:31:00 -04:00
|
|
|
<OLButton
|
2022-04-08 07:00:31 -04:00
|
|
|
form="leave-form"
|
|
|
|
type="submit"
|
2024-04-23 10:12:25 -04:00
|
|
|
variant="danger"
|
2022-04-08 07:00:31 -04:00
|
|
|
disabled={inFlight || !isFormValid}
|
|
|
|
>
|
|
|
|
{inFlight ? <>{t('deleting')}…</> : t('delete')}
|
2024-05-15 10:31:00 -04:00
|
|
|
</OLButton>
|
2024-05-14 11:53:25 -04:00
|
|
|
</OLModalFooter>
|
2022-04-08 07:00:31 -04:00
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default LeaveModalContent
|