Commit d9fb75a6 by Syed Abdul Rahman

modal code refactor done

parent 8636c0a5
{ {
"users": [ "users": [
{ {
"id": "594f", "id": "eba4",
"email": "syedabdul.rahman@krds.com", "email": "syedabdul.rahman@krds.com",
"selectionCount": "3" "selectionCount": "3"
},
{
"id": "eece",
"email": "lucy@gmail.com",
"selectionCount": "4"
},
{
"id": "bd3f",
"email": "abdul@gmail.com",
"selectionCount": "4"
},
{
"id": "fa09",
"email": "test@gmail.com"
},
{
"id": "da06",
"email": "testing@gmail.com",
"selectionCount": 3
} }
], ],
"selectedSeats": [ "selectedSeats": [
{
"id": "eba4",
"userid": "eba4",
"selected": [
{
"row": 6,
"seat": 3
},
{
"row": 6,
"seat": 4
},
{
"row": 5,
"seat": 4
}
]
},
{
"id": "eece",
"userid": "eece",
"selected": [
{
"row": 7,
"seat": 1
},
{
"row": 7,
"seat": 2
},
{
"row": 7,
"seat": 4
},
{
"row": 6,
"seat": 2
}
]
},
{
"id": "bd3f",
"userid": "bd3f",
"selected": [
{
"row": 5,
"seat": 5
},
{
"row": 5,
"seat": 6
},
{
"row": 5,
"seat": 7
},
{
"row": 5,
"seat": 8
}
]
}
] ]
} }
\ No newline at end of file
.inputWrapper { .inputWrapper {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
gap: .5rem; gap: 0.5rem;
} }
.label { .label {
...@@ -13,7 +13,6 @@ ...@@ -13,7 +13,6 @@
outline: none; outline: none;
padding: 0.8em; padding: 0.8em;
border-radius: 5px; border-radius: 5px;
width: 93%;
font-family: 'Inter-Medium'; font-family: 'Inter-Medium';
color: #000000db; color: #000000db;
font-size: 16px; font-size: 16px;
......
import Input from "../../Base/Input/Index"; import Input from '../../Base/Input/Index';
import Button from "../../Base/Button/Index"; import Button from '../../Base/Button/Index';
import styles from "./styles.module.css"; import styles from './styles.module.css';
const Modal = ({ onConfirm, onChange, variant, onOfSeats, onCancel }) => { const Modal = ({ children }) => {
return ( return (
<div className={styles["overlay-container"]}> <div className={styles['overlay-container']}>
<div className={styles["modal-dialog"]} role="dialog" aria-modal="true"> <div className={styles['modal-dialog']} role="dialog" aria-modal="true">
{variant == "input" && ( {children}
<>
<h2 className={styles["modal-title"]}>Select Your Seats</h2>
<p>Please choose how many seats you'd like to book.</p>
<Input
label={"Number of Seats"}
placeholder="Enter number of seats"
type="number"
max="10"
min="1"
onChange={(e) => onChange(e.target.value)}
/>
<div className={`${styles["btn-wrapper"]} ${styles["flex-direction"]}`}>
<Button size={"sm"} onClick={onConfirm}>
Confirm
</Button>
</div>
</>
)}
{variant == "confirm" && (
<>
<h2 className={styles["modal-title"]}>Confirm Your Selection</h2>
{/* <p>
You have selected <strong>{onOfSeats}</strong> seat
{onOfSeats !== 1 ? "s" : ""}.
</p> */}
<p>Please confirm to proceed with your booking.</p>
<div className={styles["btn-wrapper"]}>
{/* <Button size={"sm"} onClick={onCancel}>
Cancel
</Button> */}
<Button size={"sm"} onClick={onConfirm}>
Confirm
</Button>
</div>
</>
)}
</div> </div>
</div> </div>
); );
......
...@@ -4,24 +4,9 @@ export default { ...@@ -4,24 +4,9 @@ export default {
tags: ['autodocs'], tags: ['autodocs'],
title: 'component/Shared/Modal', title: 'component/Shared/Modal',
component: Modal, component: Modal,
argTypes: { argTypes: {}
onConfirm: { action: 'On Modal confirm' },
onChange: { action: 'On No of seats value change' },
variant: {
control: { type: 'select' },
options: ['confirm', 'input']
},
onChange: {
action: 'onchange'
},
onConfirm: {
action: 'onconfirmm'
}
}
}; };
export const Default = { export const Default = {
args: { args: {}
variant: 'input'
}
}; };
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
border-radius: 10px; border-radius: 10px;
padding: 1rem 1.5rem; padding: 1rem 1.5rem;
box-sizing: border-box; box-sizing: border-box;
min-width: 300px;
min-height: 150px;
} }
.btn-wrapper { .btn-wrapper {
...@@ -27,7 +29,7 @@ ...@@ -27,7 +29,7 @@
gap: 1rem; gap: 1rem;
margin: 1rem 0; margin: 1rem 0;
} }
.flex-direction{ .flex-direction {
flex-direction: column; flex-direction: column;
} }
......
import SeatConfirmationContent from './Index';
export default {
title: 'Component/TopLevel/ConfirmationModal',
tags: ['autodocs'],
component: SeatConfirmationContent,
argTypes: {
onConfirm: { action: 'onConfirm' }
}
};
export const ConfirmationModal = {};
import Button from '../../Base/Button/Index';
import styles from './styles.module.css';
const Index = ({ onConfirm }) => {
return (
<>
<h2 className={styles['modal-title']}>Confirm Your Selection</h2>
<p className={styles['modal-title']}>
Please confirm to proceed with your booking.
</p>
<div className={styles['btn-wrapper']}>
<Button size={'md'} onClick={onConfirm}>
Confirm
</Button>
</div>
</>
);
};
export default Index;
.btn-wrapper {
display: flex;
gap: 1rem;
margin: 1rem 0;
flex-direction: column;
}
.modal-title {
font-family: 'Poppins-Medium';
font-weight: 500;
}
...@@ -4,7 +4,7 @@ export default { ...@@ -4,7 +4,7 @@ export default {
title: 'component/TopLevel/Login', title: 'component/TopLevel/Login',
component: Login, component: Login,
argTypes: { argTypes: {
handleSubmit: { action: 'Form Value' } onSubmit: { action: 'Form Value' }
} }
}; };
......
import Input from '../../Base/Input/Index';
import Button from '../../Base/Button/Index';
import styles from './styles.module.css';
const Index = ({ onChange, onConfirm, disabled }) => {
return (
<>
<h2 className={styles['modal-title']}>Select Your Seats</h2>
<p className={styles['modal-title']}>
Please choose how many seats you'd like to book.
</p>
<Input
label={'Number of Seats'}
placeholder="Enter number of seats"
type="number"
max="10"
min="1"
onChange={(e) => onChange(e.target.value)}
/>
<div className={`${styles['btn-wrapper']} ${styles['flex-direction']}`}>
<Button size={'md'} onClick={onConfirm} disabled={disabled}>
Confirm
</Button>
</div>
</>
);
};
export default Index;
import SeatSelectionContent from './Index';
export default {
title: 'Component/TopLevel/SeatSelectionContent',
tags: ['autodocs'],
component: SeatSelectionContent,
argTypes: {
onChange: { action: 'onChange' },
onConfirm: { action: 'onConfirm' }
}
};
export const SelectSeatContent = {};
.btn-wrapper {
display: flex;
/* justify-content: flex-end; */
flex-direction: column;
gap: 1rem;
margin: 1rem 0;
width: 100%;
}
.modal-title {
font-family: 'Poppins-Medium';
font-weight: 500;
}
...@@ -12,6 +12,8 @@ import { ...@@ -12,6 +12,8 @@ import {
import BookingWrapper from '../../components/Layout/BookingWrapper/Index'; import BookingWrapper from '../../components/Layout/BookingWrapper/Index';
import Header from '../../components/Layout/Header/Index'; import Header from '../../components/Layout/Header/Index';
import Modal from '../../components/Shared/Modal/Index'; import Modal from '../../components/Shared/Modal/Index';
import ConfirmSeatContent from '../../components/TopLevel/ConfirmSeatContent/Index';
import SeatSelectionContent from '../../components/TopLevel/SeatSelectionContent/Index';
import Button from '../../components/Base/Button/Index'; import Button from '../../components/Base/Button/Index';
import LegendWrapper from '../../components/TopLevel/LegendWrapper/Index'; import LegendWrapper from '../../components/TopLevel/LegendWrapper/Index';
import img from '../../assets/images/power-button_12080802.png'; import img from '../../assets/images/power-button_12080802.png';
...@@ -30,14 +32,8 @@ const BookingPage = () => { ...@@ -30,14 +32,8 @@ const BookingPage = () => {
useState(false); useState(false);
const [noOfSeats, setNoOfSeats] = useState(); const [noOfSeats, setNoOfSeats] = useState();
const [buttonState, setButtonState] = useState(true); const [buttonState, setButtonState] = useState(true);
const [modalButtonState, setModalButtonState] = useState(true);
useEffect(() => { useEffect(() => {
const fetchSelectedSeats = async () => {
const data = await getSelectedSeatsApi();
const currentData = data?.find((e) => e.userid == userId);
setSelectedSeats(data);
setCurrentSeats(currentData?.selected);
};
const fetchSeatSelectionCount = async () => { const fetchSeatSelectionCount = async () => {
const data = await getSeatSelectionCountApi(userId); const data = await getSeatSelectionCountApi(userId);
setNoOfSeats(data?.selectionCount); setNoOfSeats(data?.selectionCount);
...@@ -47,6 +43,13 @@ const BookingPage = () => { ...@@ -47,6 +43,13 @@ const BookingPage = () => {
setShowSeatsModal(getItem(appConstants.MODAL)); setShowSeatsModal(getItem(appConstants.MODAL));
}, []); }, []);
const fetchSelectedSeats = async () => {
const data = await getSelectedSeatsApi();
const currentData = data?.find((e) => e.userid == userId);
setSelectedSeats(data);
setCurrentSeats(currentData?.selected);
};
const data = [ const data = [
{ {
row_id: 1, row_id: 1,
...@@ -333,7 +336,13 @@ const BookingPage = () => { ...@@ -333,7 +336,13 @@ const BookingPage = () => {
}; };
const onModalChange = (value) => { const onModalChange = (value) => {
setNoOfSeats(value); const numericValue = parseInt(value, 10);
setNoOfSeats(numericValue);
if (value && value !== '') {
setModalButtonState(false);
} else {
setModalButtonState(true);
}
}; };
const modalClose = () => { const modalClose = () => {
...@@ -341,6 +350,7 @@ const BookingPage = () => { ...@@ -341,6 +350,7 @@ const BookingPage = () => {
if (userId && noOfSeats) { if (userId && noOfSeats) {
saveSeatSelectionCountApi(userId, noOfSeats); saveSeatSelectionCountApi(userId, noOfSeats);
} }
fetchSelectedSeats();
setShowSeatsModal(false); setShowSeatsModal(false);
}; };
...@@ -378,20 +388,23 @@ const BookingPage = () => { ...@@ -378,20 +388,23 @@ const BookingPage = () => {
setButtonState(true); setButtonState(true);
} }
} else { } else {
if (prev?.length < noOfSeats) { console.log('INSIDE ELSE', prev?.length, noOfSeats);
if (prev?.length < noOfSeats || !prev?.length) {
console.log('INSIDE IF 22');
if (prev) {
updatedSeats = [...prev, { row: rowId, seat: columnId }]; updatedSeats = [...prev, { row: rowId, seat: columnId }];
} else {
updatedSeats = [{ row: rowId, seat: columnId }];
}
if (updatedSeats?.length === parseInt(noOfSeats)) { if (updatedSeats?.length === parseInt(noOfSeats)) {
setButtonState(false); setButtonState(false);
} else { } else {
setButtonState(true); setButtonState(true);
} }
} else { } else {
console.log('INSIDE ELSE 222');
updatedSeats = prev ? [...prev] : []; updatedSeats = prev ? [...prev] : [];
// if (updatedSeats?.length === parseInt(noOfSeats)) {
// setButtonState(false);
// } else {
// setButtonState(true);
// }
} }
} }
...@@ -420,10 +433,10 @@ const BookingPage = () => { ...@@ -420,10 +433,10 @@ const BookingPage = () => {
}; };
await createSeatApi(info); await createSeatApi(info);
} }
setCurrentSeats([]);
fetchData(); fetchData();
setShowSeatsConfirmationModal(false); setShowSeatsConfirmationModal(false);
}; };
return ( return (
<div className={styles['seat-booking-wrapper']}> <div className={styles['seat-booking-wrapper']}>
<img <img
...@@ -442,30 +455,24 @@ const BookingPage = () => { ...@@ -442,30 +455,24 @@ const BookingPage = () => {
/> />
</div> </div>
<div className={styles['btn-wrapper']}> <div className={styles['btn-wrapper']}>
<Button <Button size={'lg'} onClick={onSeatsConfirm} disabled={buttonState}>
size={'lg'}
onClick={onSeatsConfirm}
// disabled={currentSeats?.length == noOfSeats ? true : false}>
disabled={buttonState}>
Confirm Confirm
</Button> </Button>
</div> </div>
<LegendWrapper /> <LegendWrapper />
{showSeatsModal && ( {showSeatsModal && (
<Modal <Modal>
onConfirm={modalClose} <SeatSelectionContent
onChange={onModalChange} onChange={onModalChange}
variant="input" onConfirm={modalClose}
value={noOfSeats} disabled={modalButtonState}
/> />
</Modal>
)} )}
{showSeatsConfirmationModal && ( {showSeatsConfirmationModal && (
<Modal <Modal>
onConfirm={seatsFinal} <ConfirmSeatContent onConfirm={seatsFinal} />
onChange={onModalChange} </Modal>
variant={'confirm'}
onCancel={finalCancel}
/>
)} )}
</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