add a `Login` notifications request (#4006)

zio/stable
Hailey 2024-05-13 19:51:12 -07:00 committed by GitHub
parent fce65b74ff
commit fd704bfd44
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 1 deletions

View File

@ -72,7 +72,7 @@ export function useRequestNotificationsPermission() {
const gate = useGate() const gate = useGate()
return React.useCallback( return React.useCallback(
async (context: 'StartOnboarding' | 'AfterOnboarding') => { async (context: 'StartOnboarding' | 'AfterOnboarding' | 'Login') => {
const permissions = await Notifications.getPermissionsAsync() const permissions = await Notifications.getPermissionsAsync()
if ( if (
@ -97,6 +97,7 @@ export function useRequestNotificationsPermission() {
const res = await Notifications.requestPermissionsAsync() const res = await Notifications.requestPermissionsAsync()
logEvent('notifications:request', { logEvent('notifications:request', {
context: context,
status: res.status, status: res.status,
}) })

View File

@ -17,6 +17,7 @@ export type LogEvents = {
} }
'notifications:openApp': {} 'notifications:openApp': {}
'notifications:request': { 'notifications:request': {
context: 'StartOnboarding' | 'AfterOnboarding' | 'Login'
status: 'granted' | 'denied' | 'undetermined' status: 'granted' | 'denied' | 'undetermined'
} }
'state:background': { 'state:background': {

View File

@ -19,6 +19,7 @@ import {cleanError} from '#/lib/strings/errors'
import {createFullHandle} from '#/lib/strings/handles' import {createFullHandle} from '#/lib/strings/handles'
import {logger} from '#/logger' import {logger} from '#/logger'
import {useSessionApi} from '#/state/session' import {useSessionApi} from '#/state/session'
import {useRequestNotificationsPermission} from 'lib/notifications/notifications'
import {atoms as a, useTheme} from '#/alf' import {atoms as a, useTheme} from '#/alf'
import {Button, ButtonIcon, ButtonText} from '#/components/Button' import {Button, ButtonIcon, ButtonText} from '#/components/Button'
import {FormError} from '#/components/forms/FormError' import {FormError} from '#/components/forms/FormError'
@ -65,6 +66,7 @@ export const LoginForm = ({
const passwordInputRef = useRef<TextInput>(null) const passwordInputRef = useRef<TextInput>(null)
const {_} = useLingui() const {_} = useLingui()
const {login} = useSessionApi() const {login} = useSessionApi()
const requestNotificationsPermission = useRequestNotificationsPermission()
const onPressSelectService = React.useCallback(() => { const onPressSelectService = React.useCallback(() => {
Keyboard.dismiss() Keyboard.dismiss()
@ -111,6 +113,7 @@ export const LoginForm = ({
}, },
'LoginForm', 'LoginForm',
) )
requestNotificationsPermission('Login')
} catch (e: any) { } catch (e: any) {
const errMsg = e.toString() const errMsg = e.toString()
LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut) LayoutAnimation.configureNext(LayoutAnimation.Presets.easeInEaseOut)