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
37f4be73
Commit
37f4be73
authored
Oct 26, 2023
by
Madhankumar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
appcontext update
parent
c70643c1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
17 deletions
+12
-17
index.js
src/context/index.js
+10
-8
login.js
src/pages/login.js
+2
-9
No files found.
src/context/index.js
View file @
37f4be73
import
{
createContext
,
useContext
,
useState
}
from
"react"
;
import
{
createContext
,
useContext
,
useState
}
from
"react"
;
import
*
as
api
from
"../lib/api"
;
import
*
as
api
from
"../lib/api"
;
import
{
toast
}
from
"react-toastify"
;
import
{
toast
}
from
"react-toastify"
;
import
{
useNavigate
}
from
"react-router-dom"
;
export
const
AppContext
=
createContext
();
export
const
AppContext
=
createContext
();
export
const
useAppContext
=
()
=>
useContext
(
AppContext
);
export
const
useAppContext
=
()
=>
useContext
(
AppContext
);
...
@@ -8,8 +9,8 @@ export function ContextProvider({ children }) {
...
@@ -8,8 +9,8 @@ export function ContextProvider({ children }) {
const
[
userSeats
,
setUserSeats
]
=
useState
([]);
const
[
userSeats
,
setUserSeats
]
=
useState
([]);
const
[
reservedSeats
,
setReservedSeats
]
=
useState
([]);
const
[
reservedSeats
,
setReservedSeats
]
=
useState
([]);
const
[
seatLayout
,
setSeatLayout
]
=
useState
([]);
const
[
seatLayout
,
setSeatLayout
]
=
useState
([]);
const
[
isLoading
,
set
i
sLoading
]
=
useState
(
false
);
const
[
isLoading
,
set
I
sLoading
]
=
useState
(
false
);
const
navigate
=
useNavigate
();
const
loginOrRegister
=
async
({
mobile
})
=>
{
const
loginOrRegister
=
async
({
mobile
})
=>
{
try
{
try
{
const
user
=
await
api
.
getUserByMobile
({
mobile
});
const
user
=
await
api
.
getUserByMobile
({
mobile
});
...
@@ -19,7 +20,8 @@ export function ContextProvider({ children }) {
...
@@ -19,7 +20,8 @@ export function ContextProvider({ children }) {
sessionStorage
.
setItem
(
"userId"
,
response
?.
id
);
sessionStorage
.
setItem
(
"userId"
,
response
?.
id
);
await
getAllReservedSeats
();
await
getAllReservedSeats
();
// return true for newly registered user
// return true for newly registered user
return
true
;
navigate
(
"/seat-limit"
);
}
else
{
}
else
{
//login
//login
sessionStorage
.
setItem
(
"userId"
,
user
?.[
0
]?.
id
);
sessionStorage
.
setItem
(
"userId"
,
user
?.[
0
]?.
id
);
...
@@ -30,7 +32,7 @@ export function ContextProvider({ children }) {
...
@@ -30,7 +32,7 @@ export function ContextProvider({ children }) {
userSelectedSeats
?.[
0
]?.
seats
?.
length
userSelectedSeats
?.[
0
]?.
seats
?.
length
);
);
// return false for already registered user
// return false for already registered user
return
false
;
navigate
(
"/booking"
)
;
}
}
}
catch
(
err
)
{
}
catch
(
err
)
{
toast
.
error
(
err
.
message
);
toast
.
error
(
err
.
message
);
...
@@ -53,7 +55,7 @@ export function ContextProvider({ children }) {
...
@@ -53,7 +55,7 @@ export function ContextProvider({ children }) {
}
}
};
};
const
getAllReservedSeats
=
async
()
=>
{
const
getAllReservedSeats
=
async
()
=>
{
set
i
sLoading
(
false
);
set
I
sLoading
(
false
);
try
{
try
{
//to clear the data for glitch
//to clear the data for glitch
setReservedSeats
([]);
setReservedSeats
([]);
...
@@ -72,7 +74,7 @@ export function ContextProvider({ children }) {
...
@@ -72,7 +74,7 @@ export function ContextProvider({ children }) {
setUserSeats
(
e
.
seats
)
setUserSeats
(
e
.
seats
)
);
);
set
i
sLoading
(
true
);
set
I
sLoading
(
true
);
return
await
response
;
return
await
response
;
}
catch
(
err
)
{
}
catch
(
err
)
{
toast
.
error
(
err
.
message
);
toast
.
error
(
err
.
message
);
...
@@ -80,12 +82,12 @@ export function ContextProvider({ children }) {
...
@@ -80,12 +82,12 @@ export function ContextProvider({ children }) {
};
};
const
getSeatLayout
=
async
()
=>
{
const
getSeatLayout
=
async
()
=>
{
set
i
sLoading
(
false
);
set
I
sLoading
(
false
);
try
{
try
{
setSeatLayout
([]);
setSeatLayout
([]);
const
response
=
await
api
.
getSeatLayout
();
const
response
=
await
api
.
getSeatLayout
();
setSeatLayout
(
response
);
setSeatLayout
(
response
);
set
i
sLoading
(
true
);
set
I
sLoading
(
true
);
}
catch
(
err
)
{
}
catch
(
err
)
{
toast
.
error
(
err
.
message
);
toast
.
error
(
err
.
message
);
}
}
...
...
src/pages/login.js
View file @
37f4be73
import
{
useEffect
}
from
"react"
;
import
{
useEffect
}
from
"react"
;
import
{
useAppContext
}
from
"../context"
;
import
{
useAppContext
}
from
"../context"
;
import
Login
from
"../components/top-level/login"
;
import
Login
from
"../components/top-level/login"
;
import
{
useNavigate
}
from
"react-router-dom"
;
export
function
LoginPage
()
{
const
navigate
=
useNavigate
();
export
function
LoginPage
()
{
const
{
loginOrRegister
}
=
useAppContext
();
const
{
loginOrRegister
}
=
useAppContext
();
useEffect
(()
=>
{
useEffect
(()
=>
{
sessionStorage
.
clear
();
sessionStorage
.
clear
();
},
[]);
},
[]);
const
handleLogin
=
async
({
mobile
})
=>
{
const
handleLogin
=
async
({
mobile
})
=>
{
const
isRegistered
=
await
loginOrRegister
({
mobile
});
await
loginOrRegister
({
mobile
});
if
(
isRegistered
)
{
navigate
(
"/seat-limit"
);
}
else
{
navigate
(
"/booking"
);
}
};
};
return
<
Login
onSubmit
=
{
handleLogin
}
/>
;
return
<
Login
onSubmit
=
{
handleLogin
}
/>
;
}
}
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