Fallback change email dialog
This commit is contained in:
@@ -14,6 +14,7 @@ import * as TextField from '#/components/forms/TextField'
|
|||||||
import {InlineLinkText} from '#/components/Link'
|
import {InlineLinkText} from '#/components/Link'
|
||||||
import {Loader} from '#/components/Loader'
|
import {Loader} from '#/components/Loader'
|
||||||
import {Text} from '#/components/Typography'
|
import {Text} from '#/components/Typography'
|
||||||
|
import {ChangeEmailDialog} from './ChangeEmailDialog'
|
||||||
|
|
||||||
export function VerifyEmailDialog({
|
export function VerifyEmailDialog({
|
||||||
control,
|
control,
|
||||||
@@ -26,36 +27,50 @@ export function VerifyEmailDialog({
|
|||||||
onCloseWithoutVerifying?: () => void
|
onCloseWithoutVerifying?: () => void
|
||||||
onCloseAfterVerifying?: () => void
|
onCloseAfterVerifying?: () => void
|
||||||
reasonText?: string
|
reasonText?: string
|
||||||
changeEmailControl: Dialog.DialogControlProps
|
/**
|
||||||
|
* if a changeEmailControl for a ChangeEmailDialog is not provided,
|
||||||
|
* this component will create one for you. Using this prop
|
||||||
|
* helps reduce duplication, since these dialogs are often used together.
|
||||||
|
*/
|
||||||
|
changeEmailControl?: Dialog.DialogControlProps
|
||||||
}) {
|
}) {
|
||||||
const agent = useAgent()
|
const agent = useAgent()
|
||||||
|
const fallbackChangeEmailControl = Dialog.useDialogControl()
|
||||||
|
|
||||||
const [didVerify, setDidVerify] = React.useState(false)
|
const [didVerify, setDidVerify] = React.useState(false)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog.Outer
|
<>
|
||||||
control={control}
|
<Dialog.Outer
|
||||||
onClose={async () => {
|
control={control}
|
||||||
if (!didVerify) {
|
onClose={async () => {
|
||||||
onCloseWithoutVerifying?.()
|
if (!didVerify) {
|
||||||
return
|
onCloseWithoutVerifying?.()
|
||||||
}
|
return
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await agent.resumeSession(agent.session!)
|
await agent.resumeSession(agent.session!)
|
||||||
onCloseAfterVerifying?.()
|
onCloseAfterVerifying?.()
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
logger.error(String(e))
|
logger.error(String(e))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
}}>
|
}}>
|
||||||
<Dialog.Handle />
|
<Dialog.Handle />
|
||||||
<Inner
|
<Inner
|
||||||
setDidVerify={setDidVerify}
|
setDidVerify={setDidVerify}
|
||||||
reasonText={reasonText}
|
reasonText={reasonText}
|
||||||
changeEmailControl={changeEmailControl}
|
changeEmailControl={changeEmailControl ?? fallbackChangeEmailControl}
|
||||||
/>
|
/>
|
||||||
</Dialog.Outer>
|
</Dialog.Outer>
|
||||||
|
{!changeEmailControl && (
|
||||||
|
<ChangeEmailDialog
|
||||||
|
control={fallbackChangeEmailControl}
|
||||||
|
verifyEmailControl={control}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user