Toggle navigation
Toggle navigation
This project
Loading...
Sign in
황선혁
/
weather_chatbot
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
Eric Whale
2022-06-07 19:31:53 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
a891e3d7f942f6bb90156efdfc9c72e0342824b9
a891e3d7
1 parent
99bc942d
Add logout
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
11 deletions
client/src/routes/settings.jsx
client/src/routes/settings.jsx
View file @
a891e3d
import
{
useState
,
useEffect
}
from
"react"
;
import
{
useNavigate
}
from
"react-router-dom"
;
import
{
Navigate
,
useNavigate
}
from
"react-router-dom"
;
import
authService
from
"../service/auth"
;
// components
import
Topbar
from
"../components/Topbar"
;
import
Bottombar
from
"../components/Bottombar"
;
function
Settings
()
{
const
token
=
sessionStorage
.
getItem
(
"user-token"
);
const
navigate
=
useNavigate
();
const
[
editSuccess
,
setEdi
tSuccess
]
=
useState
(
0
);
const
[
logoutSuccess
,
setLogou
tSuccess
]
=
useState
(
0
);
const
[
userinfo
,
setUserinfo
]
=
useState
({
username
:
""
,
country
:
""
,
...
...
@@ -15,13 +16,12 @@ function Settings() {
email
:
""
,
});
// useEffect(() => {
// navigate("/login", { replace: true });
// }, [ navigate]);
const
logout
=
()
=>
{
return
;
};
useEffect
(()
=>
{
if
(
logoutSuccess
===
"logout"
)
{
sessionStorage
.
clear
();
navigate
(
"/login"
,
{
replace
:
true
});
}
},
[
logoutSuccess
,
setLogoutSuccess
,
navigate
]);
const
onChange
=
(
e
)
=>
{
setUserinfo
((
orgState
)
=>
({
...
...
@@ -37,9 +37,15 @@ function Settings() {
return
;
}
const
response
=
await
authService
.
handleUserEdit
(
userinfo
);
setEditSuccess
(
response
);
if
(
response
===
"success"
)
{
alert
(
"User info successfully changed"
);
}
};
if
(
!
token
)
{
return
<
Navigate
to=
"/login"
/>;
}
return
(
<
div
>
<
Topbar
/>
...
...
@@ -89,7 +95,8 @@ function Settings() {
<
br
/>
<
div
>
Want to logout?
<
button
onClick=
{
()
=>
logout
()
}
>
Logout
</
button
>
Want to logout?
{
" "
}
<
button
onClick=
{
()
=>
setLogoutSuccess
(
"logout"
)
}
>
Logout
</
button
>
</
div
>
<
Bottombar
/>
</
div
>
...
...
Please
register
or
login
to post a comment