Skip to content

Commit

Permalink
bug/6846-theo-DemographicsFetchedBeforeLogin (#6849)
Browse files Browse the repository at this point in the history
* Fetch demographics data after loggedIn

* Update global stale time

* Disable authorized services call until login is complete

* Remove unneeded data from Home screen

* Remove demographics call

* Remove options param
  • Loading branch information
theodur authored Oct 9, 2023
1 parent 6521804 commit 6c00910
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ export const getAuthorizedServices = async (): Promise<UserAuthorizedServicesDat
/**
* Returns a query for user demographics
*/
export const useAuthorizedServices = () => {
export const useAuthorizedServices = (options?: { enabled?: boolean }) => {
return useQuery({
...options,
queryKey: authorizedServicesKeys.authorizedServices,
queryFn: () => getAuthorizedServices(),
meta: {
Expand Down
15 changes: 0 additions & 15 deletions VAMobile/src/screens/HomeScreen/HomeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,10 @@ import { CloseSnackbarOnNavigation } from 'constants/common'
import { Events } from 'constants/analytics'
import { HomeStackParamList } from './HomeStackScreens'
import { NAMESPACE } from 'constants/namespaces'
import { PersonalInformationState, getProfileInfo } from 'store/slices/personalInformationSlice'
import { RootState } from 'store'
import { ScreenIDTypesConstants } from 'store/api/types'
import { a11yLabelVA } from 'utils/a11yLabel'
import { logAnalyticsEvent } from 'utils/analytics'
import { logCOVIDClickAnalytics } from 'store/slices/vaccineSlice'
import { useAppDispatch, useRouteNavigation, useTheme } from 'utils/hooks'
import { useDemographics } from 'api/demographics/getDemographics'
import { useSelector } from 'react-redux'
import ContactInformationScreen from './ProfileScreen/ContactInformationScreen'
import ContactVAScreen from './ContactVAScreen/ContactVAScreen'
import DeveloperScreen from './ProfileScreen/SettingsScreen/DeveloperScreen'
Expand All @@ -42,16 +37,6 @@ export const HomeScreen: FC<HomeScreenProps> = ({ navigation }) => {

const navigateTo = useRouteNavigation()
const theme = useTheme()
const { profile } = useSelector<RootState, PersonalInformationState>((state) => state.personalInformation)
const { data: demographics, isLoading: loadingDemographics } = useDemographics()
const name = loadingDemographics ? '' : demographics?.preferredName || profile?.firstName || ''

useEffect(() => {
// Fetch the profile information
if (name === '') {
dispatch(getProfileInfo(ScreenIDTypesConstants.PROFILE_SCREEN_ID))
}
}, [dispatch, name])

useEffect(() => {
navigation.setOptions({
Expand Down
14 changes: 0 additions & 14 deletions VAMobile/src/screens/SyncScreen/SyncScreen.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,6 @@ context('SyncScreen', () => {

describe('sync completion', () => {
it('should complete the sync when all loading is finished', async () => {
jest.mock('../../api/demographics/getDemographics', () => {
let original = jest.requireActual('../../api/demographics/getDemographics')
return {
...original,
useDemographics: () => ({
status: "success",
data: {
genderIdentity: '',
preferredName: '',
}
}),
}
})

initializeTestInstance(false, false, false, true, false)
await waitFor(async () => {
expect(completeSync).toHaveBeenCalled()
Expand Down
7 changes: 2 additions & 5 deletions VAMobile/src/screens/SyncScreen/SyncScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import { RootState } from 'store'
import { testIdProps } from 'utils/accessibility'
import { useAppDispatch, useOrientation, useTheme } from 'utils/hooks'
import { useAuthorizedServices } from 'api/authorizedServices/getAuthorizedServices'
import { useDemographics } from 'api/demographics/getDemographics'
import colors from 'styles/themes/VAColors'

export type SyncScreenProps = Record<string, unknown>
Expand All @@ -32,8 +31,7 @@ const SyncScreen: FC<SyncScreenProps> = () => {
const { preloadComplete: personalInformationLoaded, loading: personalInformationLoading } = useSelector<RootState, PersonalInformationState>((s) => s.personalInformation)
const { preloadComplete: militaryHistoryLoaded, loading: militaryHistoryLoading } = useSelector<RootState, MilitaryServiceState>((s) => s.militaryService)
const { preloadComplete: disabilityRatingLoaded, loading: disabilityRatingLoading } = useSelector<RootState, DisabilityRatingState>((s) => s.disabilityRating)
const { data: userAuthorizedServices, isLoading: loadingUserAuthorizedServices } = useAuthorizedServices()
const { isFetched: demographicsLoaded } = useDemographics()
const { data: userAuthorizedServices, isLoading: loadingUserAuthorizedServices } = useAuthorizedServices({ enabled: loggedIn })

const [displayMessage, setDisplayMessage] = useState('')

Expand Down Expand Up @@ -82,7 +80,7 @@ const SyncScreen: FC<SyncScreenProps> = () => {
}

const finishSyncingMilitaryHistory = !loadingUserAuthorizedServices && (!userAuthorizedServices?.militaryServiceHistory || militaryHistoryLoaded)
if (personalInformationLoaded && finishSyncingMilitaryHistory && loggedIn && !loggingOut && disabilityRatingLoaded && demographicsLoaded) {
if (personalInformationLoaded && finishSyncingMilitaryHistory && loggedIn && !loggingOut && disabilityRatingLoaded) {
dispatch(completeSync())
}
}, [
Expand All @@ -96,7 +94,6 @@ const SyncScreen: FC<SyncScreenProps> = () => {
t,
disabilityRatingLoaded,
syncing,
demographicsLoaded,
])

return (
Expand Down

0 comments on commit 6c00910

Please sign in to comment.