Skip to content

Commit dc30c6f

Browse files
committed
Patient Context renamed to GlobalContext. Patient Summary Opens on new Request. Patient List opens on click. Is Editing and Balancer logo clash resolved. List of patients text box set to inline-block.
1 parent d21f6b4 commit dc30c6f

6 files changed

Lines changed: 42 additions & 25 deletions

File tree

frontend/src/App.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@ import "./App.css";
22
import {DarkModeProvider} from "./contexts/DarkModeContext";
33
import Layout from "./pages/Layout/Layout";
44
import PatientManager from "./pages/PatientManager/PatientManager";
5-
import {PatientProvider} from "./contexts/PatientContext.tsx";
5+
import {GlobalProvider} from "./contexts/GlobalContext.tsx";
66

77
const App = () => {
88
return (
99
<DarkModeProvider>
10-
<PatientProvider>
10+
<GlobalProvider>
1111
<Layout>
1212
<PatientManager/>
1313
</Layout>
14-
</PatientProvider>
14+
</GlobalProvider>
1515
</DarkModeProvider>
1616
);
1717
};

frontend/src/components/Header/Header.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {connect, useDispatch} from "react-redux";
1111
import {RootState} from "../../services/actions/types";
1212
import {logout, AppDispatch} from "../../services/actions/auth";
1313
import {HiChevronDown} from "react-icons/hi";
14-
import {usePatientContext} from "../../contexts/PatientContext.tsx";
14+
import {useGlobalContext} from "../../contexts/GlobalContext.tsx";
1515

