diff --git a/src/Components/Common/FacilitySelect.tsx b/src/Components/Common/FacilitySelect.tsx index 526bf6d68ac..d718ef3e781 100644 --- a/src/Components/Common/FacilitySelect.tsx +++ b/src/Components/Common/FacilitySelect.tsx @@ -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; @@ -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) => { @@ -39,6 +41,7 @@ export const FacilitySelect = (props: FacilitySelectProps) => { facilityType, district, state, + allowNone = false, freeText = false, errors = "", } = props; @@ -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], diff --git a/src/Components/Users/ManageUsers.tsx b/src/Components/Users/ManageUsers.tsx index 1acd9ac2a3c..a3cb3063577 100644 --- a/src/Components/Users/ManageUsers.tsx +++ b/src/Components/Users/ManageUsers.tsx @@ -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 { @@ -198,10 +198,7 @@ export default function ManageUsers() {
-
+
{user.username && (
{user.user_type && ( @@ -340,9 +337,7 @@ export default function ManageUsers() { )}
{user.created_by && ( @@ -561,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", @@ -786,7 +785,7 @@ export function UserFacilities(props: { user: any }) { {user?.home_facility_object?.name} diff --git a/src/Components/Users/UserFilter.tsx b/src/Components/Users/UserFilter.tsx index f79968cef4f..ff2a81723cd 100644 --- a/src/Components/Users/UserFilter.tsx +++ b/src/Components/Users/UserFilter.tsx @@ -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 }), }); @@ -134,6 +134,7 @@ export default function UserFilter(props: any) {
Home Facility setFilterState({ @@ -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} /> diff --git a/src/Locale/en/Users.json b/src/Locale/en/Users.json index 32c6ee209c3..01fe031c61a 100644 --- a/src/Locale/en/Users.json +++ b/src/Locale/en/Users.json @@ -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",