Handle verification requirements for composer and convo
This commit is contained in:
@@ -7,6 +7,7 @@ import {
|
|||||||
type StatefulControl,
|
type StatefulControl,
|
||||||
useStatefulDialogControl,
|
useStatefulDialogControl,
|
||||||
} from '#/components/dialogs/Context'
|
} from '#/components/dialogs/Context'
|
||||||
|
import {useIsEmailVerified} from '#/components/dialogs/EmailDialog/data/useIsEmailVerified'
|
||||||
import {Manage2FA} from '#/components/dialogs/EmailDialog/screens/Manage2FA'
|
import {Manage2FA} from '#/components/dialogs/EmailDialog/screens/Manage2FA'
|
||||||
import {Update} from '#/components/dialogs/EmailDialog/screens/Update'
|
import {Update} from '#/components/dialogs/EmailDialog/screens/Update'
|
||||||
import {VerificationReminder} from '#/components/dialogs/EmailDialog/screens/VerificationReminder'
|
import {VerificationReminder} from '#/components/dialogs/EmailDialog/screens/VerificationReminder'
|
||||||
@@ -23,7 +24,14 @@ export function useEmailDialogControl() {
|
|||||||
|
|
||||||
export function EmailDialog({control}: {control: StatefulControl<Screen>}) {
|
export function EmailDialog({control}: {control: StatefulControl<Screen>}) {
|
||||||
const {_} = useLingui()
|
const {_} = useLingui()
|
||||||
const onClose = useCallback(() => {}, [])
|
const {isEmailVerified} = useIsEmailVerified()
|
||||||
|
const onClose = useCallback(() => {
|
||||||
|
if (!isEmailVerified) {
|
||||||
|
if (control.value?.id === ScreenID.Verify) {
|
||||||
|
control.value.onCloseWithoutVerifying?.()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, [isEmailVerified, control, ,])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog.Outer control={control.control} onClose={onClose}>
|
<Dialog.Outer control={control.control} onClose={onClose}>
|
||||||
|
|||||||
@@ -15,8 +15,8 @@ export type Screen =
|
|||||||
| {
|
| {
|
||||||
id: ScreenID.Verify
|
id: ScreenID.Verify
|
||||||
instructions?: ReactNode[]
|
instructions?: ReactNode[]
|
||||||
hideInitialCodeButton?: boolean
|
|
||||||
onVerify?: () => void
|
onVerify?: () => void
|
||||||
|
onCloseWithoutVerifying?: () => void
|
||||||
}
|
}
|
||||||
| {
|
| {
|
||||||
id: ScreenID.VerificationReminder
|
id: ScreenID.VerificationReminder
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import {
|
|||||||
moderateProfile,
|
moderateProfile,
|
||||||
type ModerationDecision,
|
type ModerationDecision,
|
||||||
} from '@atproto/api'
|
} from '@atproto/api'
|
||||||
import {msg} from '@lingui/macro'
|
import {msg, Trans} from '@lingui/macro'
|
||||||
import {useLingui} from '@lingui/react'
|
import {useLingui} from '@lingui/react'
|
||||||
import {
|
import {
|
||||||
type RouteProp,
|
type RouteProp,
|
||||||
@@ -31,8 +31,11 @@ import {useProfileQuery} from '#/state/queries/profile'
|
|||||||
import {useSetMinimalShellMode} from '#/state/shell'
|
import {useSetMinimalShellMode} from '#/state/shell'
|
||||||
import {MessagesList} from '#/screens/Messages/components/MessagesList'
|
import {MessagesList} from '#/screens/Messages/components/MessagesList'
|
||||||
import {atoms as a, useBreakpoints, useTheme, web} from '#/alf'
|
import {atoms as a, useBreakpoints, useTheme, web} from '#/alf'
|
||||||
import {useDialogControl} from '#/components/Dialog'
|
import {
|
||||||
import {VerifyEmailDialog} from '#/components/dialogs/VerifyEmailDialog'
|
EmailDialog,
|
||||||
|
EmailDialogScreenID,
|
||||||
|
useEmailDialogControl,
|
||||||
|
} from '#/components/dialogs/EmailDialog'
|
||||||
import {MessagesListBlockedFooter} from '#/components/dms/MessagesListBlockedFooter'
|
import {MessagesListBlockedFooter} from '#/components/dms/MessagesListBlockedFooter'
|
||||||
import {MessagesListHeader} from '#/components/dms/MessagesListHeader'
|
import {MessagesListHeader} from '#/components/dms/MessagesListHeader'
|
||||||
import {Error} from '#/components/Error'
|
import {Error} from '#/components/Error'
|
||||||
@@ -183,19 +186,29 @@ function InnerReady({
|
|||||||
hasScrolled: boolean
|
hasScrolled: boolean
|
||||||
setHasScrolled: React.Dispatch<React.SetStateAction<boolean>>
|
setHasScrolled: React.Dispatch<React.SetStateAction<boolean>>
|
||||||
}) {
|
}) {
|
||||||
const {_} = useLingui()
|
|
||||||
const convoState = useConvo()
|
const convoState = useConvo()
|
||||||
const navigation = useNavigation<NavigationProp>()
|
const navigation = useNavigation<NavigationProp>()
|
||||||
const {params} =
|
const {params} =
|
||||||
useRoute<RouteProp<CommonNavigatorParams, 'MessagesConversation'>>()
|
useRoute<RouteProp<CommonNavigatorParams, 'MessagesConversation'>>()
|
||||||
const verifyEmailControl = useDialogControl()
|
|
||||||
const {needsEmailVerification} = useEmail()
|
const {needsEmailVerification} = useEmail()
|
||||||
|
const emailDialogControl = useEmailDialogControl()
|
||||||
|
|
||||||
React.useEffect(() => {
|
React.useEffect(() => {
|
||||||
if (needsEmailVerification) {
|
if (needsEmailVerification) {
|
||||||
verifyEmailControl.open()
|
emailDialogControl.open({
|
||||||
|
id: EmailDialogScreenID.Verify,
|
||||||
|
instructions: [
|
||||||
|
<Trans key="pre-compose">
|
||||||
|
Before you may message another user, you must first verify your
|
||||||
|
email.
|
||||||
|
</Trans>,
|
||||||
|
],
|
||||||
|
onCloseWithoutVerifying: () => {
|
||||||
|
navigation.navigate('Home')
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}, [needsEmailVerification, verifyEmailControl])
|
}, [needsEmailVerification, emailDialogControl, navigation])
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
@@ -216,15 +229,7 @@ function InnerReady({
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<VerifyEmailDialog
|
<EmailDialog control={emailDialogControl} />
|
||||||
reasonText={_(
|
|
||||||
msg`Before you may message another user, you must first verify your email.`,
|
|
||||||
)}
|
|
||||||
control={verifyEmailControl}
|
|
||||||
onCloseWithoutVerifying={() => {
|
|
||||||
navigation.navigate('Home')
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -120,8 +120,11 @@ import * as Toast from '#/view/com/util/Toast'
|
|||||||
import {UserAvatar} from '#/view/com/util/UserAvatar'
|
import {UserAvatar} from '#/view/com/util/UserAvatar'
|
||||||
import {atoms as a, native, useTheme} from '#/alf'
|
import {atoms as a, native, useTheme} from '#/alf'
|
||||||
import {Button, ButtonIcon, ButtonText} from '#/components/Button'
|
import {Button, ButtonIcon, ButtonText} from '#/components/Button'
|
||||||
import {useDialogControl} from '#/components/Dialog'
|
import {
|
||||||
import {VerifyEmailDialog} from '#/components/dialogs/VerifyEmailDialog'
|
EmailDialog,
|
||||||
|
EmailDialogScreenID,
|
||||||
|
useEmailDialogControl,
|
||||||
|
} from '#/components/dialogs/EmailDialog'
|
||||||
import {CircleInfo_Stroke2_Corner0_Rounded as CircleInfo} from '#/components/icons/CircleInfo'
|
import {CircleInfo_Stroke2_Corner0_Rounded as CircleInfo} from '#/components/icons/CircleInfo'
|
||||||
import {EmojiArc_Stroke2_Corner0_Rounded as EmojiSmile} from '#/components/icons/Emoji'
|
import {EmojiArc_Stroke2_Corner0_Rounded as EmojiSmile} from '#/components/icons/Emoji'
|
||||||
import {TimesLarge_Stroke2_Corner0_Rounded as X} from '#/components/icons/Times'
|
import {TimesLarge_Stroke2_Corner0_Rounded as X} from '#/components/icons/Times'
|
||||||
@@ -332,13 +335,23 @@ export const ComposePost = ({
|
|||||||
}, [onPressCancel, closeAllDialogs, closeAllModals])
|
}, [onPressCancel, closeAllDialogs, closeAllModals])
|
||||||
|
|
||||||
const {needsEmailVerification} = useEmail()
|
const {needsEmailVerification} = useEmail()
|
||||||
const emailVerificationControl = useDialogControl()
|
const emailDialogControl = useEmailDialogControl()
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (needsEmailVerification) {
|
if (needsEmailVerification) {
|
||||||
emailVerificationControl.open()
|
emailDialogControl.open({
|
||||||
|
id: EmailDialogScreenID.Verify,
|
||||||
|
instructions: [
|
||||||
|
<Trans key="pre-compose">
|
||||||
|
Before creating a post, you must first verify your email.
|
||||||
|
</Trans>,
|
||||||
|
],
|
||||||
|
onCloseWithoutVerifying: () => {
|
||||||
|
onClose()
|
||||||
|
},
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}, [needsEmailVerification, emailVerificationControl])
|
}, [needsEmailVerification, emailDialogControl, onClose])
|
||||||
|
|
||||||
const missingAltError = useMemo(() => {
|
const missingAltError = useMemo(() => {
|
||||||
if (!requireAltTextEnabled) {
|
if (!requireAltTextEnabled) {
|
||||||
@@ -620,15 +633,7 @@ export const ComposePost = ({
|
|||||||
const isWebFooterSticky = !isNative && thread.posts.length > 1
|
const isWebFooterSticky = !isNative && thread.posts.length > 1
|
||||||
return (
|
return (
|
||||||
<BottomSheetPortalProvider>
|
<BottomSheetPortalProvider>
|
||||||
<VerifyEmailDialog
|
<EmailDialog control={emailDialogControl} />
|
||||||
control={emailVerificationControl}
|
|
||||||
onCloseWithoutVerifying={() => {
|
|
||||||
onClose()
|
|
||||||
}}
|
|
||||||
reasonText={_(
|
|
||||||
msg`Before creating a post, you must first verify your email.`,
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
<KeyboardAvoidingView
|
<KeyboardAvoidingView
|
||||||
testID="composePostView"
|
testID="composePostView"
|
||||||
behavior={isIOS ? 'padding' : 'height'}
|
behavior={isIOS ? 'padding' : 'height'}
|
||||||
|
|||||||
Reference in New Issue
Block a user