2022-04-08 07:00:31 -04:00
|
|
|
import { useState, Dispatch, SetStateAction } from 'react'
|
2024-04-23 10:12:25 -04:00
|
|
|
import { Modal } from 'react-bootstrap'
|
2022-04-08 07:00:31 -04:00
|
|
|
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'
|
2022-04-22 09:49:26 -04:00
|
|
|
import { ExposedSettings } from '../../../../../../types/exposed-settings'
|
2024-04-23 10:12:25 -04:00
|
|
|
import ButtonWrapper from '@/features/ui/components/bootstrap-5/wrappers/button-wrapper'
|
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()
|
2022-04-22 09:49:26 -04:00
|
|
|
const { isOverleaf } = getMeta('ol-ExposedSettings') as ExposedSettings
|
2022-04-08 07:01:21 -04:00
|
|
|
const hasPassword = getMeta('ol-hasPassword') as boolean
|
|
|
|
|
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 (
|
|
|
|
<>
|
|
|
|
<Modal.Header closeButton>
|
|
|
|
<Modal.Title>{t('delete_account')}</Modal.Title>
|
|
|
|
</Modal.Header>
|
|
|
|
|
|
|
|
<Modal.Body>
|
|
|
|
<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}
|
|
|
|
/>
|
|
|
|
</Modal.Body>
|
|
|
|
|
|
|
|
<Modal.Footer>
|
2024-04-23 10:12:25 -04:00
|
|
|
<ButtonWrapper
|
2022-11-17 12:53:55 -05:00
|
|
|
disabled={inFlight}
|
|
|
|
onClick={handleHide}
|
2024-04-23 10:12:25 -04:00
|
|
|
variant="secondary"
|
|
|
|
bs3Props={{ bsStyle: null, className: 'btn-secondary' }}
|
2022-11-17 12:53:55 -05:00
|
|
|
>
|
2022-04-08 07:00:31 -04:00
|
|
|
{t('cancel')}
|
2024-04-23 10:12:25 -04:00
|
|
|
</ButtonWrapper>
|
2022-04-08 07:00:31 -04:00
|
|
|
|
2024-04-23 10:12:25 -04:00
|
|
|
<ButtonWrapper
|
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-04-23 10:12:25 -04:00
|
|
|
</ButtonWrapper>
|
2022-04-08 07:00:31 -04:00
|
|
|
</Modal.Footer>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default LeaveModalContent
|