diff --git a/src/Routers/routes/ResourceRoutes.tsx b/src/Routers/routes/ResourceRoutes.tsx
index 547aeb53610..4b4f3f63c58 100644
--- a/src/Routers/routes/ResourceRoutes.tsx
+++ b/src/Routers/routes/ResourceRoutes.tsx
@@ -6,12 +6,14 @@ import { ResourceDetailsUpdate } from "@/components/Resource/ResourceDetailsUpda
import ListView from "@/components/Resource/ResourceList";
import { AppRoutes } from "@/Routers/AppRouter";
-
-const getDefaultView = () =>
- localStorage.getItem("defaultResourceView") === "list" ? "list" : "board";
+import { getDefaultView } from "@/Utils/viewStorageUtils";
const ResourceRoutes: AppRoutes = {
- "/resource": () => ,
+ "/resource": () => (
+
+ ),
"/resource/board": () => ,
"/resource/list": () => ,
"/resource/:id": ({ id }) => ,
diff --git a/src/Routers/routes/ShiftingRoutes.tsx b/src/Routers/routes/ShiftingRoutes.tsx
index 68131390f50..e59240d40d7 100644
--- a/src/Routers/routes/ShiftingRoutes.tsx
+++ b/src/Routers/routes/ShiftingRoutes.tsx
@@ -7,12 +7,12 @@ import BoardView from "@/components/Shifting/ShiftingBoard";
import ListView from "@/components/Shifting/ShiftingList";
import { AppRoutes } from "@/Routers/AppRouter";
-
-const getDefaultView = () =>
- localStorage.getItem("defaultShiftView") === "list" ? "list" : "board";
+import { getDefaultView } from "@/Utils/viewStorageUtils";
const ShiftingRoutes: AppRoutes = {
- "/shifting": () => ,
+ "/shifting": () => (
+
+ ),
"/shifting/board": () => ,
"/shifting/list": () => ,
"/shifting/:id": ({ id }) => ,
diff --git a/src/Utils/viewStorageUtils.ts b/src/Utils/viewStorageUtils.ts
new file mode 100644
index 00000000000..655ad6677cc
--- /dev/null
+++ b/src/Utils/viewStorageUtils.ts
@@ -0,0 +1,7 @@
+export const getDefaultView = (key: string, defaultValue: string): string => {
+ return localStorage.getItem(key) || defaultValue;
+};
+
+export const setDefaultView = (key: string, value: string): void => {
+ localStorage.setItem(key, value);
+};
diff --git a/src/components/Resource/ResourceBoard.tsx b/src/components/Resource/ResourceBoard.tsx
index 39b6f5184e5..300d61b89e4 100644
--- a/src/components/Resource/ResourceBoard.tsx
+++ b/src/components/Resource/ResourceBoard.tsx
@@ -25,6 +25,7 @@ import { RESOURCE_CHOICES } from "@/common/constants";
import routes from "@/Utils/request/api";
import request from "@/Utils/request/request";
+import { setDefaultView } from "@/Utils/viewStorageUtils";
const KanbanBoard = lazy(
() => import("@/components/Kanban/Board"),
@@ -47,7 +48,7 @@ export default function BoardView() {
const onListViewBtnClick = () => {
navigate("/resource/list", { query: qParams });
- localStorage.setItem("defaultResourceView", "list");
+ setDefaultView("defaultResourceView", "list");
};
return (
diff --git a/src/components/Resource/ResourceList.tsx b/src/components/Resource/ResourceList.tsx
index 0175c9d63ea..aff52f36295 100644
--- a/src/components/Resource/ResourceList.tsx
+++ b/src/components/Resource/ResourceList.tsx
@@ -22,6 +22,7 @@ import routes from "@/Utils/request/api";
import request from "@/Utils/request/request";
import useTanStackQueryInstead from "@/Utils/request/useQuery";
import { formatDateTime } from "@/Utils/utils";
+import { setDefaultView } from "@/Utils/viewStorageUtils";
export default function ListView() {
const {
@@ -37,7 +38,7 @@ export default function ListView() {
const onBoardViewBtnClick = () => {
navigate("/resource/board", { query: qParams });
- localStorage.setItem("defaultResourceView", "board");
+ setDefaultView("defaultResourceView", "board");
};
const appliedFilters = formatFilter(qParams);
diff --git a/src/components/Shifting/ShiftingBoard.tsx b/src/components/Shifting/ShiftingBoard.tsx
index 068820d3311..bad235467b0 100644
--- a/src/components/Shifting/ShiftingBoard.tsx
+++ b/src/components/Shifting/ShiftingBoard.tsx
@@ -30,6 +30,7 @@ import {
import routes from "@/Utils/request/api";
import request from "@/Utils/request/request";
+import { setDefaultView } from "@/Utils/viewStorageUtils";
const KanbanBoard = lazy(
() => import("@/components/Kanban/Board"),
@@ -78,7 +79,7 @@ export default function BoardView() {
const { t } = useTranslation();
const onListViewBtnClick = () => {
navigate("/shifting/list", { query: qParams });
- localStorage.setItem("defaultShiftView", "list");
+ setDefaultView("defaultShiftView", "list");
};
return (
diff --git a/src/components/Shifting/ShiftingList.tsx b/src/components/Shifting/ShiftingList.tsx
index e9051b1449b..d56daf2ec5f 100644
--- a/src/components/Shifting/ShiftingList.tsx
+++ b/src/components/Shifting/ShiftingList.tsx
@@ -19,6 +19,7 @@ import useFilters from "@/hooks/useFilters";
import routes from "@/Utils/request/api";
import request from "@/Utils/request/request";
import useTanStackQueryInstead from "@/Utils/request/useQuery";
+import { setDefaultView } from "@/Utils/viewStorageUtils";
import ShiftingTable from "./ShiftingTable";
@@ -35,7 +36,7 @@ export default function ListView() {
const { t } = useTranslation();
const onBoardViewBtnClick = () => {
navigate("/shifting/board", { query: qParams });
- localStorage.setItem("defaultShiftView", "board");
+ setDefaultView("defaultShiftView", "board");
};
const {
data: shiftData,
diff --git a/src/components/Users/ManageUsers.tsx b/src/components/Users/ManageUsers.tsx
index 0851a186728..e2ab7f319e7 100644
--- a/src/components/Users/ManageUsers.tsx
+++ b/src/components/Users/ManageUsers.tsx
@@ -27,6 +27,7 @@ import routes from "@/Utils/request/api";
import request from "@/Utils/request/request";
import useTanStackQueryInstead from "@/Utils/request/useQuery";
import { classNames } from "@/Utils/utils";
+import { getDefaultView, setDefaultView } from "@/Utils/viewStorageUtils";
export default function ManageUsers() {
const { t } = useTranslation();
@@ -47,7 +48,9 @@ export default function ManageUsers() {
const userTypes = authUser.is_superuser
? [...USER_TYPES]
: USER_TYPES.slice(0, userIndex + 1);
- const [activeTab, setActiveTab] = useState(0);
+ const [activeTab, setActiveTab] = useState(
+ getDefaultView("usersDefaultView", "card") === "list" ? 1 : 0,
+ );
const { data: homeFacilityData } = useTanStackQueryInstead(
routes.getAnyFacility,
@@ -105,6 +108,11 @@ export default function ManageUsers() {
if (userListLoading || districtDataLoading || !userListData?.results) {
return ;
}
+ const handleTabChange = (tab: number) => {
+ setActiveTab(tab);
+ const newView = tab === 1 ? "list" : "card";
+ setDefaultView("usersDefaultView", newView);
+ };
manageUsers = (
@@ -113,7 +121,7 @@ export default function ManageUsers() {
onSearch={(username) => updateQuery({ username })}
searchValue={qParams.username}
activeTab={activeTab}
- onTabChange={setActiveTab}
+ onTabChange={handleTabChange}
/>