-
Notifications
You must be signed in to change notification settings - Fork 514
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
base: develop
Are you sure you want to change the base?
Fixed : User Search Bar #9750
Changes from 1 commit
4080682
e624ee3
ba7ad28
a460730
aefe830
0a7be59
cace396
f60d1a2
92ac884
a86e895
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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({ | ||||||
queryKey: ["facilityUsers", facilityId], | ||||||
queryFn: query(routes.facility.getUsers, { | ||||||
|
@@ -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; | ||||||
|
||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}> | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
<CountBlock | ||||||
text={t("total_users")} | ||||||
count={userListData.count} | ||||||
|
@@ -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} | ||||||
/> | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.