diff --git a/src/components/Location/LocationSearch.tsx b/src/components/Location/LocationSearch.tsx index 3e741c7c03f..b1473dccc27 100644 --- a/src/components/Location/LocationSearch.tsx +++ b/src/components/Location/LocationSearch.tsx @@ -1,7 +1,10 @@ import { useQuery } from "@tanstack/react-query"; -import { t } from "i18next"; import { useState } from "react"; +import { useTranslation } from "react-i18next"; +import CareIcon from "@/CAREUI/icons/CareIcon"; + +import { Button } from "@/components/ui/button"; import { Command, CommandEmpty, @@ -23,7 +26,7 @@ import locationApi from "@/types/location/locationApi"; interface LocationSearchProps { facilityId: string; mode?: "kind" | "instance"; - onSelect: (location: LocationList) => void; + onSelect: (location: LocationList | null) => void; disabled?: boolean; value?: LocationList | null; } @@ -35,6 +38,7 @@ export function LocationSearch({ disabled, value, }: LocationSearchProps) { + const { t } = useTranslation(); const [open, setOpen] = useState(false); const [search, setSearch] = useState(""); @@ -50,14 +54,28 @@ export function LocationSearch({
- {stringifyNestedObject(value || { name: "" }) || "Select location..."} + {stringifyNestedObject(value || { name: "" }) || ( + Select location... + )} + {value && ( + + )}
- + ( + null, + ); - const limit = 12; + const { qParams, updateQuery, Pagination, resultsPerPage } = useFilters({ + limit: 12, + cacheBlacklist: ["search_text", "current_location"], + }); const { data, isLoading } = useQuery({ - queryKey: ["devices", facilityId, page, limit], + queryKey: ["devices", facilityId, qParams, resultsPerPage], queryFn: query.debounced(deviceApi.list, { pathParams: { facility_id: facilityId }, queryParams: { - offset: (page - 1) * limit, - limit, + search_text: qParams.search_text, + current_location: qParams.current_location, + limit: resultsPerPage, + offset: (qParams.page - 1) * resultsPerPage, }, }), }); return (
-
+
- - +
+
+ { + updateQuery({ search_text: e.target.value }); + }} + className="w-full border border-gray-300 rounded-lg px-4 py-2 shadow-sm focus:ring-2 focus:ring-primary focus:border-primary" + /> +
+
+ { + updateQuery({ + current_location: location?.id || undefined, + }); + setSelectedLocation(location); + }} + value={selectedLocation} + /> +
+ +
{isLoading ? ( @@ -71,16 +105,7 @@ export default function DevicesList({ facilityId }: Props) { )}
- {data && data.count > limit && ( -
- setPage(page)} - defaultPerPage={limit} - cPage={page} - /> -
- )} +
)}