Skip to content

Commit

Permalink
fix: Purchase builder products input from API (#4847)
Browse files Browse the repository at this point in the history
The fare products in the PurchaseSelectionBuilderInput needs to
come from the products API for HjemJobbHjem to work.

Added staleTime to not make the app query products API everytime
it tries to open the purchase flow. Also set initialDataUpdateAt: 0
so the products directly from Firestore is considered stale at
query mount.
  • Loading branch information
gorandalum authored and reidzeibel committed Nov 27, 2024
1 parent b5ebb81 commit 4547ef6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/purchase-selection/use-purchase-selection-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {getCurrentCoordinatesGlobal} from '@atb/GeolocationContext';
import {usePreferences} from '@atb/preferences';
import {useTicketingState} from '@atb/ticketing';
import {APP_VERSION} from '@env';
import {useGetFareProductsQuery} from '@atb/ticketing/use-get-fare-products-query';

/**
* Returns a purchase selection builder for creating or modifying a
Expand All @@ -19,16 +20,13 @@ import {APP_VERSION} from '@env';
* should be invoked by user actions and not as a side effect of state change.
*/
export const usePurchaseSelectionBuilder = () => {
const {
fareProductTypeConfigs,
userProfiles,
preassignedFareProducts,
tariffZones,
} = useFirestoreConfiguration();
const {fareProductTypeConfigs, userProfiles, tariffZones} =
useFirestoreConfiguration();
const {
preferences: {defaultUserTypeString},
} = usePreferences();
const {customerProfile} = useTicketingState();
const {data: preassignedFareProducts} = useGetFareProductsQuery();

const builderInput: PurchaseSelectionBuilderInput = {
fareProductTypeConfigs,
Expand Down
2 changes: 2 additions & 0 deletions src/ticketing/use-get-fare-products-query.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ export const useGetFareProductsQuery = () => {
const {userId, authStatus} = useAuthState();
return useQuery({
initialData: preassignedFareProducts,
initialDataUpdatedAt: 0,
queryKey: ['getProducts', userId],
queryFn: getFareProducts,
cacheTime: ONE_HOUR_MS,
staleTime: ONE_HOUR_MS,
enabled: authStatus === 'authenticated',
});
};

0 comments on commit 4547ef6

Please sign in to comment.