From bb72f1e53811788db9bc66fdae187b33e36712fe Mon Sep 17 00:00:00 2001 From: Luke Berndt Date: Tue, 9 Jul 2024 07:27:51 -0400 Subject: [PATCH] actually redirects to terms --- account/src/App/Restricted.js | 5 +- account/src/User/Login.js | 234 +++++++++++++++++----------------- 2 files changed, 122 insertions(+), 117 deletions(-) diff --git a/account/src/App/Restricted.js b/account/src/App/Restricted.js index 5ad2bb5..8947193 100644 --- a/account/src/App/Restricted.js +++ b/account/src/App/Restricted.js @@ -8,7 +8,7 @@ import { useNavigate, useLocation } from 'react-router-dom'; */ const Restricted = ({ children }) => { - const { authenticated, hasAuthenticated,terms } = useSelector((state) => state.user); + const { authenticated, hasAuthenticated, terms } = useSelector((state) => state.user); const dispatch = useDispatch(); const navigate = useNavigate(); const location = useLocation(); @@ -22,8 +22,9 @@ const Restricted = ({ children }) => { if (authenticated) { if ((pathname != "/terms") && (terms != 1.1)) { navigate("/terms") + } else { + return children; } - return children; } else { navigate("/login") diff --git a/account/src/User/Login.js b/account/src/User/Login.js index a5584a1..721c186 100644 --- a/account/src/User/Login.js +++ b/account/src/User/Login.js @@ -1,7 +1,7 @@ -import { useState } from "react"; -import { useNavigate, useSearchParams, Link } from 'react-router-dom'; -import { loginUser } from "../features/user/userSlice"; -import { useDispatch } from 'react-redux'; +import { useState } from "react"; +import { useNavigate, useSearchParams, Link, useLocation } from 'react-router-dom'; +import { useSelector, useDispatch } from 'react-redux' +import { loginUser } from "../features/user/userSlice"; import { Container, Header, @@ -28,27 +28,31 @@ const forgotStyle = { const Login = (props) => { + const { terms } = useSelector((state) => state.user); const [loginMessage, setLoginMessage] = useState(""); const [email, setEmail] = useState(""); const [password, setPassword] = useState(""); const navigate = useNavigate(); let [searchParams] = useSearchParams(); const nextLocation = searchParams.get("nextLocation"); + const location = useLocation(); + const { hash, pathname, search } = location; const dispatch = useDispatch(); const loginSubmit = async (event) => { event.preventDefault(); - const result = await dispatch(loginUser({email,password})).unwrap(); + const result = await dispatch(loginUser({ email, password })).unwrap(); if (result.success) { - - if (nextLocation) { + if ((pathname != "/terms") && (terms != 1.1)) { + navigate("/terms") + } else if (nextLocation) { switch (nextLocation) { case "frontend": - window.location = process.env.REACT_APP_FRONTEND_SERVER; + window.location = process.env.REACT_APP_FRONTEND_SERVER; break; - default: + default: case "admin": - window.location = process.env.REACT_APP_ADMIN_SERVER; + window.location = process.env.REACT_APP_ADMIN_SERVER; break; case "account": navigate("/"); @@ -56,7 +60,7 @@ const Login = (props) => { } } else { navigate("/"); - } + } console.log(result) } else { console.error(result); @@ -73,113 +77,113 @@ const Login = (props) => { } } - let loginMessageDisplay =(<>) + let loginMessageDisplay = (<>) - if (loginMessage) { - loginMessageDisplay = ( - - - - Problems... - {loginMessage} - - - ); - } - - return ( - -
{process.env.REACT_APP_SITE_NAME}
- - - - -
Let's get this started!
-
- {process.env.REACT_APP_SITE_NAME} makes it easy to share recordings from{" "} - - Trunk Recorder - .
-

- Trunk Recorder makes it easy to record the radio systems - used by your local police and fire department. Trunk Recorder - is sort of like an awesome version of those Scanners from - Radio Shack... 10-4! -

-

- This site is a work in progress. I plan on adding more - features over time, but right now it can: -

-
    -
  • 30 day archive
  • -
  • Filter by talkgroup
  • -
-

- All of this goodness is free! In the future, I might offer - paid accounts with additional features and a longer archive - period, but I will always try to have a free version. -

-

- {" "} - - Luke{" "} - - admin@email.com - {" "} -

-
- -
Need an account?
- - {loginMessageDisplay} - - -
- Forgot Password -
-
-
-
-
+ if (loginMessage) { + loginMessageDisplay = ( + + + + Problems... + {loginMessage} + + ); } + return ( + +
{process.env.REACT_APP_SITE_NAME}
+ + + + +
Let's get this started!
+
+ {process.env.REACT_APP_SITE_NAME} makes it easy to share recordings from{" "} + + Trunk Recorder + .
+

+ Trunk Recorder makes it easy to record the radio systems + used by your local police and fire department. Trunk Recorder + is sort of like an awesome version of those Scanners from + Radio Shack... 10-4! +

+

+ This site is a work in progress. I plan on adding more + features over time, but right now it can: +

+
    +
  • 30 day archive
  • +
  • Filter by talkgroup
  • +
+

+ All of this goodness is free! In the future, I might offer + paid accounts with additional features and a longer archive + period, but I will always try to have a free version. +

+

+ {" "} + - Luke{" "} + + admin@email.com + {" "} +

+
+ +
Need an account?
+ + {loginMessageDisplay} + + +
+ Forgot Password +
+
+
+
+
+ ); +} + export default Login;