Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
Seat-Booking
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Madhankumar
Seat-Booking
Commits
b6d296a7
Commit
b6d296a7
authored
Oct 12, 2023
by
Madhankumar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
api call optimized
parent
20ba4c3b
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
55 additions
and
45 deletions
+55
-45
db.json
db.json
+2
-2
App.js
src/App.js
+0
-2
index.js
src/_context/index.js
+11
-5
index.js
src/components/top-level/seat-layout/index.js
+4
-3
index.js
src/components/top-level/seat-limit/index.js
+0
-7
confirmation.js
src/pages/confirmation.js
+12
-2
login.js
src/pages/login.js
+12
-17
seat-layout.js
src/pages/seat-layout.js
+11
-5
seat-limit.js
src/pages/seat-limit.js
+3
-2
No files found.
db.json
View file @
b6d296a7
...
@@ -12,8 +12,8 @@
...
@@ -12,8 +12,8 @@
"reservedSeats"
:
[
"reservedSeats"
:
[
{
{
"seats"
:
[
"seats"
:
[
"
E
8"
,
"
D
8"
,
"
H4
"
"
F7
"
],
],
"id"
:
1
"id"
:
1
},
},
...
...
src/App.js
View file @
b6d296a7
import
"./App.css"
;
import
"./App.css"
;
import
{
BrowserRouter
as
Router
,
Route
,
Routes
}
from
"react-router-dom"
;
import
{
BrowserRouter
as
Router
,
Route
,
Routes
}
from
"react-router-dom"
;
import
{
_Login
}
from
"../src/pages/login"
;
import
{
_Login
}
from
"../src/pages/login"
;
import
{
_Seatlayout
}
from
"../src/pages/seat-layout"
;
import
{
_Seatlayout
}
from
"../src/pages/seat-layout"
;
import
{
_Confirmation
}
from
"../src/pages/confirmation"
;
import
{
_Confirmation
}
from
"../src/pages/confirmation"
;
import
{
AuthGuard
}
from
"./auth/index"
;
import
{
AuthGuard
}
from
"./auth/index"
;
import
{
_seatLimit
}
from
"../src/pages/seat-limit"
;
import
{
_seatLimit
}
from
"../src/pages/seat-limit"
;
function
App
()
{
function
App
()
{
...
...
src/_context/index.js
View file @
b6d296a7
...
@@ -12,10 +12,16 @@ export function ContextProvider({ children }) {
...
@@ -12,10 +12,16 @@ export function ContextProvider({ children }) {
if
(
!
user
.
length
)
{
if
(
!
user
.
length
)
{
//register
//register
const
response
=
await
api
.
Register
({
mobile
});
const
response
=
await
api
.
Register
({
mobile
});
return
await
response
;
return
{
response
:
response
,
isRegistered
:
true
,
};
}
else
{
}
else
{
//login
//login
return
await
user
[
0
];
return
{
response
:
user
[
0
],
isRegistered
:
false
,
};
}
}
}
catch
(
err
)
{
}
catch
(
err
)
{
toast
.
error
(
err
.
message
);
toast
.
error
(
err
.
message
);
...
@@ -24,6 +30,7 @@ export function ContextProvider({ children }) {
...
@@ -24,6 +30,7 @@ export function ContextProvider({ children }) {
const
AddOrUpdateSeats
=
async
({
id
,
seats
})
=>
{
const
AddOrUpdateSeats
=
async
({
id
,
seats
})
=>
{
try
{
try
{
const
isSeats
=
userseats
.
filter
((
e
)
=>
e
.
id
==
id
);
const
isSeats
=
userseats
.
filter
((
e
)
=>
e
.
id
==
id
);
//check the id
if
(
!
isSeats
.
length
)
{
if
(
!
isSeats
.
length
)
{
//add seats
//add seats
const
response
=
await
api
.
AddSeats
({
seats
});
const
response
=
await
api
.
AddSeats
({
seats
});
...
@@ -51,9 +58,8 @@ export function ContextProvider({ children }) {
...
@@ -51,9 +58,8 @@ export function ContextProvider({ children }) {
const
GetSeatById
=
async
(
id
)
=>
{
const
GetSeatById
=
async
(
id
)
=>
{
try
{
try
{
const
response
=
await
api
.
GetAllSeats
();
const
response
=
await
api
.
GetSeatById
(
id
);
const
result
=
response
.
filter
((
e
)
=>
e
.
id
==
id
);
return
response
;
return
result
;
}
catch
(
err
)
{
}
catch
(
err
)
{
toast
.
error
(
err
.
message
);
toast
.
error
(
err
.
message
);
}
}
...
...
src/components/top-level/seat-layout/index.js
View file @
b6d296a7
// import { useNavigate } from "react-router-dom";
import
{
useEffect
,
useState
}
from
"react"
;
import
{
useEffect
,
useState
}
from
"react"
;
import
Button
from
"../../base/button"
;
import
Button
from
"../../base/button"
;
import
styles
from
"./seat-layout.module.css"
;
import
styles
from
"./seat-layout.module.css"
;
...
@@ -51,9 +50,11 @@ function SeatLayout({
...
@@ -51,9 +50,11 @@ function SeatLayout({
{
seats
?.
map
((
seat
,
i
)
=>
(
{
seats
?.
map
((
seat
,
i
)
=>
(
<
div
key
=
{
i
}
className
=
{
styles
.
seat
}
>
<
div
key
=
{
i
}
className
=
{
styles
.
seat
}
>
{
seat
?.
map
((
e
,
i
)
=>
(
{
seat
?.
map
((
e
,
i
)
=>
(
<
div
className
=
{
`
${
e
===
0
?
styles
[
"remove-seats"
]
:
""
}
`
}
>
<
div
key
=
{
i
}
className
=
{
`
${
e
===
0
?
styles
[
"remove-seats"
]
:
""
}
`
}
>
<
Seat
<
Seat
key
=
{
e
}
seatNo
=
{
e
}
seatNo
=
{
e
}
onChange
=
{()
=>
handleSeats
(
e
)}
onChange
=
{()
=>
handleSeats
(
e
)}
status
=
{
status
=
{
...
...
src/components/top-level/seat-limit/index.js
View file @
b6d296a7
...
@@ -9,7 +9,6 @@ function SeatLimit({ onLimit, ...props }) {
...
@@ -9,7 +9,6 @@ function SeatLimit({ onLimit, ...props }) {
e
.
preventDefault
();
e
.
preventDefault
();
if
(
limit
>
0
)
{
if
(
limit
>
0
)
{
onLimit
({
limit
});
onLimit
({
limit
});
sessionStorage
.
setItem
(
"seatLimit"
,
limit
);
}
else
{
}
else
{
toast
.
info
(
"Please enter atleast 1 seat"
);
toast
.
info
(
"Please enter atleast 1 seat"
);
}
}
...
@@ -26,12 +25,6 @@ function SeatLimit({ onLimit, ...props }) {
...
@@ -26,12 +25,6 @@ function SeatLimit({ onLimit, ...props }) {
min
=
"1"
min
=
"1"
max
=
"10"
max
=
"10"
/>
/>
{
/* <input
className={styles.input}
type="number"
value={limit}
onChange={(e) => setLimit(e.target.value)}
/> */
}
<
/div
>
<
/div
>
<
Button
{...
props
}
>
Book
Seats
<
/Button
>
<
Button
{...
props
}
>
Book
Seats
<
/Button
>
<
/form
>
<
/form
>
...
...
src/pages/confirmation.js
View file @
b6d296a7
import
Confirmation
from
"../components/top-level/confirmation"
;
import
Confirmation
from
"../components/top-level/confirmation"
;
import
{
useLocation
,
useNavigate
}
from
"react-router-dom"
;
import
{
useLocation
,
useNavigate
}
from
"react-router-dom"
;
import
{
useEffect
,
useState
}
from
"react"
;
import
{
useEffect
,
useState
}
from
"react"
;
import
{
useAppContext
}
from
"../_context"
;
export
function
_Confirmation
()
{
export
function
_Confirmation
()
{
const
[
count
,
setCount
]
=
useState
(
0
);
const
[
count
,
setCount
]
=
useState
(
0
);
const
[
reservedseat
,
setReservedSeat
]
=
useState
([]);
const
[
reservedseat
,
setReservedSeat
]
=
useState
([]);
let
{
GetSeatById
}
=
useAppContext
();
const
navigate
=
useNavigate
();
const
navigate
=
useNavigate
();
const
location
=
useLocation
();
const
location
=
useLocation
();
useEffect
(()
=>
{
useEffect
(()
=>
{
getSeatById
();
getSeatById
();
},
[]);
},
[]);
const
getSeatById
=
async
()
=>
{
const
getSeatById
=
async
()
=>
{
setCount
(
location
?.
state
?.
seats
.
length
);
if
(
location
?.
state
?.
seats
.
length
)
{
setReservedSeat
(
location
?.
state
?.
seats
);
setCount
(
location
.
state
.
seats
.
length
);
setReservedSeat
(
location
.
state
.
seats
);
}
else
{
const
userid
=
sessionStorage
.
getItem
(
"userId"
);
const
userseats
=
await
GetSeatById
(
userid
);
setCount
(
userseats
.
seats
.
length
);
setReservedSeat
(
userseats
.
seats
);
}
};
};
const
handleModify
=
(
e
)
=>
{
const
handleModify
=
(
e
)
=>
{
e
.
preventDefault
();
e
.
preventDefault
();
//for Auth Guard
sessionStorage
.
setItem
(
"currentPath"
,
"/booking"
);
sessionStorage
.
setItem
(
"currentPath"
,
"/booking"
);
navigate
(
"/booking"
);
navigate
(
"/booking"
);
};
};
...
...
src/pages/login.js
View file @
b6d296a7
...
@@ -5,28 +5,23 @@ import { useNavigate } from "react-router-dom";
...
@@ -5,28 +5,23 @@ import { useNavigate } from "react-router-dom";
export
function
_Login
()
{
export
function
_Login
()
{
const
navigate
=
useNavigate
();
const
navigate
=
useNavigate
();
const
{
LoginOrRegister
,
GetSeatById
}
=
useAppContext
();
const
{
LoginOrRegister
}
=
useAppContext
();
useEffect
(()
=>
{
useEffect
(()
=>
{
sessionStorage
.
clear
();
sessionStorage
.
clear
();
},
[]);
},
[]);
const
handleLogin
=
async
({
mobile
})
=>
{
const
handleLogin
=
async
({
mobile
})
=>
{
const
users
=
await
LoginOrRegister
({
mobile
});
const
users
=
await
LoginOrRegister
({
mobile
});
sessionStorage
.
setItem
(
"userId"
,
users
.
response
.
id
);
if
(
users
)
{
if
(
users
.
isRegistered
)
{
sessionStorage
.
setItem
(
"userId"
,
users
.
id
);
//for Auth Guard
//check seat length for already booked seats for the user
sessionStorage
.
setItem
(
"currentPath"
,
"/seat-limit"
);
const
userseat
=
await
GetSeatById
(
users
.
id
);
navigate
(
"/seat-limit"
);
}
else
{
if
(
userseat
.
length
)
{
//for Auth Guard
//if store the seat length in session
sessionStorage
.
setItem
(
"currentPath"
,
"/booking"
);
sessionStorage
.
setItem
(
"seatLimit"
,
userseat
[
0
].
seats
.
length
);
navigate
(
"/booking"
);
//redirect to booking component otherwise it will not redirect if not login
sessionStorage
.
setItem
(
"currentPath"
,
"/booking"
);
navigate
(
"/booking"
);
}
else
{
sessionStorage
.
setItem
(
"currentPath"
,
"/seat-limit"
);
navigate
(
"/seat-limit"
);
}
}
}
};
};
return
<
Login
onSubmit
=
{
handleLogin
}
/>
;
return
<
Login
onSubmit
=
{
handleLogin
}
/>
;
...
...
src/pages/seat-layout.js
View file @
b6d296a7
...
@@ -5,20 +5,21 @@ import { useNavigate } from "react-router-dom";
...
@@ -5,20 +5,21 @@ import { useNavigate } from "react-router-dom";
import
{
bookingSeats
}
from
"./seed"
;
import
{
bookingSeats
}
from
"./seed"
;
export
function
_Seatlayout
()
{
export
function
_Seatlayout
()
{
cons
t
{
userseats
,
AddOrUpdateSeats
,
GetAllSeats
}
=
useAppContext
();
le
t
{
userseats
,
AddOrUpdateSeats
,
GetAllSeats
}
=
useAppContext
();
const
[
reservedSeat
,
setReservedSeat
]
=
useState
([]);
const
[
reservedSeat
,
setReservedSeat
]
=
useState
([]);
const
[
selectedSeat
,
setSelectedSeat
]
=
useState
([]);
const
[
selectedSeat
,
setSelectedSeat
]
=
useState
([]);
const
[
seatLimit
,
setSeatLimit
]
=
useState
(
0
);
const
navigate
=
useNavigate
();
const
navigate
=
useNavigate
();
const
userId
=
sessionStorage
.
getItem
(
"userId"
);
const
userId
=
sessionStorage
.
getItem
(
"userId"
);
const
seatLimit
=
sessionStorage
.
getItem
(
"seatLimit"
);
useEffect
(()
=>
{
useEffect
(()
=>
{
handleReservedSeats
();
handleReservedSeats
();
},
[
userseats
]);
},
[
userseats
]);
useEffect
(()
=>
{
use
Layout
Effect
(()
=>
{
GetAllSeats
();
GetAllSeats
();
},
[]);
},
[]);
const
handleReservedSeats
=
()
=>
{
const
handleReservedSeats
=
async
()
=>
{
let
seatArray
=
[];
let
seatArray
=
[];
const
reservedSeats
=
userseats
?.
filter
((
e
)
=>
e
.
id
!=
userId
);
const
reservedSeats
=
userseats
?.
filter
((
e
)
=>
e
.
id
!=
userId
);
reservedSeats
.
forEach
((
element
)
=>
{
reservedSeats
.
forEach
((
element
)
=>
{
...
@@ -27,9 +28,14 @@ export function _Seatlayout() {
...
@@ -27,9 +28,14 @@ export function _Seatlayout() {
setReservedSeat
(
seatArray
);
setReservedSeat
(
seatArray
);
});
});
});
});
const
selectedSeats
=
userseats
?.
find
((
e
)
=>
e
.
id
==
userId
);
const
selectedSeats
=
await
userseats
?.
find
((
e
)
=>
e
.
id
==
userId
);
const
results
=
selectedSeats
?.
seats
;
const
results
=
selectedSeats
?.
seats
;
setSelectedSeat
(
results
);
setSelectedSeat
(
results
);
const
sessionSeatLimit
=
sessionStorage
.
getItem
(
"seatLimit"
);
setTimeout
(()
=>
{
sessionStorage
.
setItem
(
"seatLimit"
,
sessionSeatLimit
??
results
?.
length
);
setSeatLimit
(
sessionStorage
.
getItem
(
"seatLimit"
));
},
500
);
};
};
const
handleConfirmed
=
async
({
id
,
seats
})
=>
{
const
handleConfirmed
=
async
({
id
,
seats
})
=>
{
...
...
src/pages/seat-limit.js
View file @
b6d296a7
...
@@ -3,8 +3,9 @@ import { useNavigate } from "react-router-dom";
...
@@ -3,8 +3,9 @@ import { useNavigate } from "react-router-dom";
export
function
_seatLimit
()
{
export
function
_seatLimit
()
{
const
navigate
=
useNavigate
();
const
navigate
=
useNavigate
();
const
handleLimit
=
(
e
)
=>
{
const
handleLimit
=
()
=>
{
sessionStorage
.
setItem
(
"seatLimit"
,
e
.
limit
);
//for Auth Guard
sessionStorage
.
setItem
(
"currentPath"
,
"/booking"
);
sessionStorage
.
setItem
(
"currentPath"
,
"/booking"
);
navigate
(
"/booking"
);
navigate
(
"/booking"
);
};
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment