From 7cbc51debc18b733738d05aef45e58f659e7cd21 Mon Sep 17 00:00:00 2001 From: Omer Gery <68545675+OmerGery@users.noreply.github.com> Date: Sun, 21 Jan 2024 13:16:30 +0200 Subject: [PATCH] fix for delete from BA --- .../Locomotion/src/context/newRideContext/index.tsx | 11 +++++++++-- .../Locomotion/src/context/newRideContext/utils.ts | 1 + .../src/popups/ChoosePaymentMethod/index.tsx | 8 ++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/examples/client/Locomotion/src/context/newRideContext/index.tsx b/examples/client/Locomotion/src/context/newRideContext/index.tsx index 1c7c2607b..b2dd5831e 100644 --- a/examples/client/Locomotion/src/context/newRideContext/index.tsx +++ b/examples/client/Locomotion/src/context/newRideContext/index.tsx @@ -388,6 +388,10 @@ const RidePageContextProvider = ({ children }: { const FAILED_ESTIMATIONS_ACTIONS = { [ESTIMATION_ERRORS['RIDE_VALIDATION:SOME_STOP_POINTS_ARE_OUT_OF_TERRITORY']]: () => changeBsPage(BS_PAGES.NOT_IN_TERRITORY), [ESTIMATION_ERRORS.FIRST_STOP_POINT_NOT_IN_TERRITORY]: () => changeBsPage(BS_PAGES.PICKUP_NOT_IN_TERRITORY), + [ESTIMATION_ERRORS.CLIENT_NOT_IN_BUSINESS_ACCOUNT]: async () => { + await StorageService.delete('lastBusinessAccountId'); + setBusinessAccountId(null); + }, }; @@ -444,8 +448,11 @@ const RidePageContextProvider = ({ children }: { } catch (e: any) { Mixpanel.setEvent('service estimations failed', { status: e?.response?.status }); if (throwError) { - if (FAILED_ESTIMATIONS_ACTIONS[e?.response?.data?.errors[0]]) { - FAILED_ESTIMATIONS_ACTIONS[e?.response?.data?.errors[0]](); + const error = e?.response?.data?.errors[0]; + const errorHandleFunction = FAILED_ESTIMATIONS_ACTIONS[error]; + if (errorHandleFunction) { + Mixpanel.setEvent('service estimations failed with error reason', { error }); + await errorHandleFunction(); } else { cleanRideState(); setRidePopup(RIDE_POPUPS.FAILED_SERVICE_REQUEST); diff --git a/examples/client/Locomotion/src/context/newRideContext/utils.ts b/examples/client/Locomotion/src/context/newRideContext/utils.ts index db677a66a..521da5d8d 100644 --- a/examples/client/Locomotion/src/context/newRideContext/utils.ts +++ b/examples/client/Locomotion/src/context/newRideContext/utils.ts @@ -7,6 +7,7 @@ import { getLocationTimezone } from './api'; export const ESTIMATION_ERRORS = { 'RIDE_VALIDATION:SOME_STOP_POINTS_ARE_OUT_OF_TERRITORY': 'RIDE_VALIDATION:SOME_STOP_POINTS_ARE_OUT_OF_TERRITORY', FIRST_STOP_POINT_NOT_IN_TERRITORY: 'FIRST_STOP_POINT_NOT_IN_TERRITORY', + CLIENT_NOT_IN_BUSINESS_ACCOUNT: 'BUSINESS_ACCOUNT_CLIENT_NOT_FOUND', }; export const RIDE_FAILED_REASONS = { diff --git a/examples/client/Locomotion/src/popups/ChoosePaymentMethod/index.tsx b/examples/client/Locomotion/src/popups/ChoosePaymentMethod/index.tsx index e169b142a..d32c24210 100644 --- a/examples/client/Locomotion/src/popups/ChoosePaymentMethod/index.tsx +++ b/examples/client/Locomotion/src/popups/ChoosePaymentMethod/index.tsx @@ -60,6 +60,7 @@ const PaymentMethodPopup = ({ selectedBusinessAccountId ? PAYMENT_MODES.BUSINESS : PAYMENT_MODES.PERSONAL, ); const isBusinessMode = activePaymentTab === PAYMENT_MODES.BUSINESS; + const personalPaymentMethods = [ ...usePayments.paymentMethods, ...(showCash ? [cashPaymentMethod] : []), @@ -80,6 +81,13 @@ const PaymentMethodPopup = ({ usePayments.loadCustomer(); }, []); + useEffect(() => { + if (!usePayments.businessPaymentMethods?.length + && activePaymentTab === PAYMENT_MODES.BUSINESS) { + setActivePaymentTab(PAYMENT_MODES.PERSONAL); + } + }, [usePayments.businessPaymentMethods]); + useEffect(() => { const updateDefaultPaymentMethod = async () => { if (selected) {