Skip to content

Commit 11e84f5

Browse files
authored
Merge pull request #377 from StubberG3/balancer/309/login
Balancer/309/login
2 parents bae4e1c + 9a15d55 commit 11e84f5

24 files changed

Lines changed: 150 additions & 282 deletions

File tree

frontend/src/api/apiClient.ts

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const handleSubmitFeedback = async (
3131
message: FormValues["message"],
3232
) => {
3333
try {
34-
const response = await api.post(`/v1/api/feedback/`, {
34+
const response = await publicApi.post(`/v1/api/feedback/`, {
3535
feedbacktype: feedbackType,
3636
name,
3737
email,
@@ -49,10 +49,8 @@ const handleSendDrugSummary = async (
4949
guid: string,
5050
) => {
5151
try {
52-
const endpoint = guid
53-
? `/v1/api/embeddings/ask_embeddings?guid=${guid}`
54-
: "/v1/api/embeddings/ask_embeddings";
55-
const response = await api.post(endpoint, {
52+
const endpoint = guid ? `/v1/api/embeddings/ask_embeddings?guid=${guid}` : '/v1/api/embeddings/ask_embeddings';
53+
const response = await adminApi.post(endpoint, {
5654
message,
5755
});
5856
console.log("Response data:", JSON.stringify(response.data, null, 2));
@@ -65,9 +63,7 @@ const handleSendDrugSummary = async (
6563

6664
const handleRuleExtraction = async (guid: string) => {
6765
try {
68-
const response = await api.get(
69-
`/v1/api/rule_extraction_openai?guid=${guid}`,
70-
);
66+
const response = await adminApi.get(`/v1/api/rule_extraction_openai?guid=${guid}`);
7167
// console.log("Rule extraction response:", JSON.stringify(response.data, null, 2));
7268
return response.data;
7369
} catch (error) {
@@ -81,7 +77,7 @@ const fetchRiskDataWithSources = async (
8177
source: "include" | "diagnosis" | "diagnosis_depressed" = "include",
8278
) => {
8379
try {
84-
const response = await api.post(`/v1/api/riskWithSources`, {
80+
const response = await publicApi.post(`/v1/api/riskWithSources`, {
8581
drug: medication,
8682
source: source,
8783
});
@@ -210,7 +206,7 @@ const handleSendDrugSummaryStreamLegacy = async (
210206

211207
const fetchConversations = async (): Promise<Conversation[]> => {
212208
try {
213-
const response = await api.get(`/chatgpt/conversations/`);
209+
const response = await publicApi.get(`/chatgpt/conversations/`);
214210
return response.data;
215211
} catch (error) {
216212
console.error("Error(s) during getConversations: ", error);
@@ -220,7 +216,7 @@ const fetchConversations = async (): Promise<Conversation[]> => {
220216

221217
const fetchConversation = async (id: string): Promise<Conversation> => {
222218
try {
223-
const response = await api.get(`/chatgpt/conversations/${id}/`);
219+
const response = await publicApi.get(`/chatgpt/conversations/${id}/`);
224220
return response.data;
225221
} catch (error) {
226222
console.error("Error(s) during getConversation: ", error);
@@ -230,7 +226,7 @@ const fetchConversation = async (id: string): Promise<Conversation> => {
230226

231227
const newConversation = async (): Promise<Conversation> => {
232228
try {
233-
const response = await api.post(`/chatgpt/conversations/`, {
229+
const response = await adminApi.post(`/chatgpt/conversations/`, {
234230
messages: [],
235231
});
236232
return response.data;
@@ -246,7 +242,7 @@ const continueConversation = async (
246242
page_context?: string,
247243
): Promise<{ response: string; title: Conversation["title"] }> => {
248244
try {
249-
const response = await api.post(
245+
const response = await adminApi.post(
250246
`/chatgpt/conversations/${id}/continue_conversation/`,
251247
{
252248
message,
@@ -262,7 +258,7 @@ const continueConversation = async (
262258

263259
const deleteConversation = async (id: string) => {
264260
try {
265-
const response = await api.delete(`/chatgpt/conversations/${id}/`);
261+
const response = await adminApi.delete(`/chatgpt/conversations/${id}/`);
266262
return response.data;
267263
} catch (error) {
268264
console.error("Error(s) during deleteConversation: ", error);
@@ -277,12 +273,9 @@ const updateConversationTitle = async (
277273
{ status: string; title: Conversation["title"] } | { error: string }
278274
> => {
279275
try {
280-
const response = await api.patch(
281-
`/chatgpt/conversations/${id}/update_title/`,
282-
{
283-
title: newTitle,
284-
},
285-
);
276+
const response = await adminApi.patch(`/chatgpt/conversations/${id}/update_title/`, {
277+
title: newTitle,
278+
});
286279
return response.data;
287280
} catch (error) {
288281
console.error("Error(s) during getConversation: ", error);

frontend/src/components/Header/FeatureMenuDropDown.tsx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ export const FeatureMenuDropDown = () => {
44
const location = useLocation();
55
const currentPath = location.pathname;
66
return (
7-
<div className="h-50 absolute top-full mb-2 mt-2 flex flex-row items-center rounded-lg border-2 bg-white font-inter text-sm sm:px-6 md:px-8 lg:px-8 xl:px-6 ">
8-
<div className="mx-3 my-5 ">
7+
<div className="h-50 absolute top-full mb-2 mt-2 flex flex-row items-center rounded-lg border-2 bg-white font-satoshi text-sm">
8+
<div className="">
99
<Link to="/AdminPortal">
1010
<ul className={currentPath === "/AdminPortal" ? "subheader-nav-item subheader-nav-item-selected" : "subheader-nav-item"}>
1111
<span className="font-bold">Manage files</span>
1212

13-
<div className="mt-1 font-satoshi text-sm text-gray-400">
13+
<div className="font-normal mt-1 text-gray-600">
1414
Manage and chat with files
1515
</div>
1616
</ul>
@@ -19,7 +19,7 @@ export const FeatureMenuDropDown = () => {
1919
<ul className={currentPath === "/rulesmanager" ? "subheader-nav-item subheader-nav-item-selected" : "subheader-nav-item"}>
2020
<span className="font-bold">Manage rules</span>
2121

22-
<div className="mt-1 font-satoshi text-sm text-gray-400">
22+
<div className="font-normal mt-1 text-gray-600">
2323
Manage list of rules
2424
</div>
2525
</ul>
@@ -28,7 +28,7 @@ export const FeatureMenuDropDown = () => {
2828
<ul className={currentPath === "/ManageMeds" ? "subheader-nav-item subheader-nav-item-selected" : "subheader-nav-item"}>
2929
<span className="font-bold">Manage meds</span>
3030

31-
<div className="mt-1 font-satoshi text-sm text-gray-400">
31+
<div className="font-normal mt-1 text-gray-600">
3232
Manage list of meds
3333
</div>
3434
</ul>

frontend/src/components/Header/Header.tsx

Lines changed: 14 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
1-
import { useState, useRef, useEffect, Fragment } from "react";
2-
// import { useState, Fragment } from "react";
3-
import accountLogo from "../../assets/account.svg";
1+
import { useState, useRef, useEffect } from "react";
42
import { Link, useNavigate, useLocation } from "react-router-dom";
5-
import LoginMenuDropDown from "./LoginMenuDropDown";
63
import "../../components/Header/header.css";
74
import Chat from "./Chat";
85
import { FeatureMenuDropDown } from "./FeatureMenuDropDown";
96
import MdNavBar from "./MdNavBar";
10-
import { connect, useDispatch } from "react-redux";
7+
import { connect } from "react-redux";
118
import { RootState } from "../../services/actions/types";
12-
import { logout, AppDispatch } from "../../services/actions/auth";
13-
import { HiChevronDown } from "react-icons/hi";
9+
import { FaChevronDown, FaSignOutAlt } from "react-icons/fa";
1410
import { useGlobalContext } from "../../contexts/GlobalContext.tsx";
1511

1612
interface LoginFormProps {
@@ -24,44 +20,16 @@ const Header: React.FC<LoginFormProps> = ({ isAuthenticated, isSuperuser }) => {
2420
const dropdownRef = useRef(null);
2521
let delayTimeout: number | null = null;
2622
const [showChat, setShowChat] = useState(false);
27-
const [showLoginMenu, setShowLoginMenu] = useState(false);
28-
const [redirect, setRedirect] = useState(false);
2923
const { setShowSummary, setEnterNewPatient, triggerFormReset, setIsEditing } =
3024
useGlobalContext();
3125

32-
const dispatch = useDispatch<AppDispatch>();
33-
34-
const logout_user = () => {
35-
dispatch(logout());
36-
setRedirect(false);
37-
};
38-
39-
const guestLinks = () => (
40-
<nav onClick={handleLoginMenu} className="flex cursor-pointer items-center">
41-
<img
42-
src={accountLogo}
43-
alt="logo"
44-
className="mr-5 h-5 object-contain lg:h-4 "
45-
/>
46-
<span className=" text-black hover:border-b-2 hover:border-blue-600 hover:text-black hover:no-underline lg:text-sm xl:text-lg">
47-
Sign in
48-
</span>
49-
</nav>
50-
);
51-
5226
const authLinks = () => (
53-
<nav onClick={logout_user} className="flex cursor-pointer items-center">
54-
<img src={accountLogo} alt="logo" className="mr-5 h-5 object-contain " />
55-
<span className=" text-black hover:border-b-2 hover:border-blue-600 hover:text-black hover:no-underline lg:text-sm xl:text-lg">
56-
Sign out
57-
</span>
58-
</nav>
27+
<Link to="/logout" className="font-satoshi flex cursor-pointer items-center text-black hover:text-blue-600">
28+
Sign Out
29+
<FaSignOutAlt className="ml-2 inline-block" />
30+
</Link>
5931
);
6032

61-
const handleLoginMenu = () => {
62-
setShowLoginMenu(!showLoginMenu);
63-
};
64-
6533
const handleMouseEnter = () => {
6634
if (delayTimeout !== null) {
6735
clearTimeout(delayTimeout);
@@ -126,7 +94,7 @@ const Header: React.FC<LoginFormProps> = ({ isAuthenticated, isSuperuser }) => {
12694
Balancer
12795
</span>
12896
</Link>
129-
<nav className=" flex space-x-2 font-satoshi lg:space-x-3 xl:gap-3 xl:font-bold ">
97+
<nav className="flex space-x-2 font-satoshi lg:space-x-3 xl:gap-3 xl:font-bold ">
13098
<Link
13199
to="/"
132100
onClick={() => handleForm()}
@@ -186,7 +154,7 @@ const Header: React.FC<LoginFormProps> = ({ isAuthenticated, isSuperuser }) => {
186154
>
187155
Donate
188156
</a>
189-
{isSuperuser && (
157+
{(isAuthenticated && isSuperuser) && (
190158
<div
191159
onMouseEnter={handleMouseEnter}
192160
onMouseLeave={handleMouseLeave}
@@ -210,25 +178,20 @@ const Header: React.FC<LoginFormProps> = ({ isAuthenticated, isSuperuser }) => {
210178
: "absolute ml-1.5 "
211179
}`}
212180
>
213-
<HiChevronDown className="inline-block" />
181+
<FaChevronDown className="inline-block" />
214182
</span>
215183
</span>
216184
{showFeaturesMenu && <FeatureMenuDropDown />}
217185
</div>
218186
)}
219-
220-
{redirect ? navigate("/") : <Fragment></Fragment>}
221187
</>
222188
</nav>
223-
<LoginMenuDropDown
224-
showLoginMenu={showLoginMenu}
225-
handleLoginMenu={handleLoginMenu}
226-
/>
227189
{isAuthenticated && (
228-
<Chat showChat={showChat} setShowChat={setShowChat} />
190+
<>
191+
<Chat showChat={showChat} setShowChat={setShowChat} />
192+
</>
229193
)}
230-
{/* <Chat showChat={showChat} setShowChat={setShowChat} /> */}
231-
{isAuthenticated ? authLinks() : guestLinks()}
194+
{isAuthenticated && authLinks()}
232195
</div>
233196
<MdNavBar handleForm={handleForm} isAuthenticated={isAuthenticated} />
234197
</header>

frontend/src/components/Header/LoginMenuDropDown.tsx

Lines changed: 0 additions & 78 deletions
This file was deleted.

frontend/src/components/Header/MdNavBar.tsx

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ import Chat from "./Chat";
55
// import logo from "../../assets/balancer.png";
66
import closeLogo from "../../assets/close.svg";
77
import hamburgerLogo from "../../assets/hamburger.svg";
8-
import {useDispatch} from "react-redux";
9-
import {logout, AppDispatch} from "../../services/actions/auth";
108

119
interface LoginFormProps {
1210
isAuthenticated: boolean;
@@ -22,13 +20,6 @@ const MdNavBar = (props: LoginFormProps) => {
2220
setNav(!nav);
2321
};
2422

25-
const dispatch = useDispatch<AppDispatch>();
26-
27-
const logout_user = () => {
28-
dispatch(logout());
29-
};
30-
31-
3223
return (
3324
<div
3425
className={
@@ -131,20 +122,19 @@ const MdNavBar = (props: LoginFormProps) => {
131122
<li className="border-b border-gray-300 p-4">
132123
<a href="https://www.flipcause.com/secure/cause_pdetails/MjMyMTIw"
133124
target="_blank"
134-
className="text-black hover:border-blue-600 hover:text-blue-600 hover:no-underline"
125+
className="mr-9 text-black hover:border-b-2 hover:border-blue-600 hover:text-black hover:no-underline"
135126
>
136127
Donate
137128
</a>
138129
</li>
139130
{isAuthenticated &&
140-
<li className="border-b border-gray-300 p-4">
141-
<a
142-
onClick={logout_user}
143-
className="mr-9 text-black hover:border-b-2 hover:border-blue-600 hover:text-black hover:no-underline"
144-
>
145-
Sign Out
146-
</a>
147-
</li>
131+
<li className="border-b border-gray-300 p-4">
132+
<Link
133+
to="/logout"
134+
className="mr-9 text-black hover:border-b-2 hover:border-blue-600 hover:text-black hover:no-underline"
135+
>Sign Out
136+
</Link>
137+
</li>
148138
}
149139
</ul>
150140
</div>

0 commit comments

Comments
 (0)