Skip to content

Commit

Permalink
updated facility-user(changes required)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeffrin2005 committed Jan 7, 2025
1 parent aefe830 commit 0a7be59
Showing 1 changed file with 7 additions and 17 deletions.
24 changes: 7 additions & 17 deletions src/components/Facility/FacilityUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,42 +9,34 @@ import UserListView from "@/components/Users/UserListAndCard";

import useFilters from "@/hooks/useFilters";

import { RESULTS_PER_PAGE_LIMIT } from "@/common/constants";

import routes from "@/Utils/request/api";
import query from "@/Utils/request/query";

export default function FacilityUsers(props: { facilityId: number }) {
const { t } = useTranslation();
const { qParams, updateQuery, Pagination } = useFilters({
limit: 18,
limit: RESULTS_PER_PAGE_LIMIT,
cacheBlacklist: ["username"],
});
const [activeTab, setActiveTab] = useState(0);
const { facilityId } = props;
const { username } = qParams;

const handleSearch = (key: string, value: string) => {
updateQuery({
...qParams,
[key]: value || undefined,
});
};

const { data: userListData, isLoading: userListLoading } = useQuery({
queryKey: ["facilityUsers", facilityId, qParams],
queryFn: query(routes.facility.getUsers, {
pathParams: { facility_id: facilityId },
queryParams: {
username,
limit: qParams.limit || 18,
offset: ((qParams.page || 1) - 1) * (qParams.limit || 18),
limit: qParams.limit,
offset: (qParams.page - 1) * qParams.limit,
},
}),
enabled: !!facilityId,
});

if (userListLoading) {
return <div>Loading...</div>;
}
if (!userListData) {
return <div>{t("no_users_found")}</div>;
}
Expand All @@ -61,15 +53,13 @@ export default function FacilityUsers(props: { facilityId: number }) {

<UserListView
users={userListData?.results ?? []}
onSearch={(username) => handleSearch("username", username)}
onSearch={(username) => updateQuery({ username })}
searchValue={username || ""}
activeTab={activeTab}
onTabChange={setActiveTab}
/>

{userListData.count > (qParams.limit || 18) && (
<Pagination totalCount={userListData.count} />
)}
<Pagination totalCount={userListData.count} />
</Page>
);
}

0 comments on commit 0a7be59

Please sign in to comment.