Commit b0195a1b by Manivasagam S

code changes

parent ee405c45
...@@ -16,11 +16,13 @@ ...@@ -16,11 +16,13 @@
margin: 5rem auto; margin: 5rem auto;
text-align: center; text-align: center;
width: 100%; width: 100%;
max-width: 25rem; max-width: 15rem;
padding: 3rem; padding: 2rem;
background-color: #eff0ef; background-color: #eff0ef;
border-radius: 2rem; border-radius: 2rem;
animation: fadeIn 0.5s ease-in-out; animation: fadeIn 0.5s ease-in-out;
} }
.span { .span {
...@@ -151,3 +153,20 @@ ...@@ -151,3 +153,20 @@
font-size: 1rem; font-size: 1rem;
font-weight: 500; font-weight: 500;
} }
@media(min-width:320px){
.container{
padding: 2rem;
}
}
@media(min-width:425px){
.container{
max-width: 21rem;
}
}
@media (min-width:640px){
.container{
max-width: 23rem;
padding: 3rem;
}
}
\ No newline at end of file
...@@ -35,18 +35,14 @@ ...@@ -35,18 +35,14 @@
align-items: center; align-items: center;
margin:0 auto; margin:0 auto;
margin-top: 1rem; margin-top: 1rem;
gap: 2.188px; gap: 1rem;
width: 100%; width: 100%;
/*
flex-direction: column; */
} }
.legendItem { .legendItem {
display: inline-flex; display: inline-flex;
align-items: center; align-items: center;
gap: 3px; gap: 1px;
font-size: 0.875px; font-size: 0.875px;
color: white; color: white;
font-family: 'Segoe UI'; font-family: 'Segoe UI';
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
display: inline-block; display: inline-block;
background-color: transparent; background-color: transparent;
border: 0.5px solid rgba(164,175,255,255); border: 0.5px solid rgba(164,175,255,255);
width: 18px; width: 19px;
height: 18px; height: 19px;
border-radius: 5px; border-radius: 5px;
margin: 6px; margin: 6px;
cursor: pointer; cursor: pointer;
...@@ -12,9 +12,8 @@ ...@@ -12,9 +12,8 @@
box-shadow:2px 4px 8px rgba(0,0,0,0.2) ; box-shadow:2px 4px 8px rgba(0,0,0,0.2) ;
} }
.available:hover { .available:hover {
background-color: lab(52.35% 1.51 0); background-color: lab(71.81% 1.61 -0.02);
transform: scale(1.1); transform: scale(1.1);
} }
......
...@@ -30,6 +30,7 @@ export const SeatLayout = ({ ...@@ -30,6 +30,7 @@ export const SeatLayout = ({
currentReservedSeats = [], currentReservedSeats = [],
limit, limit,
onSelectionChange, onSelectionChange,
}) => { }) => {
const [localSelectedSeats, setLocalSelectedSeats] = useState(currentReservedSeats); const [localSelectedSeats, setLocalSelectedSeats] = useState(currentReservedSeats);
...@@ -58,17 +59,15 @@ export const SeatLayout = ({ ...@@ -58,17 +59,15 @@ export const SeatLayout = ({
const newlySelected = updated.filter( const newlySelected = updated.filter(
(s) => !currentReservedSeats.includes(s) (s) => !currentReservedSeats.includes(s)
); );
const unselectedMine = currentReservedSeats.filter( const unselectedMine = currentReservedSeats.filter(
(s) => !updated.includes(s) (s) => !updated.includes(s)
); );
const totalAllowed = limit + unselectedMine.length; const totalAllowed = limit + unselectedMine.length;
if (newlySelected.length < totalAllowed) { if (newlySelected.length < totalAllowed) {
return [...updated, seatNo]; return [...updated, seatNo];
} else { } else {
return updated; // reject selection return updated;
} }
} }
}); });
......
import { useEffect, useState } from "react"; import { useEffect, useState, useRef } from "react";
import { getAllUsers, updateUserReservedSeats } from "../../../Api/userApi"; import { getAllUsers, updateUserReservedSeats } from "../../../Api/userApi";
import { Button } from "../../Base/Buttons/Button"; import { Button } from "../../Base/Buttons/Button";
import { Legend } from "../Seat-legend/Legend"; import { Legend } from "../Seat-legend/Legend";
...@@ -11,7 +11,7 @@ import { Modal } from "../../Base/Modal/Modal"; ...@@ -11,7 +11,7 @@ import { Modal } from "../../Base/Modal/Modal";
import { SeatSelectForm } from "../../Form/SeatSelectForm/SeatSelectForm"; import { SeatSelectForm } from "../../Form/SeatSelectForm/SeatSelectForm";
import { Screen } from "../../Shared/Screen/Screen"; import { Screen } from "../../Shared/Screen/Screen";
import { AiOutlineLogout } from "react-icons/ai"; import { AiOutlineLogout } from "react-icons/ai";
import { useRef } from "react";
export const Selectseat = ({ onLogout }) => { export const Selectseat = ({ onLogout }) => {
const [selectedSeats, setSelectedSeats] = useState([]); const [selectedSeats, setSelectedSeats] = useState([]);
const [selectedData, setselectedData] = useState([]); const [selectedData, setselectedData] = useState([]);
...@@ -19,8 +19,8 @@ export const Selectseat = ({ onLogout }) => { ...@@ -19,8 +19,8 @@ export const Selectseat = ({ onLogout }) => {
const [seatCount, setSeatCount] = useState(1); const [seatCount, setSeatCount] = useState(1);
const [availableSeats, setAvailableSeats] = useState(0); const [availableSeats, setAvailableSeats] = useState(0);
const [showSelect, setShowSelect] = useState(true); const [showSelect, setShowSelect] = useState(true);
const hasWelcomed = useRef(false); const hasWelcomed = useRef(false);
useEffect(() => { useEffect(() => {
getAllUsers() getAllUsers()
...@@ -37,15 +37,13 @@ export const Selectseat = ({ onLogout }) => { ...@@ -37,15 +37,13 @@ export const Selectseat = ({ onLogout }) => {
setselectedData(userSeats); setselectedData(userSeats);
setreservedSeats(othersReserved); setreservedSeats(othersReserved);
setSeatCount(userSeats.length);
setShowSelect(true);
const available = totalSeats - allReserved.length; const available = totalSeats - allReserved.length;
setAvailableSeats(available); setAvailableSeats(available);
// if (userSeats.length > 0) { if (currentUser?.name && !hasWelcomed.current) {
// setSeatCount(userSeats.length);
// setShowSelect(false);
// }
if (currentUser?.name && !hasWelcomed.current) {
toast.success(`Welcome, ${currentUser.name}`); toast.success(`Welcome, ${currentUser.name}`);
hasWelcomed.current = true; hasWelcomed.current = true;
} }
...@@ -64,8 +62,10 @@ export const Selectseat = ({ onLogout }) => { ...@@ -64,8 +62,10 @@ export const Selectseat = ({ onLogout }) => {
return; return;
} }
if (selectedData.length === 0 && selectedSeats.length < seatCount) { const newlySelected = selectedSeats.filter(s => !selectedData.includes(s));
toast.info(`Please select ${seatCount} seat(s)`);
if (newlySelected.length < seatCount - selectedData.length) {
toast.error(`You must select exactly ${seatCount - selectedData.length} new seats`);
return; return;
} }
...@@ -83,12 +83,10 @@ export const Selectseat = ({ onLogout }) => { ...@@ -83,12 +83,10 @@ export const Selectseat = ({ onLogout }) => {
.flatMap(u => u.reservedSeats || []) .flatMap(u => u.reservedSeats || [])
.filter(seat => !currentUser.reservedSeats.includes(seat)); .filter(seat => !currentUser.reservedSeats.includes(seat));
const conflictSeats = selectedSeats.filter(seat => const conflictSeats = selectedSeats.filter(seat => latestReserved.includes(seat));
latestReserved.includes(seat)
);
if (conflictSeats.length > 0) { if (conflictSeats.length > 0) {
toast.error(`The following seat(s) were just taken: ${conflictSeats.join(", ")}`); toast.error(`The following seats were just taken: ${conflictSeats.join(", ")}`);
return; return;
} }
...@@ -97,32 +95,24 @@ export const Selectseat = ({ onLogout }) => { ...@@ -97,32 +95,24 @@ export const Selectseat = ({ onLogout }) => {
.then(res => { .then(res => {
if (res) { if (res) {
toast.success("Seats booked!"); toast.success("Seats booked!");
hasWelcomed.current=true; hasWelcomed.current = true;
const finalSeats = [...selectedData, ...selectedSeats]; localStorage.setItem("bookedSeats", JSON.stringify(selectedSeats));
localStorage.setItem("bookedSeats", JSON.stringify(selectedSeats));
console.log(selectedSeats);
setSelectedSeats([]); setSelectedSeats([]);
setTimeout(() => { setTimeout(() => window.location.replace("/success"), 1000);
window.location.replace("/success");
}, 1000);
} }
}) })
.catch(err => { .catch(err => {
console.error("Error confirming seats", err); console.error("Error confirming seats", err);
toast.error("Failed to confirm seats"); toast.error("Failed to confirm seats");
setTimeout(() => { setTimeout(() => window.location.replace("/error"), 1000);
window.location.replace("/error");
}, 1000);
}); });
}; };
const handleModal = () => { const handleModal = () => setShowSelect(false);
setShowSelect(false);
};
const seatOptions = Array.from({ length: availableSeats }).map((_, i) => ({ const seatOptions = Array.from({ length: availableSeats }).map((_, i) => ({
value: i + 1, value: selectedData.length + i + 1,
label: `${i + 1} ${i + 1 === 1 ? "seat" : "seats"}` label: `${selectedData.length + i + 0} seats`
})); }));
return ( return (
...@@ -139,7 +129,7 @@ export const Selectseat = ({ onLogout }) => { ...@@ -139,7 +129,7 @@ export const Selectseat = ({ onLogout }) => {
selectedSeats={selectedSeats} selectedSeats={selectedSeats}
reservedSeats={reservedSeats} reservedSeats={reservedSeats}
currentReservedSeats={selectedData} currentReservedSeats={selectedData}
limit={seatCount} limit={seatCount - selectedData.length}
onSelectionChange={setSelectedSeats} onSelectionChange={setSelectedSeats}
/> />
</div> </div>
...@@ -150,7 +140,7 @@ export const Selectseat = ({ onLogout }) => { ...@@ -150,7 +140,7 @@ export const Selectseat = ({ onLogout }) => {
label="Confirm" label="Confirm"
size="md" size="md"
onClick={confirmHandler} onClick={confirmHandler}
disabled={selectedData.length === 0 && selectedSeats.length !== seatCount} disabled={seatCount === 0 || selectedSeats.length < seatCount - selectedData.length}
/> />
</div> </div>
...@@ -161,7 +151,11 @@ export const Selectseat = ({ onLogout }) => { ...@@ -161,7 +151,11 @@ export const Selectseat = ({ onLogout }) => {
{showSelect && ( {showSelect && (
<Modal <Modal
title="Choose Number of Seats" title={
selectedData.length > 0
? `You have already booked ${selectedData.length} seat(s). Add more?`
: "Choose Number of Seats"
}
availableSeats={availableSeats} availableSeats={availableSeats}
seatCount={seatCount} seatCount={seatCount}
setSeatCount={setSeatCount} setSeatCount={setSeatCount}
......
...@@ -51,6 +51,7 @@ signUp:'sdfs' ...@@ -51,6 +51,7 @@ signUp:'sdfs'
width: 100%; width: 100%;
overflow-x: auto; overflow-x: auto;
overflow: visible !important; overflow: visible !important;
margin-left: 3px;
} }
...@@ -154,5 +155,8 @@ cursor:pointer; ...@@ -154,5 +155,8 @@ cursor:pointer;
.logoutButton{ .logoutButton{
font-size:2rem; font-size:2rem;
} }
.seatcontainer{
margin-left:1px;
}
} }
\ No newline at end of file
...@@ -6,13 +6,13 @@ ...@@ -6,13 +6,13 @@
"name": "Mani", "name": "Mani",
"reservedSeats": [ "reservedSeats": [
"G3", "G3",
"F3", "E4",
"G2", "G4",
"C2",
"C8",
"F4", "F4",
"E3",
"F7", "F7",
"F8" "E8",
"G8"
] ]
}, },
{ {
...@@ -20,18 +20,15 @@ ...@@ -20,18 +20,15 @@
"phoneNumber": "9361775481", "phoneNumber": "9361775481",
"name": "mani", "name": "mani",
"reservedSeats": [ "reservedSeats": [
"F5", "F3",
"E5", "F2",
"G5", "F1",
"F6", "F8",
"E6", "D8",
"E7",
"E8",
"G6", "G6",
"G7", "E7",
"G8", "D5",
"D7", "D6"
"D8"
] ]
}, },
{ {
...@@ -41,13 +38,7 @@ ...@@ -41,13 +38,7 @@
"phoneNumber": "9934782103", "phoneNumber": "9934782103",
"reservedSeats": [ "reservedSeats": [
"B4", "B4",
"D4", "D4"
"E3",
"A3",
"A2",
"A1",
"H1",
"H2"
] ]
}, },
{ {
...@@ -64,7 +55,10 @@ ...@@ -64,7 +55,10 @@
"name": "abinesh", "name": "abinesh",
"email": "abi@gmail.com", "email": "abi@gmail.com",
"phoneNumber": "1234587690", "phoneNumber": "1234587690",
"reservedSeats": [] "reservedSeats": [
"C5",
"B5"
]
}, },
{ {
"id": "8ebe", "id": "8ebe",
...@@ -78,11 +72,7 @@ ...@@ -78,11 +72,7 @@
"name": "ganesh", "name": "ganesh",
"email": "ganesh@gmail.com", "email": "ganesh@gmail.com",
"phoneNumber": "9786543219", "phoneNumber": "9786543219",
"reservedSeats": [ "reservedSeats": []
"C6",
"C7",
"B8"
]
}, },
{ {
"id": "9659", "id": "9659",
...@@ -174,7 +164,8 @@ ...@@ -174,7 +164,8 @@
"reservedSeats": [ "reservedSeats": [
"D3", "D3",
"C3", "C3",
"C4" "C4",
"C2"
] ]
} }
] ]
......
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