Skip to content

Commit

Permalink
Update index.tsx
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerGery committed Jan 15, 2024
1 parent b2d1db9 commit c606538
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions examples/client/Locomotion/src/context/newRideContext/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,10 @@ const RidePageContextProvider = ({ children }: {
const stopRequestInterval = () => {
clearInterval(intervalRef.current);
};

const saveLastRide = async (rideId: string, rideBusinessAccountId: string) => Promise.all([
StorageService.save({ lastRideId: rideId }),
const saveLastRide = async (rideId: string) => {
await StorageService.save({ lastRideId: rideId });
};
const saveOrderedRidePaymentMethod = async (rideBusinessAccountId: string | null) => Promise.all([
StorageService.save({ lastBusinessAccountId: rideBusinessAccountId || PAYMENT_MODES.PERSONAL }),
StorageService.save({ orderedRide: true }),
]);
Expand Down Expand Up @@ -332,13 +333,13 @@ const RidePageContextProvider = ({ children }: {
cleanRequestStopPoints();
setRide(newRide);
changeBsPage(BS_PAGES.ACTIVE_RIDE);
saveLastRide(newRide.id, newRide.businessAccountId);
saveLastRide(newRide.id);
},
[RIDE_STATES.ACTIVE]: (activeRide: any) => {
cleanRequestStopPoints();
setRide(activeRide);
changeBsPage(BS_PAGES.ACTIVE_RIDE);
saveLastRide(activeRide.id, activeRide.businessAccountId);
saveLastRide(activeRide.id);
},
[RIDE_STATES.CANCELED]: (canceledRide: any) => {
if (canceledRide.canceledBy !== user?.id) {
Expand Down Expand Up @@ -1144,7 +1145,10 @@ const RidePageContextProvider = ({ children }: {
};


const afRide = await rideApi.createRide(rideToCreate);
const [afRide] = await Promise.all([
rideApi.createRide(rideToCreate),
saveOrderedRidePaymentMethod(businessAccountId),
]);
if (afRide.state === RIDE_STATES.REJECTED) {
throw new Error(RIDE_FAILED_REASONS.BUSY);
}
Expand All @@ -1157,8 +1161,6 @@ const RidePageContextProvider = ({ children }: {
setRide(formattedRide);
}
} catch (e: any) {
console.log(e);
console.log(e.message);
const key = e.response?.data?.errors[0] || e.message;
Mixpanel.setEvent('Ride failed', { status: e?.response?.status, reason: key });
if (FAILED_TO_CREATE_RIDE_ACTIONS[key]) {
Expand Down

0 comments on commit c606538

Please sign in to comment.