1616
interface LoginFormProps {
1717
isAuthenticated: boolean;
@@ -29,7 +29,7 @@ const Header: React.FC<LoginFormProps> = ({
2929
const [showChat, setShowChat] = useState(false);
3030
const [showLoginMenu, setShowLoginMenu] = useState(false);
3131
const [redirect, setRedirect] = useState(false);
32-
const {setShowSummary, setEnterNewPatient, triggerFormReset} = usePatientContext()
32+
const {setShowSummary, setEnterNewPatient, triggerFormReset, setIsEditing} = useGlobalContext()
3333

3434
const dispatch = useDispatch<AppDispatch>();
3535

@@ -91,6 +91,7 @@ const Header: React.FC<LoginFormProps> = ({
9191

9292

9393
const handleForm = () => {
94+
setIsEditing(false);
9495
triggerFormReset();
9596
setEnterNewPatient(true);
9697
setShowSummary(false);
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,43 @@
1-
// Update PatientContext.tsx to include the reset functionality
21
import React, {createContext, useContext, useState} from 'react';
32

4-
interface PatientContextType {
3+
interface GlobalContextType {
54
showSummary: boolean;
65
setShowSummary: React.Dispatch<React.SetStateAction<boolean>>;
76
enterNewPatient: boolean;
87
setEnterNewPatient: React.Dispatch<React.SetStateAction<boolean>>;
98
resetFormValues: boolean;
109
triggerFormReset: () => void;
10+
isEditing: boolean;
11+
setIsEditing: React.Dispatch<React.SetStateAction<boolean>>;
1112
}
1213

1314

1415
//redux / context issue need to provide default to avoid undefined
1516
//if we don't the login errors out
16-
const defaultContextValue: PatientContextType = {
17-
enterNewPatient: true,
17+
const defaultContextValue: GlobalContextType = {
18+
enterNewPatient: false,
1819
setEnterNewPatient: () => {
1920
}, //no-op default
20-
showSummary: true,
21+
showSummary: false,
2122
setShowSummary: () => {
2223
}, //no-op default
2324
resetFormValues: false,
2425
triggerFormReset: () => {
2526
}, //no-op default
27+
isEditing: false,
28+
setIsEditing: () => {
29+
}, //no-op default
2630
};
2731

2832

29-
const PatientContext = createContext<PatientContextType>(defaultContextValue);
33+
const GlobalContext = createContext<GlobalContextType>(defaultContextValue);
3034

3135

32-
export const PatientProvider: React.FC<{ children: React.ReactNode }> = ({children}) => {
36+
export const GlobalProvider: React.FC<{ children: React.ReactNode }> = ({children}) => {
3337
const [showSummary, setShowSummary] = useState<boolean>(false);
3438
const [enterNewPatient, setEnterNewPatient] = useState<boolean>(true);
3539
const [resetFormValues, setResetFormValues] = useState<boolean>(false);
36-
40+
const [isEditing, setIsEditing] = useState<boolean>(false);
3741

3842
const triggerFormReset = () => {
3943
setResetFormValues(true);
@@ -44,25 +48,27 @@ export const PatientProvider: React.FC<{ children: React.ReactNode }> = ({childr
4448
};
4549

4650
return (
47-
<PatientContext.Provider
51+
<GlobalContext.Provider
4852
value={{
4953
showSummary,
5054
setShowSummary,
5155
enterNewPatient,
5256
setEnterNewPatient,
5357
resetFormValues,
54-
triggerFormReset
58+
triggerFormReset,
59+
isEditing,
60+
setIsEditing
5561
}}
5662
>
5763
{children}
58-
</PatientContext.Provider>
64+
</GlobalContext.Provider>
5965
);
6066
};
6167

62-
export const usePatientContext = () => {
63-
const context = useContext(PatientContext);
68+
export const useGlobalContext = () => {
69+
const context = useContext(GlobalContext);
6470
if (context === undefined) {
65-
throw new Error('usePatientContext must be used within a PatientProvider');
71+
throw new Error('useGlobalContext must be used within a GlobalProvider');
6672
}
6773
return context;
6874
};

frontend/src/pages/PatientManager/NewPatientForm.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {useMedications} from "../ListMeds/useMedications";
55
import ChipsInput from "../../components/ChipsInput/ChipsInput";
66
import Tooltip from "../../components/Tooltip";
77
import {api} from "../../api/apiClient";
8-
import {usePatientContext} from "../../contexts/PatientContext.tsx";
8+
import {useGlobalContext} from "../../contexts/GlobalContext.tsx";
99
// import ErrorMessage from "../../components/ErrorMessage";
1010

1111
// create new interface for refactor and to work with backend
@@ -62,7 +62,7 @@ const NewPatientForm = ({
6262
const [isPressed, setIsPressed] = useState(false);
6363
const [isLoading, setIsLoading] = useState(false);
6464

65-
const {resetFormValues} = usePatientContext();
65+
const {resetFormValues, setShowSummary} = useGlobalContext();
6666

6767
useEffect(() => {
6868
if (resetFormValues) {
@@ -188,6 +188,7 @@ const NewPatientForm = ({
188188
// Update state and localStorage
189189
setPatientInfo(updatedPatientInfo);
190190
setAllPatientInfo(updatedAllPatientInfo);
191+
setShowSummary(true)
191192
localStorage.setItem(
192193
"patientInfos",
193194
JSON.stringify(updatedAllPatientInfo)

frontend/src/pages/PatientManager/PatientHistory.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import {FaUser, FaTrash, FaRegThumbsDown} from "react-icons/fa";
33
import {useState} from "react";
44
import FeedbackForm from "../Feedback/FeedbackForm"
55
import Modal from "../../components/Modal/Modal";
6+
import {useGlobalContext} from "../../contexts/GlobalContext.tsx";
67

78
export interface PatientHistoryProps {
89
allPatientInfo: PatientInfo[];
@@ -21,6 +22,7 @@ const PatientHistory = ({
2122
}: PatientHistoryProps) => {
2223

2324
const [isModalOpen, setIsModalOpen] = useState({status: false, id: ''});
25+
const {setShowSummary} = useGlobalContext()
2426

2527
const handleOpenModal = (id: string, event: React.MouseEvent) => {
2628
event.stopPropagation();
@@ -54,7 +56,7 @@ const PatientHistory = ({
5456
<div className=" md:mx-0 md:p-0 ">
5557
<br/>
5658
{allPatientInfo.length > 0 && (
57-
<h2 className="header_logo cursor-pointer font-satoshi text-xl font-bold text-gray-600 hover:text-blue-600 no-print">
59+
<h2 className="header_logo inline-block cursor-pointer font-satoshi text-xl font-bold text-gray-600 hover:text-blue-600 no-print">
5860
List of Patients
5961
{/* <span className="blue_gradient">Patients</span> */}
6062
</h2>
@@ -64,6 +66,7 @@ const PatientHistory = ({
6466
key={`link-${index}`}
6567
onClick={() => {
6668
setPatientInfo(item);
69+
setShowSummary(true)
6770
window.scrollTo(0, 0); // This line makes the page scroll to the top
6871
}}
6972
className="font_body mb-3 flex justify-between cursor-pointer rounded-md border bg-white p-3 px-3 py-2.5 pl-5 ring-1 hover:ring-slate-300 md:p-2 md:px-6 lg:w-[860px] no-print items-center"

frontend/src/pages/PatientManager/PatientManager.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import PatientSummary from "./PatientSummary.tsx";
88
import {Diagnosis, PatientInfo} from "./PatientTypes.ts";
99
import {copy} from "../../assets/index.js";
1010
import Welcome from "../../components/Welcome/Welcome.tsx";
11-
import {usePatientContext} from "../../contexts/PatientContext.tsx";
11+
import {useGlobalContext} from "../../contexts/GlobalContext.tsx";
1212

1313
const PatientManager = () => {
1414

@@ -67,9 +67,15 @@ const PatientManager = () => {
6767
};
6868

6969
const [allPatientInfo, setAllPatientInfo] = useState<PatientInfo[]>([]);
70-
const [isEditing, setIsEditing] = useState<boolean>(false);
7170
const [isPatientDeleted, setIsPatientDeleted] = useState<boolean>(false);
72-
const {showSummary, setShowSummary, enterNewPatient, setEnterNewPatient} = usePatientContext();
71+
const {
72+
showSummary,
73+
setShowSummary,
74+
enterNewPatient,
75+
setEnterNewPatient,
76+
isEditing,
77+
setIsEditing
78+
} = useGlobalContext();
7379

7480
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
7581
// @ts-ignore

0 commit comments

Comments
 (0)