From eb38d1945c169c6483169ac4975213031b075118 Mon Sep 17 00:00:00 2001 From: Theo Bentum Date: Mon, 26 Aug 2024 09:15:26 -0700 Subject: [PATCH] bug/9395-ProfileScreenErrorState (#9433) Co-authored-by: Jon Bindbeutel --- .../ProfileScreen/ProfileScreen.test.tsx | 6 +- .../ProfileScreen/ProfileScreen.tsx | 84 ++++++++----------- 2 files changed, 38 insertions(+), 52 deletions(-) diff --git a/VAMobile/src/screens/HomeScreen/ProfileScreen/ProfileScreen.test.tsx b/VAMobile/src/screens/HomeScreen/ProfileScreen/ProfileScreen.test.tsx index 89c8191c82b..eb0885e90a3 100644 --- a/VAMobile/src/screens/HomeScreen/ProfileScreen/ProfileScreen.test.tsx +++ b/VAMobile/src/screens/HomeScreen/ProfileScreen/ProfileScreen.test.tsx @@ -83,13 +83,15 @@ context('ProfileScreen', () => { }) describe('when common error occurs', () => { - it('should render error component', async () => { + it('renders error message', async () => { when(api.get as jest.Mock) .calledWith('/v0/military-service-history') .mockRejectedValue({ networkError: true } as api.APIError) initializeTestInstance() - await waitFor(() => expect(screen.getByText("The app can't be loaded.")).toBeTruthy()) + await waitFor(() => + expect(screen.getByText('We can’t show all your information right now. Check back later.')).toBeTruthy(), + ) }) }) }) diff --git a/VAMobile/src/screens/HomeScreen/ProfileScreen/ProfileScreen.tsx b/VAMobile/src/screens/HomeScreen/ProfileScreen/ProfileScreen.tsx index 03470e2a656..f0efcce9f64 100644 --- a/VAMobile/src/screens/HomeScreen/ProfileScreen/ProfileScreen.tsx +++ b/VAMobile/src/screens/HomeScreen/ProfileScreen/ProfileScreen.tsx @@ -6,45 +6,40 @@ import { StackScreenProps } from '@react-navigation/stack' import { useAuthorizedServices } from 'api/authorizedServices/getAuthorizedServices' import { useServiceHistory } from 'api/militaryService' import { usePersonalInformation } from 'api/personalInformation/getPersonalInformation' -import { Box, ChildTemplate, ErrorComponent, LargeNavButton, LoadingComponent, NameTag, TextView } from 'components' +import { + Box, + CategoryLandingAlert, + ChildTemplate, + ErrorComponent, + LargeNavButton, + LoadingComponent, + NameTag, + TextView, +} from 'components' import { NAMESPACE } from 'constants/namespaces' import { HomeStackParamList } from 'screens/HomeScreen/HomeStackScreens' -import { ScreenIDTypesConstants } from 'store/api/types' -import { useError, useRouteNavigation, useTheme } from 'utils/hooks' +import { DowntimeFeatureTypeConstants, ScreenIDTypesConstants } from 'store/api/types' +import { useDowntime, useRouteNavigation, useTheme } from 'utils/hooks' type ProfileScreenProps = StackScreenProps function ProfileScreen({ navigation }: ProfileScreenProps) { + const theme = useTheme() + const navigateTo = useRouteNavigation() + const { t } = useTranslation(NAMESPACE.COMMON) + const { data: userAuthorizedServices, isLoading: loadingUserAuthorizedServices, error: getUserAuthorizedServicesError, refetch: refetchUserAuthorizedServices, } = useAuthorizedServices() - - const { - isLoading: loadingServiceHistory, - error: serviceHistoryError, - refetch: refetchServiceHistory, - } = useServiceHistory() - const navigateTo = useRouteNavigation() - const theme = useTheme() - const { t } = useTranslation(NAMESPACE.COMMON) const { data: personalInfo } = usePersonalInformation() + const { isLoading: loadingServiceHistory, isError: serviceHistoryError } = useServiceHistory() - /** - * Function used on error to reload the data for this page. This combines all calls necessary to load the page rather - * than checking the needsDataLoad flag because if something went wrong we assume we want to reload all of the necessary data - */ - const getInfoTryAgain = (): void => { - refetchUserAuthorizedServices() - if (userAuthorizedServices?.militaryServiceHistory && serviceHistoryError) { - refetchServiceHistory() - } - } + const serviceHistoryInDowntime = useDowntime(DowntimeFeatureTypeConstants.militaryServiceHistory) const loadingCheck = loadingServiceHistory || loadingUserAuthorizedServices - const errorCheck = useError(ScreenIDTypesConstants.PROFILE_SCREEN_ID) || serviceHistoryError const displayName = !!personalInfo?.fullName && ( @@ -77,37 +72,26 @@ function ProfileScreen({ navigation }: ProfileScreenProps) { screenID={ScreenIDTypesConstants.PROFILE_SCREEN_ID} error={getUserAuthorizedServicesError} /> - ) : errorCheck ? ( - - - - navigateTo('Settings')} /> - - ) : ( <> {displayName} - - {userAuthorizedServices?.userProfileUpdate && ( - <> - navigateTo('PersonalInformation')} - /> - navigateTo('ContactInformation')} - /> - - )} - navigateTo('MilitaryInformation')} /> - navigateTo('Settings')} /> - + {userAuthorizedServices?.userProfileUpdate && ( + <> + navigateTo('PersonalInformation')} + /> + navigateTo('ContactInformation')} /> + + )} + navigateTo('MilitaryInformation')} /> + navigateTo('Settings')} /> + {(serviceHistoryError || serviceHistoryInDowntime) && ( + + + + )} )}