From 88410b3fc95594aa143b3b2770963e7ef601e184 Mon Sep 17 00:00:00 2001 From: Joacim Delfin Sveen Date: Mon, 24 Jun 2024 09:30:33 +0200 Subject: [PATCH 1/3] Handles employeeProfile the same time as userInfo --- apps/web/src/context/UserInfoContext.tsx | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/apps/web/src/context/UserInfoContext.tsx b/apps/web/src/context/UserInfoContext.tsx index 44e3d771..7d7b2a68 100644 --- a/apps/web/src/context/UserInfoContext.tsx +++ b/apps/web/src/context/UserInfoContext.tsx @@ -25,9 +25,16 @@ const UserInfoProvider: React.FC<{ children: React.ReactNode }> = ({ try { const user = await getUserInfo() setUserInfo(user) + + if (user) { + const userEmail = user.email?.toLowerCase() + const employeeProfile = await getEmployeeProfile(userEmail) + setUserEmployeeProfile(employeeProfile) + } } catch (error) { if (isError(error)) { setUserInfo(null) + setUserEmployeeProfile(null) } } } @@ -35,22 +42,6 @@ const UserInfoProvider: React.FC<{ children: React.ReactNode }> = ({ fetchUser() }, []) - useEffect(() => { - async function fetchEmployeeProfile() { - if (userInfo) { - const userEmail = userInfo.email?.toLowerCase() - if (userEmail) { - const data = await getEmployeeProfile(userEmail) - setUserEmployeeProfile(data) - } - } else { - setUserEmployeeProfile(null) - } - } - - fetchEmployeeProfile() - }, [userInfo]) - return ( Date: Mon, 24 Jun 2024 09:31:10 +0200 Subject: [PATCH 2/3] Updated webRoot in launch.json --- .vscode/launch.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index df9cf0c6..a37decd0 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -9,7 +9,7 @@ "request": "launch", "name": "Launch Chrome against localhost", "url": "https://localhost:3000", - "webRoot": "${workspaceFolder}/apps/website" + "webRoot": "${workspaceFolder}/apps/web" } ] } From d3b1e1560fac9512bafb3d794161db343f92b859 Mon Sep 17 00:00:00 2001 From: Joacim Delfin Sveen Date: Mon, 24 Jun 2024 09:51:26 +0200 Subject: [PATCH 3/3] Added extra if-statement to stop uneccessary api-call --- apps/web/src/context/UserInfoContext.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/web/src/context/UserInfoContext.tsx b/apps/web/src/context/UserInfoContext.tsx index 7d7b2a68..75632b8c 100644 --- a/apps/web/src/context/UserInfoContext.tsx +++ b/apps/web/src/context/UserInfoContext.tsx @@ -28,8 +28,10 @@ const UserInfoProvider: React.FC<{ children: React.ReactNode }> = ({ if (user) { const userEmail = user.email?.toLowerCase() - const employeeProfile = await getEmployeeProfile(userEmail) - setUserEmployeeProfile(employeeProfile) + if (userEmail) { + const employeeProfile = await getEmployeeProfile(userEmail) + setUserEmployeeProfile(employeeProfile) + } } } catch (error) { if (isError(error)) {