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

Fixed : User Search Bar #9750

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 19 additions & 22 deletions src/components/Facility/FacilityUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,17 @@ import useFilters from "@/hooks/useFilters";

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

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

const { data: facilityData } = useTanStackQueryInstead(
routes.getAnyFacility,
{
pathParams: {
id: facilityId,
},
prefetch: facilityId !== undefined,
},
);

const { data: userListData, isLoading: userListLoading } = useQuery({
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const { data: userListData, isLoading: userListLoading } = useQuery({
const { data, isLoading } = useQuery({

queryKey: ["facilityUsers", facilityId],
queryFn: query(routes.facility.getUsers, {
Expand All @@ -43,16 +33,23 @@ export default function FacilityUsers(props: { facilityId: number }) {
if (userListLoading) {
return <div>Loading...</div>;
}
if (!userListData) {
return <div>No users found</div>;
if (!userListData?.results?.length) {
return <div>{t("no_users_found")}</div>;
}

const filteredUsers = searchTerm
? userListData.results.filter((user) => {
const searchString = searchTerm.toLowerCase();
return (
user.username?.toLowerCase().includes(searchString) ||
user.first_name?.toLowerCase().includes(searchString) ||
user.last_name?.toLowerCase().includes(searchString)
);
})
: userListData.results;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assume user page has 100 users, your api will only give you 1st 14, this search will only on that 14!!!

return (
<Page
title={`${t("users")} - ${facilityData?.name}`}
hideBack={true}
breadcrumbs={false}
>
<Page title={`${t("users")}`} hideBack={true} breadcrumbs={false}>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<Page title={`${t("users")}`} hideBack={true} breadcrumbs={false}>
<Page title={t("users")}} hideBack breadcrumbs={false}>

<CountBlock
text={t("total_users")}
count={userListData.count}
Expand All @@ -62,9 +59,9 @@ export default function FacilityUsers(props: { facilityId: number }) {
/>

<UserListView
users={userListData?.results ?? []}
onSearch={(username) => updateQuery({ username })}
searchValue={qParams.username}
users={filteredUsers}
onSearch={(value) => setSearchTerm(value)}
searchValue={searchTerm}
activeTab={activeTab}
onTabChange={setActiveTab}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Users/UserListAndCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ export default function UserListView({
) : (
<div className="h-full space-y-2 rounded-lg bg-white p-7 shadow">
<div className="flex w-full items-center justify-center text-xl font-bold text-secondary-500">
No Users Found
{t("no_users_found")}
</div>
</div>
)}
Expand Down
Loading