Skip to content

Commit

Permalink
Version 3.3.12 (#796)
Browse files Browse the repository at this point in the history
* hide price (#791)

* Update cardDetailUtils.ts

* Revert "Update cardDetailUtils.ts"

This reverts commit d16d766.

* hide price

* move to settings context

* remove loadShowPrice from context

* Revert "remove loadShowPrice from context"

This reverts commit d94850e.

* id

* testID

---------

Co-authored-by: Omer Gery <68545675+OmerGery@users.noreply.github.com>
Co-authored-by: EliFrankel <elifrankelilj@gmail.com>

* change default to false (#795)

* add stripe key to debug mode

* change default to false

---------

Co-authored-by: Omer Gery <68545675+OmerGery@users.noreply.github.com>

---------

Co-authored-by: Omer Gery <68545675+OmerGery@users.noreply.github.com>
Co-authored-by: EliFrankel <elifrankelilj@gmail.com>
  • Loading branch information
3 people authored Dec 18, 2023
1 parent a842539 commit 83a366b
Show file tree
Hide file tree
Showing 14 changed files with 105 additions and 31 deletions.
14 changes: 11 additions & 3 deletions examples/client/Locomotion/src/Components/PriceBreakdown/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
PriceText,
} from './styled';
import { COUPON_TYPE } from '../../lib/commonTypes';
import settingsContext from '../../context/settings';

const NoBreakdownComponent = ({
didRequestFail,
Expand Down Expand Up @@ -59,9 +60,11 @@ const PriceBreakdown = ({
didRequestFail,
retryGetPriceBreakdown,
}: PriceBreakdownProps) => {
const { showPrice, loadShowPrice } = settingsContext.useContainer();
const isDebuggingEnabled = typeof atob !== 'undefined';
const [priceCalculationItems, setPriceCalculationItems] = useState<any[]>();
const [total, setTotal] = useState<null | string>(null);

const getPriceWithCurrency = (amount: number) => `${getCurrencySymbol(priceCalculation.currency)}${amount.toFixed(2)}`;

const calculationTypeToUnit: any = {
Expand All @@ -83,7 +86,8 @@ const PriceBreakdown = ({
totalPrice += item.price;
let name;
if (item.pricingRule) {
const calculationTypeToUnitInstance = calculationTypeToUnit[item.pricingRule.calculationType];
const calculationTypeToUnitInstance = calculationTypeToUnit[
item.pricingRule.calculationType];
name = `${i18n.t('ridePriceBreakdown.priceItem', {
name: item.pricingRule.name,
})} ${calculationTypeToUnitInstance ? calculationTypeToUnitInstance(
Expand Down Expand Up @@ -117,6 +121,10 @@ const PriceBreakdown = ({
}
}, [priceCalculation]);

useEffect(() => {
loadShowPrice();
}, []);

return (
<>
<InnerContainer>
Expand All @@ -142,8 +150,8 @@ const PriceBreakdown = ({
<InnerContainer>
<Row>
<ItemText>{`${i18n.t('ridePriceBreakdown.total')}`}</ItemText>
{priceCalculationItems ? (
<PriceText>{total}</PriceText>
{priceCalculationItems && showPrice ? (
<PriceText testID="priceCalculation">{total}</PriceText>
) : (
<SkeletonContent
containerStyle={{}}
Expand Down
16 changes: 12 additions & 4 deletions examples/client/Locomotion/src/Components/RideCard/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ import StopPointsVerticalView from '../StopPointsVerticalView';
import { getFormattedPrice, isPriceEstimated, convertTimezoneByLocation } from '../../context/newRideContext/utils';
import cashIcon from '../../assets/cash.svg';
import { PAYMENT_METHODS } from '../../pages/Payments/consts';
import paymentContext from '../../context/payments';
import PaymentContext from '../../context/payments';
import SettingsContext from '../../context/settings';

interface CardComponentProps {
paymentMethod: {
Expand All @@ -26,7 +27,7 @@ interface CardComponentProps {
const CardComponent = ({ paymentMethod }: CardComponentProps) => {
const isCash = PAYMENT_METHODS.CASH === paymentMethod.id;
const isOffline = PAYMENT_METHODS.OFFLINE === paymentMethod.id;
const { offlinePaymentText, loadOfflinePaymentText } = paymentContext.useContainer();
const { offlinePaymentText, loadOfflinePaymentText } = PaymentContext.useContainer();

useEffect(() => {
loadOfflinePaymentText();
Expand All @@ -51,7 +52,7 @@ const CardComponent = ({ paymentMethod }: CardComponentProps) => {
};
return (
<TextRowWithIcon
text={getText()}
text={getText() || ''}
Image={() => !isCash && !isOffline && <PaymentIcon type={paymentMethod.brand} />}
icon={getIcon()}
style={{ marginTop: 10, marginBottom: 10 }}
Expand Down Expand Up @@ -79,6 +80,7 @@ const RideCard = ({
const {
getRidePriceCalculation,
} = useContext(RidePageContext);
const { showPrice, loadShowPrice } = SettingsContext.useContainer();

const addPriceCalculation = async () => {
const price = await getRidePriceCalculation(ride.id, ride.priceCalculationId);
Expand All @@ -91,6 +93,10 @@ const RideCard = ({
}
}, [ride]);

useEffect(() => {
loadShowPrice();
}, []);

const formatScheludedTo = async (time: any) => {
try {
const { stopPoints = [] } = ride;
Expand Down Expand Up @@ -144,7 +150,8 @@ const RideCard = ({
{serviceName}
</ServiceType>
</TopTextsContainer>
<TopPriceContainer>
{ showPrice && (
<TopPriceContainer testID="priceContainer">
<RideDate>
{getFormattedPrice(ride.priceCurrency, ride.priceAmount)}
</RideDate>
Expand All @@ -157,6 +164,7 @@ const RideCard = ({
: null}
{displayTimezone ? <ServiceType /> : null}
</TopPriceContainer>
)}
</DateContainer>

<StopPointsVerticalView ride={ride} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
PaymentRow, RidePriceDetails, PriceText, ViewDetails, CardRowContainer,
} from './styled';
import { PaymentMethodInterface } from '../../context/payments/interface';
import PaymentContext from '../../context/payments';
import SettingsContext from '../../context/settings';
import * as navigationService from '../../services/navigation';
import Button from '../Button';

Expand All @@ -33,6 +33,8 @@ const RidePaymentDetails = ({
getRidePriceCalculation,
} = useContext(RidePageContext);

const { showPrice, loadShowPrice } = SettingsContext.useContainer();

const updatePriceCalculation = async () => {
const calculation = await getRidePriceCalculation(rideId);
setPriceCalculation(calculation);
Expand All @@ -43,6 +45,7 @@ const RidePaymentDetails = ({

useEffect(() => {
updatePriceCalculation();
loadShowPrice();
}, []);

return (paymentMethod ? (
Expand All @@ -54,16 +57,19 @@ const RidePaymentDetails = ({
</CardRowContainer>
<RidePriceDetails>

{!rideHistory ? (totalAmount === 0
{!rideHistory && (totalAmount === 0
? <PriceText>{`${i18n.t('rideDetails.noCharge')}`}</PriceText>
: (
<PriceText>
: (showPrice
&& (
<PriceText testID="priceText">
{getFormattedPrice(priceCalculation?.currency,
totalAmount)}
</PriceText>
)
)
) : null}
)}

{showPrice && (
<Button
testID="viewRidePaymentDetails"
noBackground
Expand All @@ -78,6 +84,7 @@ const RidePaymentDetails = ({
</ViewDetails>
) : undefined}
</Button>
)}
</RidePriceDetails>
</PaymentRow>
</>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ const RidePageContextProvider = ({ children }: {
const getRouteName = () => navigationService?.getNavigator()?.getCurrentRoute().name;
const [numberOfPassengers, setNumberOfPassengers] = useState<number | null>(null);
const [addressSearchLabel, setAddressSearchLabel] = useState<string | null>(null);
const [futureBookingDays, setfutureBookingDays] = useState(0);
const [futureBookingDays, setFutureBookingDays] = useState(0);


const intervalRef = useRef<any>();
Expand Down Expand Up @@ -471,7 +471,7 @@ const RidePageContextProvider = ({ children }: {

const loadFutureBookingDays = async () => {
const maxDaysFromSettings = await getSettingByKey(SETTINGS_KEYS.MAX_DAYS_FOR_FUTURE_RIDE);
setfutureBookingDays(maxDaysFromSettings);
setFutureBookingDays(maxDaysFromSettings);
};

const getLastCompletedRide = async () => {
Expand Down
6 changes: 3 additions & 3 deletions examples/client/Locomotion/src/context/onboarding/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, {
createContext, useContext, useState,
} from 'react';
import { initStripe } from '@stripe/stripe-react-native';
import Config from 'react-native-config';
import AppSettings from '../../services/app-settings';
import settings from '../settings';
import SETTINGS_KEYS from '../settings/keys';
import * as navigationService from '../../services/navigation';
Expand Down Expand Up @@ -109,9 +109,9 @@ const OnboardingContextProvider = ({ children }: { children: any }) => {
getOrFetchClientPaymentAccount(),
loadCustomer(),
]);

const publishableKey = await AppSettings.getStripeKey();
initStripe({
publishableKey: Config.STRIPE_PUBLISHER_KEY,
publishableKey,
merchantIdentifier: 'merchant.identifier',
stripeAccountId: paymentAccount.stripeId,
});
Expand Down
8 changes: 8 additions & 0 deletions examples/client/Locomotion/src/context/settings/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const useSettings = () => {
const [workingHours, setWorkingHours] = useState({});
const [measureSystem, setMeasureSystem] = useState('metric');
const [appSettingsState, setAppSettingsState] = useState({});
const [showPrice, setShowPrice] = useState(false);


const getSettingByKey = async (key) => {
Expand Down Expand Up @@ -120,6 +121,11 @@ const useSettings = () => {
setAppSettingsStates(appSettingsState);
}, [appSettingsState]);

const loadShowPrice = async () => {
const hidePrice = await getSettingByKey(settingsKeys.HIDE_PRICE);
setShowPrice(!hidePrice);
};

return {
settingsList,
getWorkingHours,
Expand All @@ -130,6 +136,8 @@ const useSettings = () => {
getAppSettings,
getMeasureSystem,
measureSystem,
loadShowPrice,
showPrice,
};
};
export default createContainer(useSettings);
1 change: 1 addition & 0 deletions examples/client/Locomotion/src/context/settings/keys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ export default {
DISABLE_CAPTCHA_UI: 'riderApp.disableCaptchaUi',
MAX_DAYS_FOR_FUTURE_RIDE: 'riderApp.daysForFutureRideBooking',
OFFLINE_PAYMENT_TEXT: 'riderApp.offlinePaymentText',
HIDE_PRICE: 'riderApp.hidePrice',
};
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import moment from 'moment';
import React, { useContext, useState } from 'react';
import React, { useContext, useEffect, useState } from 'react';
import propsTypes from 'prop-types';
import { View } from 'react-native';
import SvgIcon from '../../../../../../Components/SvgIcon';
Expand All @@ -20,6 +20,7 @@ import {
import Tag from '../../../../../../Components/Tag';
import { RidePageContext } from '../../../../../../context/newRideContext';
import FareBreakdownPopup from '../../../../../../popups/FareBreakdownPopup';
import SettingsContext from '../../../../../../context/settings';

const FARE_POPUP = 'farePopup';

Expand All @@ -28,6 +29,7 @@ const ServiceCard = ({ service, withBorder }) => {
const {
setChosenService, chosenService, serviceEstimations, ride,
} = useContext(RidePageContext);
const { showPrice, loadShowPrice } = SettingsContext.useContainer();
const [popup, setPopup] = useState(null);
const isFutureRide = ride.scheduledTo;
const unavailable = !((ride.scheduledTo && service.priceCalculationId)
Expand Down Expand Up @@ -98,9 +100,13 @@ const ServiceCard = ({ service, withBorder }) => {
return i18n.t('rideDetails.unavailable');
}

return getFormattedPrice(service.currency, service.price);
return showPrice ? getFormattedPrice(service.currency, service.price) : null;
};

useEffect(() => {
loadShowPrice();
}, []);

return (
<>
<CardContainer
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useContext, useEffect, useState } from 'react';
import { initStripe } from '@stripe/stripe-react-native';
import Config from 'react-native-config';
import moment from 'moment';
import { Platform } from 'react-native';
import AppSettings from '../../services/app-settings';
import { APP_ROUTES, MAIN_ROUTES } from '../routes';
import { logout } from '../../services/logout';
import { getUserDetails } from '../../context/user/api';
Expand Down Expand Up @@ -69,9 +69,9 @@ const AuthLoadingScreen = () => {
}),
]);


const publishableKey = await AppSettings.getStripeKey();
initStripe({
publishableKey: Config.STRIPE_PUBLISHER_KEY,
publishableKey,
merchantIdentifier: 'merchant.identifier',
stripeAccountId: paymentAccount.stripeId,
});
Expand Down
12 changes: 11 additions & 1 deletion examples/client/Locomotion/src/pages/DevPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { InputContainer, Label } from './styles';
const DevSettingPage = () => {
const [operationId, setOperationId] = useState(Config.OPERATION_ID);
const [serverUrl, setServerUrl] = useState(Config.SERVER_HOST);
const [stripeKey, setStripeKey] = useState(Config.STRIPE_PUBLISHER_KEY);
return (
<PageContainer>
<PageHeader
Expand Down Expand Up @@ -41,10 +42,19 @@ const DevSettingPage = () => {
}}
value={serverUrl}
/>
<Label>Stripe Key</Label>
<TextInput
testID="stripeKey"
autoFocus
onChangeText={(newStripeKey: string) => {
setStripeKey(newStripeKey);
}}
value={stripeKey}
/>
<NavButton
testID="saveButton"
onPress={() => {
AppSettings.setSettings({ serverUrl, operationId });
AppSettings.setSettings({ serverUrl, operationId, stripeKey });
navigationService.goBack();
}}
>
Expand Down
7 changes: 6 additions & 1 deletion examples/client/Locomotion/src/pages/PostRide/Tips/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import BottomSheet from '../../../Components/BottomSheet';
import BottomSheetContextProvider, { BottomSheetContext, SNAP_POINT_STATES } from '../../../context/bottomSheetContext';
import CustomTip from './CustomTip';
import { getFormattedPrice, getCurrencySymbol } from '../../../context/newRideContext/utils';
import SettingsContext from '../../../context/settings';

const TipSectionContainer = styled.View`
width: 100%;
Expand Down Expand Up @@ -106,6 +107,7 @@ const Tips = ({
}) => {
const [selectedTip, setSelectedTip] = useState(null);
const [customTip, setCustomTip] = useState(null);
const { showPrice, loadShowPrice } = SettingsContext.useContainer();

const isPercentage = ridePrice >= tipSettings.percentageThreshold;
const buttons = isPercentage ? tipSettings.percentage : tipSettings.fixedPrice;
Expand All @@ -121,6 +123,7 @@ const Tips = ({

useEffect(() => {
setSnapPointsState(SNAP_POINT_STATES.CUSTOM_TIP);
loadShowPrice();
}, []);


Expand Down Expand Up @@ -173,9 +176,11 @@ const Tips = ({
<Title testID="tipPageTitle">
{`${i18n.t('postRide.tip.title')} ${driver.firstName}`}
</Title>
<SubTitle>
{showPrice && (
<SubTitle testID="postRideTip">
{`${i18n.t('postRide.tip.subTitle')} ${serviceDisplayPrice}`}
</SubTitle>
)}
</Column>
<ThumbnailContainer>
<StyledThumbnail>
Expand Down
Loading

0 comments on commit 83a366b

Please sign in to comment.