From 1e7eaf0ee6af212a7974f3b1eece0815b7c7494d Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Tue, 26 Nov 2024 12:02:41 -0600 Subject: [PATCH] Verify email handling --- .../dialogs/BlueskyPlusCore/index.tsx | 77 +++++++++++++++++-- 1 file changed, 72 insertions(+), 5 deletions(-) diff --git a/src/components/dialogs/BlueskyPlusCore/index.tsx b/src/components/dialogs/BlueskyPlusCore/index.tsx index 2517313979..eb6608798b 100644 --- a/src/components/dialogs/BlueskyPlusCore/index.tsx +++ b/src/components/dialogs/BlueskyPlusCore/index.tsx @@ -19,8 +19,11 @@ import {atoms as a, tokens, useBreakpoints, useTheme} from '#/alf' import {Admonition} from '#/components/Admonition' import {Button, ButtonIcon, ButtonText} from '#/components/Button' import * as Dialog from '#/components/Dialog' +import {Divider} from '#/components/Divider' +import * as TextField from '#/components/forms/TextField' import * as Toggle from '#/components/forms/Toggle' import {GradientFill} from '#/components/GradientFill' +import {At_Stroke2_Corner0_Rounded as At} from '#/components/icons/At' import {Full as BlueskyPlusLogo} from '#/components/icons/BlueskyPlus' import {CheckThick_Stroke2_Corner0_Rounded as CheckThink} from '#/components/icons/Check' import {PlusLarge_Stroke2_Corner0_Rounded as Plus} from '#/components/icons/Plus' @@ -50,7 +53,12 @@ function DialogInner({control}: {control: Dialog.DialogControlProps}) { const routes = useNavigationState(state => state.routes) const currentRoute = routes.at(routes.length - 1) const isOnSubscriptionsPage = currentRoute?.name === 'Subscriptions' + // TODO if 3p PDS + const needsEmail = !currentAccount?.email + const needsConfirmEmail = !currentAccount?.emailConfirmed + const isDisabled = needsEmail || needsConfirmEmail + const [email, setEmail] = React.useState('') const [error, setError] = React.useState('') const [offeringId, setOfferingId] = React.useState( SubscriptionOfferingId.CoreAnnual, @@ -59,22 +67,40 @@ function DialogInner({control}: {control: Dialog.DialogControlProps}) { const {mutateAsync: purchaseOffering, isPending} = usePurchaseOffering() const onPressSubscribe = async () => { + setError('') + async function purchase() { if (!currentAccount) return const offering = coreOffering?.offerings.find(o => o.id === offeringId) if (!offering) { - Toast.show( - _(msg`Hmmmm. We couldn't locate that subscription.`), - 'xmark', + const message = _(msg`Hmmmm. We couldn't locate that subscription.`) + if (isWeb) { + setError(message) + } else { + Toast.show(message, 'xmark') + } + return + } + + const emailValue = email ?? currentAccount.email + + if (!emailValue) { + const message = _( + msg`Hmmm. Something went wrong, sorry about that. Please try again.`, ) + if (isWeb) { + setError(message) + } else { + Toast.show(message, 'xmark') + } return } await purchaseOffering({ did: currentAccount.did, - email: currentAccount.email!, + email: emailValue, offering, }) } @@ -263,6 +289,47 @@ function DialogInner({control}: {control: Dialog.DialogControlProps}) { })} + {needsEmail ? ( + + + + + + A real email is required in order to receive support and updates + for your subscription. + + + + + + + + + + + ) : needsConfirmEmail ? ( + + + + You must verify your email to continue. Without a valid email, we + can provide no support for your subscription. + {' '} + + Click here to begin. + + + + ) : null} + {!isOnSubscriptionsPage && (