Skip to content

Commit

Permalink
feature/Binny-8620-VetStatusAnalytics (#8621)
Browse files Browse the repository at this point in the history
Co-authored-by: Theo Bentum <[email protected]>
  • Loading branch information
dumathane and theodur authored May 28, 2024
1 parent 67095aa commit 368cbd6
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 1 deletion.
18 changes: 18 additions & 0 deletions VAMobile/src/constants/analytics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1101,6 +1101,24 @@ export const Events = {
},
}
},
vama_vet_status_nStatus: (): Event => {
return {
name: 'vama_vet_status_nStatus',
}
},
vama_vet_status_yStatus: (): Event => {
return {
name: 'vama_vet_status_yStatus',
}
},
vama_vet_status_zStatus: (charOfDis: string): Event => {
return {
name: 'vama_vet_status_zStatus',
params: {
charOfDis,
},
}
},
vama_whatsnew_alert: (): Event => {
return {
name: 'vama_whatsnew_alert',
Expand Down
59 changes: 58 additions & 1 deletion VAMobile/src/screens/HomeScreen/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useEffect } from 'react'
import { useTranslation } from 'react-i18next'
import { useSelector } from 'react-redux'

import AsyncStorage from '@react-native-async-storage/async-storage'
import { CardStyleInterpolators, createStackNavigator } from '@react-navigation/stack'
import { StackScreenProps } from '@react-navigation/stack/lib/typescript/src/types'

Expand All @@ -10,8 +11,11 @@ import { DateTime } from 'luxon'
import { useAppointments } from 'api/appointments'
import { useAuthorizedServices } from 'api/authorizedServices/getAuthorizedServices'
import { useClaimsAndAppeals } from 'api/claimsAndAppeals'
import { useServiceHistory } from 'api/militaryService'
import { usePersonalInformation } from 'api/personalInformation/getPersonalInformation'
import { usePrescriptions } from 'api/prescriptions'
import { useFolders } from 'api/secureMessaging'
import { ServiceHistoryData } from 'api/types'
import {
Box,
CategoryLanding,
Expand All @@ -33,7 +37,7 @@ import { RootState } from 'store'
import { DowntimeFeatureTypeConstants } from 'store/api/types'
import { AnalyticsState } from 'store/slices'
import { a11yLabelVA } from 'utils/a11yLabel'
import { logAnalyticsEvent } from 'utils/analytics'
import { logAnalyticsEvent, logNonFatalErrorToFirebase } from 'utils/analytics'
import getEnv from 'utils/env'
import { useAppDispatch, useDowntime, useRouteNavigation, useTheme } from 'utils/hooks'
import { featureEnabled } from 'utils/remoteConfig'
Expand Down Expand Up @@ -83,6 +87,10 @@ export function HomeScreen({}: HomeScreenProps) {
const { data: prescriptionData, isFetched: rxPrefetch } = usePrescriptions({
enabled: featureEnabled('homeScreenPrefetch'),
})
const { data: militaryServiceHistoryAttributes } = useServiceHistory({
enabled: false,
})
const { data: personalInfoData } = usePersonalInformation({ enabled: false })

useEffect(() => {
if (apptsPrefetch && apptsData?.meta) {
Expand Down Expand Up @@ -117,6 +125,55 @@ export function HomeScreen({}: HomeScreenProps) {
}
}, [dispatch, apptsPrefetch, claimsPrefetch, rxPrefetch, smPrefetch, loginTimestamp])

useEffect(() => {
const SERVICE_INDICATOR_KEY = `@store_service_indicator${personalInfoData?.id}`
const serviceHistory = militaryServiceHistoryAttributes?.serviceHistory || ([] as ServiceHistoryData)

const setServiceIndicators = async (serviceIndicators: string): Promise<void> => {
try {
serviceHistory.forEach((service) => {
if (service.honorableServiceIndicator === 'Y') {
logAnalyticsEvent(Events.vama_vet_status_yStatus())
} else if (service.honorableServiceIndicator === 'N') {
logAnalyticsEvent(Events.vama_vet_status_nStatus())
} else if (service.honorableServiceIndicator === 'Z') {
logAnalyticsEvent(Events.vama_vet_status_zStatus(service.characterOfDischarge))
}
})
await AsyncStorage.setItem(SERVICE_INDICATOR_KEY, serviceIndicators)
console.log('setStorage: ', SERVICE_INDICATOR_KEY, serviceIndicators)
} catch (err) {
logNonFatalErrorToFirebase(err, 'loadOverrides: AsyncStorage error')
}
}

const checkServiceIndicators = async (serviceIndicators: string): Promise<void> => {
if (!serviceIndicators) {
return
}

try {
const asyncServiceIndicators = await AsyncStorage.getItem(SERVICE_INDICATOR_KEY)
if (!asyncServiceIndicators || asyncServiceIndicators !== serviceIndicators) {
console.log('asyncServiceIndicators: ', asyncServiceIndicators)
setServiceIndicators(serviceIndicators)
}
} catch (err) {
logNonFatalErrorToFirebase(err, 'loadOverrides: AsyncStorage error')
}
}

if (serviceHistory) {
let serviceIndicators = ''
serviceHistory.forEach((service) => {
console.log('service: ', JSON.stringify(service, undefined, 2))
serviceIndicators = serviceIndicators.concat(service.honorableServiceIndicator)
})
console.log('serviceIndicators: ', serviceIndicators)
checkServiceIndicators(serviceIndicators)
}
}, [militaryServiceHistoryAttributes?.serviceHistory, personalInfoData?.id])

const navigateTo = useRouteNavigation()

const onContactVA = () => {
Expand Down

0 comments on commit 368cbd6

Please sign in to comment.