+
Manage list of meds
diff --git a/frontend/src/components/Header/Header.tsx b/frontend/src/components/Header/Header.tsx
index 49798c83..cbbd2c93 100644
--- a/frontend/src/components/Header/Header.tsx
+++ b/frontend/src/components/Header/Header.tsx
@@ -1,20 +1,16 @@
-import { useState, useRef, useEffect, Fragment } from "react";
-// import { useState, Fragment } from "react";
-import accountLogo from "../../assets/account.svg";
+import { useState, useRef, useEffect } from "react";
import { Link, useNavigate, useLocation } from "react-router-dom";
-import LoginMenuDropDown from "./LoginMenuDropDown";
import "../../components/Header/header.css";
import Chat from "./Chat";
import { FeatureMenuDropDown } from "./FeatureMenuDropDown";
import MdNavBar from "./MdNavBar";
-import { connect, useDispatch } from "react-redux";
+import { connect } from "react-redux";
import { RootState } from "../../services/actions/types";
-import { logout, AppDispatch } from "../../services/actions/auth";
-import { HiChevronDown } from "react-icons/hi";
+import { FaChevronDown, FaSignOutAlt } from "react-icons/fa";
import { useGlobalContext } from "../../contexts/GlobalContext.tsx";
interface LoginFormProps {
- isAuthenticated: boolean;
+ isAuthenticated: boolean | null;
isSuperuser: boolean;
}
@@ -24,44 +20,19 @@ const Header: React.FC
= ({ isAuthenticated, isSuperuser }) => {
const dropdownRef = useRef(null);
let delayTimeout: number | null = null;
const [showChat, setShowChat] = useState(false);
- const [showLoginMenu, setShowLoginMenu] = useState(false);
- const [redirect, setRedirect] = useState(false);
const { setShowSummary, setEnterNewPatient, triggerFormReset, setIsEditing } =
useGlobalContext();
- const dispatch = useDispatch();
-
- const logout_user = () => {
- dispatch(logout());
- setRedirect(false);
- };
-
- const guestLinks = () => (
-
-
-
- Sign in
-
-
- );
-
const authLinks = () => (
-
-
-
- Sign out
-
-
+
+ Sign Out
+
+
);
- const handleLoginMenu = () => {
- setShowLoginMenu(!showLoginMenu);
- };
-
const handleMouseEnter = () => {
if (delayTimeout !== null) {
clearTimeout(delayTimeout);
@@ -102,22 +73,29 @@ const Header: React.FC = ({ isAuthenticated, isSuperuser }) => {
- Welcome to Balancer’s first release! Found a bug or have feedback? Let us know {" "}
+ Welcome to Balancer’s first release! Found a bug or have feedback? Let
+ us know{" "}
- here {" "}
+ here{" "}
- or email {" "}
-
+ or email{" "}
+
balancerteam@codeforphilly.org
.
- App is in beta; report issues to {" "}
-
+ App is in beta; report issues to{" "}
+
balancerteam@codeforphilly.org
.
@@ -133,7 +111,7 @@ const Header: React.FC = ({ isAuthenticated, isSuperuser }) => {
Balancer
-
+
handleForm()}
@@ -193,7 +171,7 @@ const Header: React.FC = ({ isAuthenticated, isSuperuser }) => {
>
Donate
- {isSuperuser && (
+ {isAuthenticated && isSuperuser && (
= ({ isAuthenticated, isSuperuser }) => {
: "absolute ml-1.5 "
}`}
>
-
+
{showFeaturesMenu && }
)}
-
- {redirect ? navigate("/") : }
>
-
- {isAuthenticated && (
-
- )}
- {/* */}
- {isAuthenticated ? authLinks() : guestLinks()}
+
+ Balancer
+
+
+ {isAuthenticated && authLinks()}
diff --git a/frontend/src/components/Header/LoginMenuDropDown.tsx b/frontend/src/components/Header/LoginMenuDropDown.tsx
deleted file mode 100644
index 427fdf07..00000000
--- a/frontend/src/components/Header/LoginMenuDropDown.tsx
+++ /dev/null
@@ -1,78 +0,0 @@
-import React from "react";
-import { Link } from "react-router-dom";
-import { classNames } from "../../utils/classNames";
-
-interface LoginMenuDropDownProps {
- showLoginMenu: boolean;
- handleLoginMenu: () => void;
-}
-
-const LoginMenuDropDown: React.FC = ({
- showLoginMenu,
-}) => {
- return (
- <>
-
-
-
-
- Balancer
-
-
-
-
- Balancer is an interactive and user-friendly research tool for bipolar
- medications, powered by Code for Philly volunteers.
-
-
- We built Balancer{" "}
-
- to improve the health and well-being of people with bipolar
- disorder.
-
-
-
- Balancer is currently still being developed, so do not take any
- information on the test site as actual medical advice.
-
-
- {/*
- You can log in or sign up for a Balancer account using your email,
- gmail or Facebook account.
-
*/}
-
-
-
- Log in
-
-
- {/*
-
- Sign up
-
- */}
-
- >
- );
-};
-
-const LoginMenu = ({ show }: { show: boolean }) => {
- if (!show) return null;
-
- return
;
-};
-
-export default LoginMenuDropDown;
diff --git a/frontend/src/components/Header/MdNavBar.tsx b/frontend/src/components/Header/MdNavBar.tsx
index 926794cf..5a8d5bce 100644
--- a/frontend/src/components/Header/MdNavBar.tsx
+++ b/frontend/src/components/Header/MdNavBar.tsx
@@ -5,11 +5,9 @@ import Chat from "./Chat";
// import logo from "../../assets/balancer.png";
import closeLogo from "../../assets/close.svg";
import hamburgerLogo from "../../assets/hamburger.svg";
-import {useDispatch} from "react-redux";
-import {logout, AppDispatch} from "../../services/actions/auth";
interface LoginFormProps {
- isAuthenticated: boolean;
+ isAuthenticated: boolean | null;
handleForm: () => void;
}
@@ -22,13 +20,6 @@ const MdNavBar = (props: LoginFormProps) => {
setNav(!nav);
};
- const dispatch = useDispatch();
-
- const logout_user = () => {
- dispatch(logout());
- };
-
-
return (
- {isAuthenticated && (
-
- )}
+
);
};
diff --git a/frontend/src/components/Header/header.css b/frontend/src/components/Header/header.css
index 4b0f4a2c..c7e807b9 100644
--- a/frontend/src/components/Header/header.css
+++ b/frontend/src/components/Header/header.css
@@ -23,7 +23,7 @@
}
.header-nav-item {
- @apply text-black border-transparent border-b-2 hover:border-blue-600 hover:text-blue-600 hover:border-b-2 hover:border-blue-600;
+ @apply text-black border-transparent border-b-2 hover:cursor-pointer hover:border-blue-600 hover:text-blue-600 hover:border-b-2 hover:border-blue-600;
}
.header-nav-item.header-nav-item-selected {
@@ -31,7 +31,7 @@
}
.subheader-nav-item {
- @apply cursor-pointer rounded-lg p-3 transition duration-300 hover:bg-gray-100;
+ @apply cursor-pointer p-3 transition duration-300 hover:bg-gray-200 border-b border-gray-200;
}
.subheader-nav-item.subheader-nav-item-selected {
diff --git a/frontend/src/components/ProtectedRoute/ProtectedRoute.tsx b/frontend/src/components/ProtectedRoute/ProtectedRoute.tsx
new file mode 100644
index 00000000..dc323217
--- /dev/null
+++ b/frontend/src/components/ProtectedRoute/ProtectedRoute.tsx
@@ -0,0 +1,31 @@
+import { ReactNode } from 'react';
+import { Navigate, useLocation } from 'react-router-dom';
+import { useSelector } from 'react-redux';
+import { RootState } from '../../services/actions/types';
+import Spinner from '../LoadingSpinner/LoadingSpinner';
+
+interface ProtectedRouteProps {
+ children: ReactNode;
+}
+
+const ProtectedRoute = ({ children }: ProtectedRouteProps) => {
+ const location = useLocation();
+ const { isAuthenticated } = useSelector((state: RootState) => state.auth);
+
+ // Wait for auth check to complete (null means not checked yet)
+ // TODO: Consider adding error handling for auth check failures
+ if (isAuthenticated === null) {
+ // TODO: Consider adding accessibility attributes (role="status", aria-live="polite", aria-label)
+ // TODO: Consider preventing Loading State Flash by adding delay before showing spinner
+ return