Skip to content

Commit

Permalink
feat: Handle emtpy offers response as error (#991)
Browse files Browse the repository at this point in the history
  • Loading branch information
gorandalum authored Mar 10, 2021
1 parent 49ec0c1 commit 1b408c7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/screens/Ticketing/Purchase/Confirmation/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ const Confirmation: React.FC<ConfirmationProps> = ({
<View>
{error && (
<MessageBox
type="warning"
type="error"
title={t(PurchaseConfirmationTexts.errorMessageBox.title)}
message={t(PurchaseConfirmationTexts.errorMessageBox.message)}
retryFunction={refreshOffer}
Expand Down
14 changes: 9 additions & 5 deletions src/screens/Ticketing/Purchase/Overview/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {UserProfileWithCount} from '../Travellers/use-user-count-state';
import {getReferenceDataName} from '@atb/reference-data/utils';
import turfBooleanPointInPolygon from '@turf/boolean-point-in-polygon';
import React, {useEffect, useMemo} from 'react';
import {View} from 'react-native';
import {ActivityIndicator, View} from 'react-native';
import {SafeAreaView} from 'react-native-safe-area-context';
import {TicketingStackParams} from '../';
import {tariffZonesSummary, TariffZoneWithMetadata} from '../TariffZones';
Expand Down Expand Up @@ -113,7 +113,7 @@ const PurchaseOverview: React.FC<OverviewProps> = ({
<View style={styles.selectionLinks}>
{error && (
<MessageBox
type="warning"
type="error"
title={t(PurchaseOverviewTexts.errorMessageBox.title)}
message={t(PurchaseOverviewTexts.errorMessageBox.message)}
retryFunction={refreshOffer}
Expand Down Expand Up @@ -173,9 +173,13 @@ const PurchaseOverview: React.FC<OverviewProps> = ({
}}
/>
<Sections.GenericItem>
<ThemeText style={styles.totalSection} type="paragraphHeadline">
{t(PurchaseOverviewTexts.totalPrice(totalPrice))}
</ThemeText>
{isSearchingOffer ? (
<ActivityIndicator style={styles.totalSection} />
) : (
<ThemeText style={styles.totalSection} type="paragraphHeadline">
{t(PurchaseOverviewTexts.totalPrice(totalPrice))}
</ThemeText>
)}
</Sections.GenericItem>
</Sections.Section>
</View>
Expand Down
13 changes: 11 additions & 2 deletions src/screens/Ticketing/Purchase/Overview/use-offer-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type UserProfileWithCountAndOffer = UserProfileWithCount & {
};

type OfferError = {
type: ErrorType;
type: ErrorType | 'empty-offers';
};

type OfferState = {
Expand Down Expand Up @@ -150,7 +150,16 @@ export default function useOfferState(

cancelToken?.throwIfRequested();

dispatch({type: 'SET_OFFER', offers: response});
if (response.length) {
dispatch({type: 'SET_OFFER', offers: response});
} else {
dispatch({
type: 'SET_ERROR',
error: {
type: 'empty-offers',
},
});
}
} catch (err) {
console.warn(err);

Expand Down

0 comments on commit 1b408c7

Please sign in to comment.