Skip to content

Commit

Permalink
PassengersCounter previous selected value
Browse files Browse the repository at this point in the history
  • Loading branch information
hilat-autofleet committed Feb 25, 2024
1 parent d043f77 commit 8f5b004
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
11 changes: 9 additions & 2 deletions examples/client/Locomotion/src/Components/SelectModal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,15 @@ interface Item {

interface SelectModalProps {
data: Item[];
defaultValue?: any;
onSelect: (item: Item) => void;
onError: (error: boolean) => void;
}

const SelectModal = ({ data, onSelect, onError }: SelectModalProps) => {
const [selectedItem, setSelectedItem] = useState(null);
const SelectModal = ({
data, onSelect, onError, defaultValue,
}: SelectModalProps) => {
const [selectedItem, setSelectedItem] = useState<Item| null>(null);
const [error, setError] = useState(false);

useEffect(() => {
Expand Down Expand Up @@ -118,6 +121,7 @@ const SelectModal = ({ data, onSelect, onError }: SelectModalProps) => {
onSelect={(item, index) => {
setSelectedItem(item);
}}
defaultValue={defaultValue}
dropdownIconPosition="left"
dropdownOverlayColor="transparent"
buttonTextAfterSelection={(item, index) => item.value}
Expand All @@ -131,5 +135,8 @@ const SelectModal = ({ data, onSelect, onError }: SelectModalProps) => {
/>
);
};
SelectModal.defaultProps = {
defaultValue: null,
};

export default SelectModal;
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ interface RidePageContextInterface {
setSpCurrentLocation: () => void;
historyResults: any[];
serviceEstimations: any[];
ride: RideInterface;
ride: RideInterface | null;
updateRidePayload: (ride: any) => void;
chosenService: any;
defaultService: any;
Expand Down Expand Up @@ -159,7 +159,7 @@ interface RidePageContextInterface {
getRidePriceCalculation: (id: string | undefined, priceCalculationId?: string) => Promise<PriceCalculation | undefined>;
getRideTotalPriceWithCurrency: (rideId : string | undefined) => Promise<{ amount: number; currency: string; } | undefined>;
getRidesByParams: (params: any) => Promise<RideInterface[]>;
numberOfPassengers: number,
numberOfPassengers: number | null,
setNumberOfPassengers: (num: number) => void,
setLastAcknowledgedRideCompletionTimestampToNow: () => void
loadFutureBookingDays: () => void;
Expand Down Expand Up @@ -227,6 +227,8 @@ export const RidePageContext = createContext<RidePageContextInterface>({
futureBookingDays: 0,
businessAccountId: null,
updateBusinessAccountId: (newBusinessAccountId: string | null) => undefined,
addNewEmptyRequestSp: () => undefined,
removeRequestSp: (index: number) => undefined,
});

const HISTORY_RECORDS_NUM = 10;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import React, { useState, useEffect } from 'react';
import SelectModal from '../../../../../../Components/SelectModal';


const PassengersCounter = ({ service, onSelect, onError = () => null }) => {
const PassengersCounter = ({
service, onSelect, onError = () => null, value,
}) => {
useEffect(() => {
if (service?.availableSeats) {
const array = [];
Expand All @@ -25,6 +27,7 @@ const PassengersCounter = ({ service, onSelect, onError = () => null }) => {
data={passengersOptions}
onSelect={onItemSelect}
onError={onError}
defaultValue={value}
/>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const RideButtons = ({
futureBookingDays,
businessAccountId,
serviceEstimations,
numberOfPassengers,
} = useContext(RidePageContext);


Expand Down Expand Up @@ -342,6 +343,7 @@ const RideButtons = ({
service={chosenService}
onSelect={setNumberOfPassengers}
onError={setPassengersCounterError}
value={numberOfPassengers}
/>
) : null}

Expand Down

0 comments on commit 8f5b004

Please sign in to comment.