From 2842f661db8aeb0154dd362a6b61b3edb808bef9 Mon Sep 17 00:00:00 2001 From: Hailey Date: Sat, 7 Sep 2024 11:54:39 -0700 Subject: Add intent for verifying email (#5120) --- src/components/intents/VerifyEmailIntentDialog.tsx | 140 +++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 src/components/intents/VerifyEmailIntentDialog.tsx (limited to 'src/components/intents/VerifyEmailIntentDialog.tsx') diff --git a/src/components/intents/VerifyEmailIntentDialog.tsx b/src/components/intents/VerifyEmailIntentDialog.tsx new file mode 100644 index 000000000..4dca8bd90 --- /dev/null +++ b/src/components/intents/VerifyEmailIntentDialog.tsx @@ -0,0 +1,140 @@ +import React from 'react' +import {View} from 'react-native' +import {msg, Trans} from '@lingui/macro' +import {useLingui} from '@lingui/react' + +import {useAgent, useSession} from 'state/session' +import {atoms as a} from '#/alf' +import {Button, ButtonText} from '#/components/Button' +import * as Dialog from '#/components/Dialog' +import {DialogControlProps} from '#/components/Dialog' +import {useIntentDialogs} from '#/components/intents/IntentDialogs' +import {Loader} from '#/components/Loader' +import {Text} from '#/components/Typography' + +export function VerifyEmailIntentDialog() { + const {verifyEmailDialogControl: control} = useIntentDialogs() + + return ( + + + + + ) +} + +function Inner({control}: {control: DialogControlProps}) { + const {_} = useLingui() + const {verifyEmailState: state} = useIntentDialogs() + const [status, setStatus] = React.useState< + 'loading' | 'success' | 'failure' | 'resent' + >('loading') + const [sending, setSending] = React.useState(false) + const agent = useAgent() + const {currentAccount} = useSession() + + React.useEffect(() => { + ;(async () => { + if (!state?.code) { + return + } + try { + await agent.com.atproto.server.confirmEmail({ + email: (currentAccount?.email || '').trim(), + token: state.code.trim(), + }) + setStatus('success') + } catch (e) { + setStatus('failure') + } + })() + }, [agent.com.atproto.server, currentAccount?.email, state?.code]) + + const onPressResendEmail = async () => { + setSending(true) + await agent.com.atproto.server.requestEmailConfirmation() + setSending(false) + setStatus('resent') + } + + return ( + + + + {status === 'loading' ? ( + + + + ) : status === 'success' ? ( + <> + + Email Verified + + + + Thanks, you have successfully verified your email address. + + + + ) : status === 'failure' ? ( + <> + + Invalid Verification Code + + + + The verification code you have provided is invalid. Please make + sure that you have used the correct verification link or request + a new one. + + + + ) : ( + <> + + Email Resent + + + + We have sent another verification email to{' '} + + {currentAccount?.email} + + . + + + + )} + {status !== 'loading' ? ( + + + {status === 'failure' ? ( + + ) : null} + + ) : null} + + + ) +} -- cgit 1.4.1