Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix : View Retention in Users Tab After Navigation #9485

Closed
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
51a053e
list and view card view
Mahendar0701 Dec 18, 2024
79fafe7
removed dediacted links for users view
Mahendar0701 Dec 18, 2024
fb3a446
Merge branch 'develop' into list-and-card-view-in-users-tab
Mahendar0701 Dec 18, 2024
8af90dd
Merge branch 'develop' into list-and-card-view-in-users-tab
Mahendar0701 Dec 18, 2024
71ac706
removed dediacted links for users view
Mahendar0701 Dec 18, 2024
db15f8b
changes
Mahendar0701 Dec 18, 2024
2430231
Merge branch 'develop' into list-and-card-view-in-users-tab
Mahendar0701 Dec 19, 2024
e0eb9d8
Merge branch 'develop' into list-and-card-view-in-users-tab
Mahendar0701 Dec 20, 2024
a939247
created view util
Mahendar0701 Dec 22, 2024
c7808ad
Merge branch 'develop' into list-and-card-view-in-users-tab
Mahendar0701 Dec 22, 2024
249be67
resolved conflicts
Mahendar0701 Dec 23, 2024
f785378
Merge branch 'develop' into list-and-card-view-in-users-tab
Mahendar0701 Dec 23, 2024
b14a320
clear view cache
Mahendar0701 Dec 26, 2024
ffa3559
Merge branch 'develop' into list-and-card-view-in-users-tab
Mahendar0701 Dec 26, 2024
d7f0669
Merge branch 'list-and-card-view-in-users-tab' of https://github.com/…
Mahendar0701 Dec 26, 2024
3a62c2f
Merge branch 'develop' into list-and-card-view-in-users-tab
Mahendar0701 Dec 27, 2024
609f723
Merge branch 'develop' into list-and-card-view-in-users-tab
Mahendar0701 Dec 28, 2024
0724ab4
Merge branch 'develop' into list-and-card-view-in-users-tab
Mahendar0701 Dec 29, 2024
1efe9f5
Merge branch 'develop' into list-and-card-view-in-users-tab
Mahendar0701 Dec 30, 2024
91765fd
updated view for facility users
Mahendar0701 Dec 30, 2024
1ac3800
Merge branch 'list-and-card-view-in-users-tab' of https://github.com/…
Mahendar0701 Dec 30, 2024
84b32c0
merge conflicts
Mahendar0701 Dec 31, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/Routers/routes/ResourceRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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": () => <Redirect to={`/resource/${getDefaultView()}`} />,
"/resource": () => (
<Redirect
to={`/resource/${getDefaultView("defaultResourceView", "board")}`}
/>
),
Mahendar0701 marked this conversation as resolved.
Show resolved Hide resolved
"/resource/board": () => <BoardView />,
"/resource/list": () => <ListView />,
"/resource/:id": ({ id }) => <ResourceDetails id={id} />,
Expand Down
8 changes: 4 additions & 4 deletions src/Routers/routes/ShiftingRoutes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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": () => <Redirect to={`/shifting/${getDefaultView()}`} />,
"/shifting": () => (
<Redirect to={`/shifting/${getDefaultView("defaultShiftView", "board")}`} />
),
"/shifting/board": () => <BoardView />,
"/shifting/list": () => <ListView />,
"/shifting/:id": ({ id }) => <ShiftDetails id={id} />,
Expand Down
7 changes: 7 additions & 0 deletions src/Utils/viewStorageUtils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export const getDefaultView = (key: string, defaultValue: string): string => {
return localStorage.getItem(key) || defaultValue;
};
Mahendar0701 marked this conversation as resolved.
Show resolved Hide resolved

export const setDefaultView = (key: string, value: string): void => {
localStorage.setItem(key, value);
};
Mahendar0701 marked this conversation as resolved.
Show resolved Hide resolved
Mahendar0701 marked this conversation as resolved.
Show resolved Hide resolved
3 changes: 2 additions & 1 deletion src/components/Resource/ResourceBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -47,7 +48,7 @@ export default function BoardView() {

const onListViewBtnClick = () => {
navigate("/resource/list", { query: qParams });
localStorage.setItem("defaultResourceView", "list");
setDefaultView("defaultResourceView", "list");
};

return (
Expand Down
3 changes: 2 additions & 1 deletion src/components/Resource/ResourceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion src/components/Shifting/ShiftingBoard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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 (
Expand Down
3 changes: 2 additions & 1 deletion src/components/Shifting/ShiftingList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand All @@ -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,
Expand Down
12 changes: 10 additions & 2 deletions src/components/Users/ManageUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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,
Expand Down Expand Up @@ -105,6 +108,11 @@ export default function ManageUsers() {
if (userListLoading || districtDataLoading || !userListData?.results) {
return <Loading />;
}
const handleTabChange = (tab: number) => {
setActiveTab(tab);
const newView = tab === 1 ? "list" : "card";
setDefaultView("usersDefaultView", newView);
};

manageUsers = (
<div>
Expand All @@ -113,7 +121,7 @@ export default function ManageUsers() {
onSearch={(username) => updateQuery({ username })}
searchValue={qParams.username}
activeTab={activeTab}
onTabChange={setActiveTab}
onTabChange={handleTabChange}
/>
<Pagination totalCount={userListData.count} />
</div>
Expand Down
Loading