about summary refs log tree commit diff
path: root/src/components/dms/MessageProfileButton.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'src/components/dms/MessageProfileButton.tsx')
-rw-r--r--src/components/dms/MessageProfileButton.tsx43
1 files changed, 15 insertions, 28 deletions
diff --git a/src/components/dms/MessageProfileButton.tsx b/src/components/dms/MessageProfileButton.tsx
index 7f31f550c..07b3a0c04 100644
--- a/src/components/dms/MessageProfileButton.tsx
+++ b/src/components/dms/MessageProfileButton.tsx
@@ -1,20 +1,18 @@
 import React from 'react'
 import {View} from 'react-native'
-import {AppBskyActorDefs} from '@atproto/api'
-import {msg} from '@lingui/macro'
+import {type AppBskyActorDefs} from '@atproto/api'
+import {msg, Trans} from '@lingui/macro'
 import {useLingui} from '@lingui/react'
 import {useNavigation} from '@react-navigation/native'
 
-import {useEmail} from '#/lib/hooks/useEmail'
-import {NavigationProp} from '#/lib/routes/types'
+import {useRequireEmailVerification} from '#/lib/hooks/useRequireEmailVerification'
+import {type NavigationProp} from '#/lib/routes/types'
 import {logEvent} from '#/lib/statsig/statsig'
 import {useGetConvoAvailabilityQuery} from '#/state/queries/messages/get-convo-availability'
 import {useGetConvoForMembers} from '#/state/queries/messages/get-convo-for-members'
 import * as Toast from '#/view/com/util/Toast'
 import {atoms as a, useTheme} from '#/alf'
 import {Button, ButtonIcon} from '#/components/Button'
-import {useDialogControl} from '#/components/Dialog'
-import {VerifyEmailDialog} from '#/components/dialogs/VerifyEmailDialog'
 import {canBeMessaged} from '#/components/dms/util'
 import {Message_Stroke2_Corner0_Rounded as Message} from '#/components/icons/Message'
 
@@ -26,8 +24,7 @@ export function MessageProfileButton({
   const {_} = useLingui()
   const t = useTheme()
   const navigation = useNavigation<NavigationProp>()
-  const {needsEmailVerification} = useEmail()
-  const verifyEmailControl = useDialogControl()
+  const requireEmailVerification = useRequireEmailVerification()
 
   const {data: convoAvailability} = useGetConvoAvailabilityQuery(profile.did)
   const {mutate: initiateConvo} = useGetConvoForMembers({
@@ -45,11 +42,6 @@ export function MessageProfileButton({
       return
     }
 
-    if (needsEmailVerification) {
-      verifyEmailControl.open()
-      return
-    }
-
     if (convoAvailability.convo) {
       logEvent('chat:open', {logContext: 'ProfileHeader'})
       navigation.navigate('MessagesConversation', {
@@ -59,14 +51,15 @@ export function MessageProfileButton({
       logEvent('chat:create', {logContext: 'ProfileHeader'})
       initiateConvo([profile.did])
     }
-  }, [
-    needsEmailVerification,
-    verifyEmailControl,
-    navigation,
-    profile.did,
-    initiateConvo,
-    convoAvailability,
-  ])
+  }, [navigation, profile.did, initiateConvo, convoAvailability])
+
+  const wrappedOnPress = requireEmailVerification(onPress, {
+    instructions: [
+      <Trans key="message">
+        Before you can message another user, you must first verify your email.
+      </Trans>,
+    ],
+  })
 
   if (!convoAvailability) {
     // show pending state based on declaration
@@ -102,15 +95,9 @@ export function MessageProfileButton({
           shape="round"
           label={_(msg`Message ${profile.handle}`)}
           style={[a.justify_center]}
-          onPress={onPress}>
+          onPress={wrappedOnPress}>
           <ButtonIcon icon={Message} size="md" />
         </Button>
-        <VerifyEmailDialog
-          reasonText={_(
-            msg`Before you may message another user, you must first verify your email.`,
-          )}
-          control={verifyEmailControl}
-        />
       </>
     )
   } else {