Skip to content

Commit

Permalink
Tweak email verification dialog (#6397)
Browse files Browse the repository at this point in the history
  • Loading branch information
haileyok authored Nov 16, 2024
1 parent a9cacbf commit c0fb524
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 24 deletions.
67 changes: 45 additions & 22 deletions src/components/dialogs/VerifyEmailDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,18 +146,17 @@ export function Inner({
<ErrorMessage message={error} />
</View>
) : null}
<Text style={[a.text_md, a.leading_snug]}>
{currentStep === 'StepOne' ? (
<>
{!reasonText ? (
<>
<Trans>
You'll receive an email at{' '}
<Text style={[a.text_md, a.leading_snug, a.font_bold]}>
{currentAccount?.email}
</Text>{' '}
to verify it's you.
</Trans>{' '}
{currentStep === 'StepOne' ? (
<View>
{reasonText ? (
<View style={[a.gap_sm]}>
<Text style={[a.text_md, a.leading_snug]}>{reasonText}</Text>
<Text style={[a.text_md, a.leading_snug]}>
Don't have access to{' '}
<Text style={[a.text_md, a.leading_snug, a.font_bold]}>
{currentAccount?.email}
</Text>
?{' '}
<InlineLinkText
to="#"
label={_(msg`Change email address`)}
Expand All @@ -169,17 +168,41 @@ export function Inner({
})
return false
}}>
<Trans>Need to change it?</Trans>
<Trans>Change your email address</Trans>
</InlineLinkText>
</>
) : (
reasonText
)}
</>
) : (
uiStrings[currentStep].message
)}
</Text>
.
</Text>
</View>
) : (
<Text style={[a.text_md, a.leading_snug]}>
<Trans>
You'll receive an email at{' '}
<Text style={[a.text_md, a.leading_snug, a.font_bold]}>
{currentAccount?.email}
</Text>{' '}
to verify it's you.
</Trans>{' '}
<InlineLinkText
to="#"
label={_(msg`Change email address`)}
style={[a.text_md, a.leading_snug]}
onPress={e => {
e.preventDefault()
control.close(() => {
openModal({name: 'change-email'})
})
return false
}}>
<Trans>Need to change it?</Trans>
</InlineLinkText>
</Text>
)}
</View>
) : (
<Text style={[a.text_md, a.leading_snug]}>
{uiStrings[currentStep].message}
</Text>
)}
</View>
{currentStep === 'StepTwo' ? (
<View>
Expand Down
16 changes: 14 additions & 2 deletions src/lib/hooks/useEmail.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {useServiceConfigQuery} from '#/state/queries/email-verification-required'
import {useProfileQuery} from '#/state/queries/profile'
import {useSession} from '#/state/session'
import {BSKY_SERVICE} from '../constants'
import {getHostnameFromUrl} from '../strings/url-helpers'
Expand All @@ -7,13 +8,24 @@ export function useEmail() {
const {currentAccount} = useSession()

const {data: serviceConfig} = useServiceConfigQuery()
const {data: profile} = useProfileQuery({did: currentAccount?.did})

const checkEmailConfirmed = !!serviceConfig?.checkEmailConfirmed

const isNewEnough =
!!profile?.createdAt &&
Date.parse(profile.createdAt) >= Date.parse('2024-11-16T02:00:00.000Z')

const isSelfHost =
serviceConfig?.checkEmailConfirmed &&
currentAccount &&
getHostnameFromUrl(currentAccount.service) !==
getHostnameFromUrl(BSKY_SERVICE)
const needsEmailVerification = !isSelfHost && !currentAccount?.emailConfirmed

const needsEmailVerification =
!isSelfHost &&
checkEmailConfirmed &&
!!currentAccount?.emailConfirmed &&
isNewEnough

return {needsEmailVerification}
}

0 comments on commit c0fb524

Please sign in to comment.