Skip to content

Commit

Permalink
Add option to filter users by no home facility (#8247)
Browse files Browse the repository at this point in the history
  • Loading branch information
shivankacker authored Aug 25, 2024
1 parent 348edf4 commit 58a8fcf
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
9 changes: 9 additions & 0 deletions src/Components/Common/FacilitySelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import AutoCompleteAsync from "../Form/AutoCompleteAsync";
import { FacilityModel } from "../Facility/models";
import request from "../../Utils/request/request";
import routes from "../../Redux/api";
import { t } from "i18next";

interface FacilitySelectProps {
name: string;
Expand All @@ -21,6 +22,7 @@ interface FacilitySelectProps {
freeText?: boolean;
selected?: FacilityModel | FacilityModel[] | null;
setSelected: (selected: FacilityModel | FacilityModel[] | null) => void;
allowNone?: boolean;
}

export const FacilitySelect = (props: FacilitySelectProps) => {
Expand All @@ -39,6 +41,7 @@ export const FacilitySelect = (props: FacilitySelectProps) => {
facilityType,
district,
state,
allowNone = false,
freeText = false,
errors = "",
} = props;
Expand Down Expand Up @@ -66,6 +69,12 @@ export const FacilitySelect = (props: FacilitySelectProps) => {
name: text,
});

if (allowNone)
return [
{ name: t("no_home_facility"), id: "NONE" },
...(data?.results || []),
];

return data?.results;
},
[searchAll, showAll, facilityType, district, exclude_user, freeText],
Expand Down
8 changes: 6 additions & 2 deletions src/Components/Users/ManageUsers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export default function ManageUsers() {

const { data: homeFacilityData } = useQuery(routes.getAnyFacility, {
pathParams: { id: qParams.home_facility },
prefetch: !!qParams.home_facility,
prefetch: !!qParams.home_facility && qParams.home_facility !== "NONE",
});

const {
Expand Down Expand Up @@ -556,7 +556,11 @@ export default function ManageUsers() {
value(
"Home Facility",
"home_facility",
qParams.home_facility ? homeFacilityData?.name || "" : "",
qParams.home_facility
? qParams.home_facility === "NONE"
? t("no_home_facility")
: homeFacilityData?.name || ""
: "",
),
value(
"Last Active",
Expand Down
9 changes: 7 additions & 2 deletions src/Components/Users/UserFilter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export default function UserFilter(props: any) {

useQuery(routes.getAnyFacility, {
pathParams: { id: filter.home_facility },
prefetch: !!filter.home_facility,
prefetch: !!filter.home_facility && filter.home_facility !== "NONE",
onResponse: ({ data }) => setFilterState({ home_facility_ref: data }),
});

Expand Down Expand Up @@ -134,6 +134,7 @@ export default function UserFilter(props: any) {
<div className="w-full flex-none">
<FieldLabel>Home Facility</FieldLabel>
<FacilitySelect
allowNone
name="home_facility"
setSelected={(selected) =>
setFilterState({
Expand All @@ -142,7 +143,11 @@ export default function UserFilter(props: any) {
home_facility_ref: selected,
})
}
selected={filterState.home_facility_ref}
selected={
filterState.home_facility === "NONE"
? { name: t("no_home_facility"), id: "NONE" }
: filterState.home_facility_ref
}
errors=""
multiple={false}
/>
Expand Down
1 change: 1 addition & 0 deletions src/Locale/en/Users.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"add_new_user": "Add New User",
"no_users_found": "No Users Found",
"home_facility": "Home Facility",
"no_home_facility" : "No home facility assigned",
"clear_home_facility": "Clear Home Facility",
"linked_facilities": "Linked Facilities",
"no_linked_facilities": "No Linked Facilities",
Expand Down

0 comments on commit 58a8fcf

Please sign in to comment.