Commit f4faf945 by Syed Abdul Rahman

seat booking functionality completed

parent 479e16af
{
"users": [
{
"id": "8329",
"id": "594f",
"email": "syedabdul.rahman@krds.com",
"selectionCount": "3"
},
{
"id": "3450",
"email": "abdul@gmail.com",
"selectionCount": "4"
},
{
"id": "06b5",
"email": "lucy@gmail.com",
"selectionCount": "3"
},
{
"id": "d17b",
"email": "test@gmail.com",
"selectionCount": "3"
},
{
"id": "84ca",
"email": "anas@krds.fr",
"selectionCount": "22"
}
],
"selectedSeats": [
{
"id": "8329",
"userid": "8329",
"id": "594f",
"userid": "594f",
"selected": [
{
"row": 8,
......@@ -37,81 +17,13 @@
},
{
"row": 8,
"seat": 3
},
{
"row": 7,
"seat": 1
}
]
},
{
"id": "3450",
"userid": "3450",
"selected": [
{
"row": 7,
"seat": 7
},
{
"row": 7,
"seat": 8
},
{
"row": 1,
"seat": 6
},
{
"row": 1,
"seat": 5
}
]
},
{
"id": "06b5",
"userid": "06b5",
"selected": [
{
"row": 8,
"seat": 5
},
{
"row": 8,
"seat": 4
},
{
"row": 8,
"seat": 6
}
]
},
{
"id": "d17b",
"userid": "d17b",
"selected": [
{
"row": 1,
"seat": 2
},
{
"row": 1,
"seat": 1
},
{
"row": 1,
"seat": 3
}
]
},
{
"id": "4d39",
"userid": "4d39",
"selected": [
{
"row": 2,
"seat": 5
}
]
}
]
}
\ No newline at end of file
......@@ -8,7 +8,6 @@ const BookingWrapper = ({
seatData,
currentSeats
}) => {
console.log(currentSeats, 'currentSeats in CHILD');
const aisleIndex = 4;
let currentUser = getItem('user');
const selectedSeatMap = new Map();
......
......@@ -29,6 +29,7 @@ const BookingPage = () => {
const [showSeatsConfirmationModal, setShowSeatsConfirmationModal] =
useState(false);
const [noOfSeats, setNoOfSeats] = useState();
const [buttonState, setButtonState] = useState(true);
useEffect(() => {
const fetchSelectedSeats = async () => {
......@@ -36,7 +37,6 @@ const BookingPage = () => {
const currentData = data?.find((e) => e.userid == userId);
setSelectedSeats(data);
setCurrentSeats(currentData?.selected);
console.log(data, 'currentSeats & selectedSeats', currentSeats.length);
};
const fetchSeatSelectionCount = async () => {
const data = await getSeatSelectionCountApi(userId);
......@@ -365,22 +365,37 @@ const BookingPage = () => {
const onSelectSeats = (rowId, columnId) => {
setCurrentSeats((prev) => {
const found = prev?.find((e) => e.row == rowId && e.seat == columnId);
const found = prev?.find((e) => e.row === rowId && e.seat === columnId);
let updatedSeats;
if (found) {
return currentSeats.filter(
(e) => !(e.row == rowId && e.seat == columnId)
updatedSeats = prev?.filter(
(e) => !(e.row === rowId && e.seat === columnId)
);
if (updatedSeats?.length === parseInt(noOfSeats)) {
setButtonState(false);
} else {
setButtonState(true);
}
} else {
if (currentSeats?.length < noOfSeats) {
let obj = {
row: rowId,
seat: columnId
};
return [...prev, obj];
if (prev?.length < noOfSeats) {
updatedSeats = [...prev, { row: rowId, seat: columnId }];
if (updatedSeats?.length === parseInt(noOfSeats)) {
setButtonState(false);
} else {
setButtonState(true);
}
} else {
return prev ? [...prev] : [];
updatedSeats = prev ? [...prev] : [];
// if (updatedSeats?.length === parseInt(noOfSeats)) {
// setButtonState(false);
// } else {
// setButtonState(true);
// }
}
}
return updatedSeats;
});
};
......@@ -430,7 +445,8 @@ const BookingPage = () => {
<Button
size={'lg'}
onClick={onSeatsConfirm}
disabled={currentSeats?.length == noOfSeats ? true : false}>
// disabled={currentSeats?.length == noOfSeats ? true : false}>
disabled={buttonState}>
Confirm
</Button>
</div>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment