From ace507232a3f7af57cc282ca08499e1649be0c6c Mon Sep 17 00:00:00 2001 From: pramod mahajan Date: Mon, 8 Sep 2025 12:48:19 +0530 Subject: [PATCH 1/2] changed dashboard route "/" to "/dashboard" --- src/pages/authentication/LoginPage.jsx | 2 +- src/pages/authentication/LoginWithOtp.jsx | 2 +- src/router/AppRoutes.jsx | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/authentication/LoginPage.jsx b/src/pages/authentication/LoginPage.jsx index ab898b4c..9240e33d 100644 --- a/src/pages/authentication/LoginPage.jsx +++ b/src/pages/authentication/LoginPage.jsx @@ -44,7 +44,7 @@ const LoginPage = () => { localStorage.setItem("jwtToken", response.data.token); localStorage.setItem("refreshToken", response.data.refreshToken); setLoading(false); - navigate("/"); + navigate("/dashboard"); } else { await AuthRepository.sendOTP({ email: data.username }); showToast("OTP has been sent to your email.", "success"); diff --git a/src/pages/authentication/LoginWithOtp.jsx b/src/pages/authentication/LoginWithOtp.jsx index 73882b4f..8b07f8fb 100644 --- a/src/pages/authentication/LoginWithOtp.jsx +++ b/src/pages/authentication/LoginWithOtp.jsx @@ -52,7 +52,7 @@ const LoginWithOtp = () => { setLoading(false); localStorage.removeItem("otpUsername"); localStorage.removeItem("otpSentTime"); - navigate("/"); + navigate("/dashboard"); } catch (err) { showToast("Invalid or expired OTP.", "error"); diff --git a/src/router/AppRoutes.jsx b/src/router/AppRoutes.jsx index feb9e05f..66293637 100644 --- a/src/router/AppRoutes.jsx +++ b/src/router/AppRoutes.jsx @@ -66,7 +66,7 @@ const router = createBrowserRouter( { element: , children: [ - { path: "/", element: }, + { path: "/dashboard", element: }, { path: "/projects", element: }, { path: "/projects/details", element: }, { path: "/project/manage/:projectId", element: }, From 63a5f7b902ec989f806fda69da2594b0b9b7ee0e Mon Sep 17 00:00:00 2001 From: pramod mahajan Date: Mon, 8 Sep 2025 14:22:23 +0530 Subject: [PATCH 2/2] normalize projectId from localStorage to avoid "null" string --- src/pages/employee/EmployeeList.jsx | 10 +++++----- src/slices/apiDataManager.jsx | 17 ++++++++++++----- src/slices/localVariablesSlice.jsx | 2 +- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/pages/employee/EmployeeList.jsx b/src/pages/employee/EmployeeList.jsx index 387d6232..eaa2f950 100644 --- a/src/pages/employee/EmployeeList.jsx +++ b/src/pages/employee/EmployeeList.jsx @@ -79,11 +79,11 @@ const EmployeeList = () => { } ); - useEffect(() => { - if (selectedProjectId === null) { - dispatch(setProjectId(projectNames[0]?.id)); - } - }, [selectedProjectId]); +useEffect(() => { + if (!selectedProjectId && projectNames?.length > 0) { + dispatch(setProjectId(projectNames[0].id)); + } +}, [selectedProjectId, projectNames, dispatch]); const navigate = useNavigate(); const applySearchFilter = (data, text) => { diff --git a/src/slices/apiDataManager.jsx b/src/slices/apiDataManager.jsx index 9c3fcc1e..ad4d38a1 100644 --- a/src/slices/apiDataManager.jsx +++ b/src/slices/apiDataManager.jsx @@ -39,10 +39,17 @@ export const useSelectedProject = () => { const selectedProject = useSelector( (store) => store.localVariables.projectId ); - var project = localStorage.getItem("project"); + + const project = localStorage.getItem("project"); + if (project) { - return project; - } else { - return selectedProject; + try { + const parsed = JSON.parse(project); + return parsed ?? selectedProject; + } catch (e) { + return selectedProject; + } } -}; + + return selectedProject; +} \ No newline at end of file diff --git a/src/slices/localVariablesSlice.jsx b/src/slices/localVariablesSlice.jsx index 7c996608..0b0a8405 100644 --- a/src/slices/localVariablesSlice.jsx +++ b/src/slices/localVariablesSlice.jsx @@ -23,7 +23,7 @@ const localVariablesSlice = createSlice({ setProjectId: (state, action) => { localStorage.setItem("project",null) state.projectId = action.payload; - localStorage.setItem("project",state.projectId) + localStorage.setItem("project",state.projectId || null) }, refreshData: ( state, action ) => {