Skip to content

Commit

Permalink
Merge pull request #788 from Autofleet/AUT-16841-max-future-ride
Browse files Browse the repository at this point in the history
add default max days
  • Loading branch information
avivbarniv authored Oct 19, 2023
2 parents 7e4df3f + b73e276 commit fbfb0a2
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 3 deletions.
7 changes: 6 additions & 1 deletion examples/client/Locomotion/src/Components/BsPages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ export const ConfirmPickupTime = (props: any) => {
chosenService,
defaultService,
setChosenService,
loadFutureBookingDays,
futureBookingDays,
} = useContext(MewRidePageContext);
const {
changeBsPage,
Expand All @@ -300,9 +302,12 @@ export const ConfirmPickupTime = (props: any) => {
const minutes = await getSettingByKey(SETTINGS_KEYS.MIN_MINUTES_BEFORE_FUTURE_RIDE);
setMinMinutesBeforeFutureRide(minutes);
};

useEffect(() => {
checkMinutesBeforeFutureRideSetting();
loadFutureBookingDays();
}, []);

useEffect(() => {
setTempSelectedDate(startDate);
}, [minMinutesBeforeFutureRide]);
Expand Down Expand Up @@ -361,7 +366,7 @@ export const ConfirmPickupTime = (props: any) => {
textColor="black"
isVisible={isDatePickerOpen}
date={tempSelectedDate}
maximumDate={getFutureRideMaxDate()}
maximumDate={getFutureRideMaxDate(futureBookingDays)}
minimumDate={getFutureRideMinDate((minMinutesBeforeFutureRide || 0))}
mode="datetime"
title={renderDatePickerTitle()}
Expand Down
13 changes: 13 additions & 0 deletions examples/client/Locomotion/src/context/newRideContext/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ interface RidePageContextInterface {
numberOfPassengers: number,
setNumberOfPassengers: (num: number) => void,
setLastAcknowledgedRideCompletionTimestampToNow: () => void
loadFutureBookingDays: () => void;
futureBookingDays: number;
}

export const RidePageContext = createContext<RidePageContextInterface>({
Expand Down Expand Up @@ -215,6 +217,8 @@ export const RidePageContext = createContext<RidePageContextInterface>({
numberOfPassengers: null,
setNumberOfPassengers: () => undefined,
setLastAcknowledgedRideCompletionTimestampToNow: () => undefined,
loadFutureBookingDays: () => undefined,
futureBookingDays: 0,
});

const HISTORY_RECORDS_NUM = 10;
Expand Down Expand Up @@ -253,6 +257,8 @@ 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 intervalRef = useRef<any>();

Expand Down Expand Up @@ -463,6 +469,11 @@ const RidePageContextProvider = ({ children }: {

const getRidesByParams = async (params: any) => rideApi.fetchRides(params);

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

const getLastCompletedRide = async () => {
let lastTimestamp = await StorageService.get('lastCompletedRideTimestamp');
if (!lastTimestamp) {
Expand Down Expand Up @@ -1344,6 +1355,8 @@ const RidePageContextProvider = ({ children }: {
formatStationsList,
clearRequestSp,
setLastAcknowledgedRideCompletionTimestampToNow,
loadFutureBookingDays,
futureBookingDays,
}}
>
{children}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const FEEDBACK_TYPES = {
export const RIDER_APP_SOURCE = 'RIDER_APP';

export const getFutureRideMinDate = (minutesBefore: number) => moment().add(minutesBefore, 'minutes').toDate();
export const getFutureRideMaxDate = () => moment().add(7, 'days').toDate();
export const getFutureRideMaxDate = (daysAfter: number) => moment().add(daysAfter, 'days').toDate();

export const TAG_OPTIONS = {
FASTEST: i18n.t('services.tags.fastest'),
Expand Down
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 @@ -16,5 +16,6 @@ export default {
MEASURE_SYSTEM: 'riderApp.measureSystem',
MULTI_SP: 'riderApp.showMultiStopPoint',
DISABLE_CAPTCHA_UI: 'riderApp.disableCaptchaUi',
MAX_DAYS_FOR_FUTURE_RIDE: 'riderApp.daysForFutureRideBooking',
OFFLINE_PAYMENT_TEXT: 'riderApp.offlinePaymentText',
};
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ const RideButtons = ({
unconfirmedPickupTime,
setNumberOfPassengers,
defaultService,
loadFutureBookingDays,
futureBookingDays,
} = useContext(RidePageContext);


Expand All @@ -81,6 +83,7 @@ const RideButtons = ({
const [passengersCounterError, setPassengersCounterError] = useState(false);
const firstDate = () => moment(ride?.scheduledTo || undefined).add(ride?.scheduledTo ? 0 : (minMinutesBeforeFutureRide || 0) + 1, 'minutes').toDate();
const [tempSelectedDate, setTempSelectedDate] = useState(firstDate());

const paymentMethodNotAllowedOnService = chosenService && ride?.paymentMethodId
&& !chosenService.allowedPaymentMethods.includes(getPaymentMethod(ride.paymentMethodId));

Expand All @@ -103,6 +106,7 @@ const RideButtons = ({
useEffect(() => {
checkFutureRidesSetting();
checkMinutesBeforeFutureRideSetting();
loadFutureBookingDays();
}, []);

const [animatedOpacity] = useState(new Animated.Value(0));
Expand Down Expand Up @@ -172,7 +176,7 @@ const RideButtons = ({
textColor="black"
isVisible={isDatePickerOpen}
date={tempSelectedDate}
maximumDate={getFutureRideMaxDate()}
maximumDate={getFutureRideMaxDate(futureBookingDays)}
minimumDate={getFutureRideMinDate((minMinutesBeforeFutureRide || 0))}
mode="datetime"
title={renderDatePickerTitle()}
Expand Down

0 comments on commit fbfb0a2

Please sign in to comment.