Skip to content

Commit

Permalink
display BA name in ride history and active
Browse files Browse the repository at this point in the history
  • Loading branch information
OmerGery committed Jan 2, 2024
1 parent d447b80 commit 05e9076
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ const ActiveRideContent = () => {
ride={ride}
/>
<RidePaymentDetails
rideId={ride.id || ''}
ride={ride}
paymentMethod={ride.payment?.paymentMethod}
state={ride.state}
currency={ride.priceCurrency}
Expand Down
16 changes: 15 additions & 1 deletion examples/client/Locomotion/src/Components/CardRow/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { View, Text } from 'react-native';
import moment from 'moment';
import styled, { ThemeContext } from 'styled-components';
import { PaymentIcon } from 'react-native-payment-icons';
import { RideInterface, RidePageContext } from '../../context/newRideContext';
import { PAYMENT_METHODS, paymentMethodToIconMap } from '../../pages/Payments/consts';
import Button from '../Button';
import { capitalizeFirstLetter, getLastFourForamttedShort } from '../../pages/Payments/cardDetailUtils';
Expand Down Expand Up @@ -93,10 +94,22 @@ const style = {

const CardRow = (paymentMethod: any) => {
const { primaryColor } = useContext(ThemeContext);
const { offlinePaymentText, loadOfflinePaymentText } = paymentContext.useContainer();
const {
offlinePaymentText,
businessPaymentMethods,
loadOfflinePaymentText,
} = paymentContext.useContainer();
const { businessAccountId } = paymentMethod;
const [isCardExpired, setIsCardExpired] = useState(false);

const getPaymentMethodTitle = () => {
if (businessAccountId) {
const relevantBusinessAccount : any = businessPaymentMethods
.find((ba: any) => ba.id === businessAccountId);
if (relevantBusinessAccount) {
return relevantBusinessAccount.name;
}
}
if (isCashPaymentMethod(paymentMethod)) {
return i18n.t('payments.cash');
}
Expand Down Expand Up @@ -127,6 +140,7 @@ const CardRow = (paymentMethod: any) => {
if (isCard) {
return <PaymentIcon type={brand} />;
}
if (!paymentMethodToIconMap[id]) { return null; }
return (
<SvgIcon
fill={primaryColor}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getFormattedPrice } from '../../context/newRideContext/utils';
import CardRow from '../CardRow';
import CardsTitle from '../CardsTitle';
import i18n from '../../I18n';
import { PriceCalculation, RidePageContext } from '../../context/newRideContext';
import { PriceCalculation, RideInterface, RidePageContext } from '../../context/newRideContext';
import {
PaymentRow, RidePriceDetails, PriceText, ViewDetails, CardRowContainer,
} from './styled';
Expand All @@ -16,12 +16,12 @@ import * as navigationService from '../../services/navigation';
import Button from '../Button';

const RidePaymentDetails = ({
rideId,
ride,
paymentMethod,
rideHistory = false,
state,
} :{
rideId: string,
ride: RideInterface,
paymentMethod: PaymentMethodInterface,
rideHistory: boolean
currency: string,
Expand All @@ -36,7 +36,7 @@ const RidePaymentDetails = ({
const { showPrice, loadShowPrice } = SettingsContext.useContainer();

const updatePriceCalculation = async () => {
const calculation = await getRidePriceCalculation(rideId);
const calculation = await getRidePriceCalculation(ride?.id);
setPriceCalculation(calculation);
};

Expand All @@ -53,7 +53,7 @@ const RidePaymentDetails = ({
<CardsTitle noPaddingLeft title={i18n.t('ride.paymentMethod')} />
<PaymentRow>
<CardRowContainer>
<CardRow {...paymentMethod} />
<CardRow {...{ ...paymentMethod, businessAccountId: ride.businessAccountId }} />
</CardRowContainer>
<RidePriceDetails>

Expand All @@ -74,7 +74,7 @@ const RidePaymentDetails = ({
testID="viewRidePaymentDetails"
noBackground
onPress={() => navigationService.navigate(MAIN_ROUTES.RIDE_PRICE_BREAKDOWN,
{ rideId, rideHistory })}
{ rideId: ride.id, rideHistory })}
>
{state !== RIDE_STATES.CANCELED
|| (state === RIDE_STATES.CANCELED
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1107,7 +1107,7 @@ const RidePageContextProvider = ({ children }: {
type: sp.type,
...(i === 0 && { notes: ride.notes }),
})),
businessAccountId,
...(businessAccountId ? { businessAccountId } : {}),
};


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ const RideView = ({ ride }) => {
const [isPaymentSuccessPopupVisible, setIsPaymentSuccessPopupVisible] = useState(false);
const [outstandingBalance, setOutstandingBalance] = useState(null);
const isPaymentRejected = !isPaymentSettled && isRidePaymentRejected;

const usePayments = PaymentContext.useContainer();

const map = createRef();
Expand Down Expand Up @@ -260,7 +259,7 @@ const RideView = ({ ride }) => {
</StopPointsVerticalViewContainer>
<StopPointsVerticalViewContainer>
<RidePaymentDetails
rideId={ride.id}
ride={ride}
paymentMethod={ride?.payment?.paymentMethod}
state={ride.state}
currency={ride.priceCurrency}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,9 @@ const RidePriceBreakDown = () => {

const updateRideFromApi = async () => {
setLoading(true);
if (params.rideId || ride.id) {
// ts does not recognize the null check
// @ts-ignore
const result = await getRideFromApi(params.rideId || ride.id);
const rideId = params.rideId || ride.id;
if (rideId) {
const result = await getRideFromApi(rideId);
setLocalRide(result);
setPaymentMethod(result.payment.paymentMethod);

Expand Down Expand Up @@ -93,7 +92,11 @@ const RidePriceBreakDown = () => {
<InformationCard title={i18n.t('ridePriceBreakdown.paymentMethodTitle')}>
<View>
<CreditCardRowContainer>
<CardRow {...paymentMethod} />
<CardRow {...{
...paymentMethod,
businessAccountId: localRide?.businessAccountId,
}}
/>
</CreditCardRowContainer>
{
(priceCalculation && isPriceEstimated(priceCalculation.calculationBasis)
Expand Down

0 comments on commit 05e9076

Please sign in to comment.