From 6c00910c8917dbdc4df7d35c8f4b74f65b369e19 Mon Sep 17 00:00:00 2001 From: Theo Bentum Date: Mon, 9 Oct 2023 14:31:14 -0700 Subject: [PATCH] bug/6846-theo-DemographicsFetchedBeforeLogin (#6849) * 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 --- .../authorizedServices/getAuthorizedServices.tsx | 3 ++- VAMobile/src/screens/HomeScreen/HomeScreen.tsx | 15 --------------- .../src/screens/SyncScreen/SyncScreen.test.tsx | 14 -------------- VAMobile/src/screens/SyncScreen/SyncScreen.tsx | 7 ++----- 4 files changed, 4 insertions(+), 35 deletions(-) diff --git a/VAMobile/src/api/authorizedServices/getAuthorizedServices.tsx b/VAMobile/src/api/authorizedServices/getAuthorizedServices.tsx index b7924affb45..2f030dd4878 100644 --- a/VAMobile/src/api/authorizedServices/getAuthorizedServices.tsx +++ b/VAMobile/src/api/authorizedServices/getAuthorizedServices.tsx @@ -15,8 +15,9 @@ export const getAuthorizedServices = async (): Promise { +export const useAuthorizedServices = (options?: { enabled?: boolean }) => { return useQuery({ + ...options, queryKey: authorizedServicesKeys.authorizedServices, queryFn: () => getAuthorizedServices(), meta: { diff --git a/VAMobile/src/screens/HomeScreen/HomeScreen.tsx b/VAMobile/src/screens/HomeScreen/HomeScreen.tsx index 301999c7e37..d13109726c9 100644 --- a/VAMobile/src/screens/HomeScreen/HomeScreen.tsx +++ b/VAMobile/src/screens/HomeScreen/HomeScreen.tsx @@ -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' @@ -42,16 +37,6 @@ export const HomeScreen: FC = ({ navigation }) => { const navigateTo = useRouteNavigation() const theme = useTheme() - const { profile } = useSelector((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({ diff --git a/VAMobile/src/screens/SyncScreen/SyncScreen.test.tsx b/VAMobile/src/screens/SyncScreen/SyncScreen.test.tsx index 212e8c27ed1..bbf403e0aa4 100644 --- a/VAMobile/src/screens/SyncScreen/SyncScreen.test.tsx +++ b/VAMobile/src/screens/SyncScreen/SyncScreen.test.tsx @@ -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() diff --git a/VAMobile/src/screens/SyncScreen/SyncScreen.tsx b/VAMobile/src/screens/SyncScreen/SyncScreen.tsx index 2e28d68db75..1a84717beb5 100644 --- a/VAMobile/src/screens/SyncScreen/SyncScreen.tsx +++ b/VAMobile/src/screens/SyncScreen/SyncScreen.tsx @@ -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 @@ -32,8 +31,7 @@ const SyncScreen: FC = () => { const { preloadComplete: personalInformationLoaded, loading: personalInformationLoading } = useSelector((s) => s.personalInformation) const { preloadComplete: militaryHistoryLoaded, loading: militaryHistoryLoading } = useSelector((s) => s.militaryService) const { preloadComplete: disabilityRatingLoaded, loading: disabilityRatingLoading } = useSelector((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('') @@ -82,7 +80,7 @@ const SyncScreen: FC = () => { } const finishSyncingMilitaryHistory = !loadingUserAuthorizedServices && (!userAuthorizedServices?.militaryServiceHistory || militaryHistoryLoaded) - if (personalInformationLoaded && finishSyncingMilitaryHistory && loggedIn && !loggingOut && disabilityRatingLoaded && demographicsLoaded) { + if (personalInformationLoaded && finishSyncingMilitaryHistory && loggedIn && !loggingOut && disabilityRatingLoaded) { dispatch(completeSync()) } }, [ @@ -96,7 +94,6 @@ const SyncScreen: FC = () => { t, disabilityRatingLoaded, syncing, - demographicsLoaded, ]) return (