From 7561013eeaa7653a31fd22c88fe803f340f58116 Mon Sep 17 00:00:00 2001 From: edwin6666 Date: Fri, 7 Jul 2023 11:08:35 -0400 Subject: [PATCH 01/10] Change Routes admin and home --- src/App.js | 4 ++-- src/components/Login/index.jsx | 7 +++++-- src/components/Navbar/Navbar.jsx | 8 ++++---- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/App.js b/src/App.js index dc42127..5ef5e5d 100644 --- a/src/App.js +++ b/src/App.js @@ -28,12 +28,12 @@ function App() { {/* Public routes */} } /> } /> - } /> + } /> } /> {/* Private routes */} }> - } /> + } /> } /> } /> diff --git a/src/components/Login/index.jsx b/src/components/Login/index.jsx index e587366..14cdd33 100644 --- a/src/components/Login/index.jsx +++ b/src/components/Login/index.jsx @@ -1,6 +1,7 @@ import { useState } from "react"; import useAuth from "../../hooks/useAuth"; import axios from "axios"; +import { useLocation, useNavigate } from "react-router-dom"; const Signin = () => { const [data, setData] = useState({ @@ -10,7 +11,9 @@ const Signin = () => { const [error, setError] = useState(""); const { setAuth } = useAuth(); - + const location = useLocation(); + const navigate = useNavigate(); + const from = location.state?.from?.pathname || "/"; @@ -28,7 +31,7 @@ const Signin = () => { setAuth({ roles, token }); console.log(roles); - window.location= "/homeuser" + navigate(from, { replace: true }); } catch (error) { if ( error.response && diff --git a/src/components/Navbar/Navbar.jsx b/src/components/Navbar/Navbar.jsx index f9e5ed3..a4513fb 100644 --- a/src/components/Navbar/Navbar.jsx +++ b/src/components/Navbar/Navbar.jsx @@ -5,8 +5,8 @@ import { Link } from 'react-router-dom'; const Navbar = () => { const handleLogout = () => { - localStorage.removeItem("token"); - window.location.reload("/login"); + + window.location= "/login"; }; const [open, setOpen] = useState(true); @@ -35,7 +35,7 @@ const Navbar = () => { From 89aeb1412abc472d8212737fede373ce8c34d0df Mon Sep 17 00:00:00 2001 From: edwin6666 Date: Sat, 8 Jul 2023 12:35:55 -0400 Subject: [PATCH 03/10] Feat: logout function --- src/components/Navbar/Navbar.jsx | 3 +++ src/components/PostCard.jsx | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/components/Navbar/Navbar.jsx b/src/components/Navbar/Navbar.jsx index 3fd1ef7..303d205 100644 --- a/src/components/Navbar/Navbar.jsx +++ b/src/components/Navbar/Navbar.jsx @@ -2,12 +2,15 @@ import React, { useState } from 'react'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faSignOutAlt } from '@fortawesome/free-solid-svg-icons'; import { Link, useLocation } from 'react-router-dom'; +import useAuth from "../../hooks/useAuth"; const Navbar = () => { const location = useLocation(); const isLoginPage = location.pathname === '/login'; + const { setAuth } = useAuth(); const handleLogout = () => { + setAuth({ roles: null, token: null }); window.location = "/login"; }; diff --git a/src/components/PostCard.jsx b/src/components/PostCard.jsx index 477e245..ea6a7bb 100644 --- a/src/components/PostCard.jsx +++ b/src/components/PostCard.jsx @@ -89,13 +89,13 @@ export function PostCard({ post }) {
{" "} {" "} {" "} {" "}
diff --git a/src/components/PostCardUser.jsx b/src/components/PostCardUser.jsx index b0f5b19..994c0cb 100644 --- a/src/components/PostCardUser.jsx +++ b/src/components/PostCardUser.jsx @@ -26,7 +26,7 @@ export function PostCardUser({ post }) {
diff --git a/src/pages/Contact.js b/src/pages/Contact.js index 0d308d0..1cc1ab2 100644 --- a/src/pages/Contact.js +++ b/src/pages/Contact.js @@ -48,7 +48,7 @@ const ContactForm = () => { return (
-

Contact us

+

Contact us

Email us at help@techtalk12.com or message us here:

@@ -106,7 +106,7 @@ const ContactForm = () => {
From 9f21d7b750dd7a1f309dcdc631b7d462556c98ae Mon Sep 17 00:00:00 2001 From: edwin6666 Date: Tue, 11 Jul 2023 23:28:07 -0400 Subject: [PATCH 08/10] Style button in contact --- src/App.js | 1 + src/components/Login/Login.jsx | 3 ++- src/pages/Contact.js | 2 +- src/pages/PostForm.js | 4 ++-- 4 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/App.js b/src/App.js index 6a1f4bb..421cfd1 100644 --- a/src/App.js +++ b/src/App.js @@ -14,6 +14,7 @@ function App() { const isLoginPage = location.pathname === "/login"; return ( +
{ const roles = res?.roles; const token = res?.token; setAuth({ roles, token }); - + console.log(roles); + navigate(from, { replace: true }); } catch (error) { if ( diff --git a/src/pages/Contact.js b/src/pages/Contact.js index 1cc1ab2..8514d62 100644 --- a/src/pages/Contact.js +++ b/src/pages/Contact.js @@ -106,7 +106,7 @@ const ContactForm = () => {
diff --git a/src/pages/PostForm.js b/src/pages/PostForm.js index 8ecf234..283f8c5 100644 --- a/src/pages/PostForm.js +++ b/src/pages/PostForm.js @@ -79,7 +79,7 @@ export function PostForm() { /> @@ -87,7 +87,7 @@ export function PostForm() { component="textarea" name="description" placeholder="Description" - className="px-3 py-2 focus:outline-none rounded bg-gray-600 text-white w-full" + className="px-3 py-2 focus:outline-none rounded bg-gray-600 text-white w-full " rows={5} /> Date: Wed, 12 Jul 2023 23:33:03 -0400 Subject: [PATCH 09/10] Feat logout or login as necessary --- src/components/Login/Login.jsx | 2 +- src/components/Navbar/Navbar.jsx | 4 ++-- src/pages/NotFoundPage.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/Login/Login.jsx b/src/components/Login/Login.jsx index a8da90b..9ba4e2d 100644 --- a/src/components/Login/Login.jsx +++ b/src/components/Login/Login.jsx @@ -131,7 +131,7 @@ const Signin = () => { )}
)} diff --git a/src/pages/NotFoundPage.js b/src/pages/NotFoundPage.js index 36e61ed..4969238 100644 --- a/src/pages/NotFoundPage.js +++ b/src/pages/NotFoundPage.js @@ -10,7 +10,7 @@ export function NotFoundPage() { )}