Commit f4faf945 by Syed Abdul Rahman

seat booking functionality completed

parent 479e16af
{ {
"users": [ "users": [
{ {
"id": "8329", "id": "594f",
"email": "syedabdul.rahman@krds.com", "email": "syedabdul.rahman@krds.com",
"selectionCount": "3" "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": [ "selectedSeats": [
{ {
"id": "8329", "id": "594f",
"userid": "8329", "userid": "594f",
"selected": [ "selected": [
{ {
"row": 8, "row": 8,
...@@ -37,81 +17,13 @@ ...@@ -37,81 +17,13 @@
}, },
{ {
"row": 8, "row": 8,
"seat": 3
},
{
"row": 7,
"seat": 1 "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, "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 "seat": 3
} }
] ]
},
{
"id": "4d39",
"userid": "4d39",
"selected": [
{
"row": 2,
"seat": 5
}
]
} }
] ]
} }
\ No newline at end of file
...@@ -8,7 +8,6 @@ const BookingWrapper = ({ ...@@ -8,7 +8,6 @@ const BookingWrapper = ({
seatData, seatData,
currentSeats currentSeats
}) => { }) => {
console.log(currentSeats, 'currentSeats in CHILD');
const aisleIndex = 4; const aisleIndex = 4;
let currentUser = getItem('user'); let currentUser = getItem('user');
const selectedSeatMap = new Map(); const selectedSeatMap = new Map();
......
...@@ -29,6 +29,7 @@ const BookingPage = () => { ...@@ -29,6 +29,7 @@ const BookingPage = () => {
const [showSeatsConfirmationModal, setShowSeatsConfirmationModal] = const [showSeatsConfirmationModal, setShowSeatsConfirmationModal] =
useState(false); useState(false);
const [noOfSeats, setNoOfSeats] = useState(); const [noOfSeats, setNoOfSeats] = useState();
const [buttonState, setButtonState] = useState(true);
useEffect(() => { useEffect(() => {
const fetchSelectedSeats = async () => { const fetchSelectedSeats = async () => {
...@@ -36,7 +37,6 @@ const BookingPage = () => { ...@@ -36,7 +37,6 @@ const BookingPage = () => {
const currentData = data?.find((e) => e.userid == userId); const currentData = data?.find((e) => e.userid == userId);
setSelectedSeats(data); setSelectedSeats(data);
setCurrentSeats(currentData?.selected); setCurrentSeats(currentData?.selected);
console.log(data, 'currentSeats & selectedSeats', currentSeats.length);
}; };
const fetchSeatSelectionCount = async () => { const fetchSeatSelectionCount = async () => {
const data = await getSeatSelectionCountApi(userId); const data = await getSeatSelectionCountApi(userId);
...@@ -365,22 +365,37 @@ const BookingPage = () => { ...@@ -365,22 +365,37 @@ const BookingPage = () => {
const onSelectSeats = (rowId, columnId) => { const onSelectSeats = (rowId, columnId) => {
setCurrentSeats((prev) => { 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) { if (found) {
return currentSeats.filter( updatedSeats = prev?.filter(
(e) => !(e.row == rowId && e.seat == columnId) (e) => !(e.row === rowId && e.seat === columnId)
); );
if (updatedSeats?.length === parseInt(noOfSeats)) {
setButtonState(false);
} else {
setButtonState(true);
}
} else { } else {
if (currentSeats?.length < noOfSeats) { if (prev?.length < noOfSeats) {
let obj = { updatedSeats = [...prev, { row: rowId, seat: columnId }];
row: rowId, if (updatedSeats?.length === parseInt(noOfSeats)) {
seat: columnId setButtonState(false);
}; } else {
return [...prev, obj]; setButtonState(true);
}
} else { } 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 = () => { ...@@ -430,7 +445,8 @@ const BookingPage = () => {
<Button <Button
size={'lg'} size={'lg'}
onClick={onSeatsConfirm} onClick={onSeatsConfirm}
disabled={currentSeats?.length == noOfSeats ? true : false}> // disabled={currentSeats?.length == noOfSeats ? true : false}>
disabled={buttonState}>
Confirm Confirm
</Button> </Button>
</div> </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