Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Added logout option in /user/profile route #167

Merged
merged 1 commit into from
Feb 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Home from "./pages/Home";
import ClubLogin from "./pages/clubs/ClubsLogin";
import ClubRegister from "./pages/clubs/ClubsRegister";
import UserRegister from "./pages/user/UserRegister";
import UserProfile from "./pages/user/UserProfile";
import ClubsPage from "./pages/display/ClubsPage";
import UserLogin from "./pages/user/UserLogin";
import ContactPage from "./pages/ContactUs";
Expand All @@ -25,7 +26,7 @@ const App = () => {

<Route exact path="/user/register" element={<UserRegister />} />
<Route exact path="/user/login" element={<UserLogin />} />

<Route exact path="/user/profile" element={<UserProfile />} />
{/* //* Auth routes - CLUBS*/}

<Route exact path="/clubs/login" element={<ClubLogin />} />
Expand Down
2 changes: 1 addition & 1 deletion src/components/Footer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const Footer = () => {
const handleReportSubmit = async (e) => {
e.preventDefault();

if (localStorage.getItem("user") === null) {
if (sessionStorage.getItem("token") === null) {
toast.error("You must be logged in to report an issue");
return;
}
Expand Down
6 changes: 5 additions & 1 deletion src/components/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ const Navbar = (props) => {
const navigate = useNavigate();

const handleNavigate = () => {
navigate("/user/login");
if (sessionStorage.getItem("token")) {
navigate("/user/profile");
} else {
navigate("/user/login");
}
};

return (
Expand Down
2 changes: 1 addition & 1 deletion src/pages/Home.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import EventsBanner from "../components/Events";
import LoginBanner from "../components/loginBanner";

const AuthState = () => {
const [login, setLogin] = useState(localStorage.getItem("token"));
const [login, setLogin] = useState(sessionStorage.getItem("token"));
return login;
};
const Home = () => {
Expand Down
70 changes: 70 additions & 0 deletions src/pages/user/UserProfile.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import React, { useState } from "react";
import Navbar from "../../components/Navbar";
import { Link, useNavigate } from "react-router-dom";


export default function UserProfile() {

const Navigate = useNavigate();
const handleLogout = () => {
sessionStorage.removeItem("token");
Navigate("/");
}

return (
<>
<Navbar />


<section className="vh-100">
<div className="container py-5 h-100">
<div className="row d-flex align-items-center justify-content-center h-100">
<div className="col-md-8 col-lg-7 col-xl-6">
<img
src="https://www.getillustrations.com/packs/plastic-illustrations-scene-builder-pack/scenes/_1x/accounts%20_%20man,%20workspace,%20desk,%20laptop,%20login,%20user_md.png"
className="img-fluid"
alt="Phone"
/>
</div>

<div className="col-md-7 col-lg-5 col-xl-5 offset-xl-1">
<form style={{ width: "auto" }}>
<h2 style={{ letterSpacing: "1px" }}>Profile</h2>
<div className="form-outline mb-4">
<label
htmlFor="email"
className=" col-form-label col-form-label-lg"
>
Update Email address
</label>


</div>
<div className="form-outline mb-4">
<label
htmlFor="password"
className="col-form-label col-form-label-lg"
>
Update Password
</label>

</div>
<br />
<button
onClick={handleLogout}
className="btn btn-lg btn-block"
style={{ backgroundColor: "#89b5f7" }}
>
Logout
</button>
<br></br> <br></br>

</form>
</div>
</div>
</div>
</section>

</>
)
}