-
Notifications
You must be signed in to change notification settings - Fork 649
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Support for Location Association History of Devices (#10950)
- Loading branch information
Showing
8 changed files
with
216 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
100 changes: 100 additions & 0 deletions
100
src/pages/Facility/settings/devices/DeviceLocationHistory.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
import { useQuery } from "@tanstack/react-query"; | ||
import { useQueryParams } from "raviger"; | ||
import { useTranslation } from "react-i18next"; | ||
|
||
import { cn } from "@/lib/utils"; | ||
|
||
import Page from "@/components/Common/Page"; | ||
import PaginationComponent from "@/components/Common/Pagination"; | ||
import { CardListSkeleton } from "@/components/Common/SkeletonLoading"; | ||
|
||
import { RESULTS_PER_PAGE_LIMIT } from "@/common/constants"; | ||
|
||
import query from "@/Utils/request/query"; | ||
import { DeviceLocationCard } from "@/pages/Facility/settings/devices/components/DeviceLocationCard"; | ||
import deviceApi from "@/types/device/deviceApi"; | ||
|
||
interface Props { | ||
facilityId: string; | ||
deviceId: string; | ||
} | ||
|
||
const DeviceLocationHistory = ({ facilityId, deviceId }: Props) => { | ||
const { t } = useTranslation(); | ||
|
||
const [qParams, setQueryParams] = useQueryParams<{ page?: number }>(); | ||
|
||
const { data: locationsData, isLoading } = useQuery({ | ||
queryKey: ["deviceLocationHistory", facilityId, deviceId, qParams], | ||
queryFn: query(deviceApi.locationHistory, { | ||
queryParams: { | ||
limit: RESULTS_PER_PAGE_LIMIT, | ||
offset: ((qParams.page ?? 1) - 1) * RESULTS_PER_PAGE_LIMIT, | ||
}, | ||
pathParams: { | ||
facilityId, | ||
id: deviceId, | ||
}, | ||
}), | ||
}); | ||
|
||
return ( | ||
<Page title={t("device_location_history")} className="mt-8"> | ||
<div> | ||
{isLoading ? ( | ||
<div> | ||
<div className="grid gap-5 my-5"> | ||
<CardListSkeleton count={RESULTS_PER_PAGE_LIMIT} /> | ||
</div> | ||
</div> | ||
) : ( | ||
<div> | ||
{locationsData?.results?.length === 0 ? ( | ||
<div className="p-2"> | ||
<div className="h-full space-y-2 rounded-lg bg-white px-7 py-12 border border-secondary-300"> | ||
<div className="flex w-full items-center justify-center text-lg text-secondary-600"> | ||
<div className="h-full flex w-full items-center justify-center"> | ||
<span className="text-sm text-gray-500"> | ||
{t("no_locations_found")} | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
) : ( | ||
<ul className="grid gap-4 my-5"> | ||
{locationsData?.results?.map((locationData) => ( | ||
<li key={locationData.id} className="w-full"> | ||
<DeviceLocationCard | ||
key={locationData.id} | ||
locationData={locationData} | ||
/> | ||
</li> | ||
))} | ||
<div className="flex w-full items-center justify-center"> | ||
<div | ||
className={cn( | ||
"flex w-full justify-center", | ||
(locationsData?.count ?? 0) > RESULTS_PER_PAGE_LIMIT | ||
? "visible" | ||
: "invisible", | ||
)} | ||
> | ||
<PaginationComponent | ||
cPage={qParams.page ?? 1} | ||
defaultPerPage={RESULTS_PER_PAGE_LIMIT} | ||
data={{ totalCount: locationsData?.count ?? 0 }} | ||
onChange={(page) => setQueryParams({ page })} | ||
/> | ||
</div> | ||
</div> | ||
</ul> | ||
)} | ||
</div> | ||
)} | ||
</div> | ||
</Page> | ||
); | ||
}; | ||
|
||
export default DeviceLocationHistory; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/pages/Facility/settings/devices/components/DeviceLocationCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import { t } from "i18next"; | ||
import { Link } from "raviger"; | ||
|
||
import CareIcon from "@/CAREUI/icons/CareIcon"; | ||
|
||
import { Badge } from "@/components/ui/badge"; | ||
import { Card, CardContent } from "@/components/ui/card"; | ||
|
||
import { formatDateTime } from "@/Utils/utils"; | ||
import { DeviceLocationHistory } from "@/types/device/device"; | ||
|
||
interface LocationCardProps { | ||
locationData: DeviceLocationHistory; | ||
} | ||
|
||
export const DeviceLocationCard = ({ locationData }: LocationCardProps) => { | ||
const { start, end, location, created_by } = locationData; | ||
|
||
return ( | ||
<Card className="flex-1 p-4"> | ||
<CardContent className="p-4 sm:p-3 space-y-4"> | ||
<div className="flex flex-wrap gap-6 sm:gap-6"> | ||
<div className="flex gap-3 text-xl font-semibold capitalize"> | ||
<Link | ||
href={`/location/${location.id}`} | ||
className="text-gray-950 font-semibold flex items-start gap-0.5" | ||
id="patient-details" | ||
> | ||
{location.name} | ||
<CareIcon | ||
icon="l-external-link-alt" | ||
className="w-3 h-3 opacity-50 mt-1" | ||
/> | ||
</Link> | ||
</div> | ||
</div> | ||
|
||
<div className="flex gap-3"> | ||
<h2 className="text-lg font-semibold">{t("locations")}</h2> | ||
<Badge variant="outline"> | ||
{t(`location_form__${location?.form}`)} | ||
</Badge> | ||
<Badge | ||
variant={location?.status === "active" ? "default" : "secondary"} | ||
> | ||
{location?.status} | ||
</Badge> | ||
</div> | ||
|
||
<div className="grid sm:flex sm:flex-wrap gap-7"> | ||
<div className="w-full mx-2 sm:w-auto"> | ||
<div className="text-gray-600 text-sm">{t("associated_by")}</div> | ||
<div className="font-semibold text-base flex items-center gap-2"> | ||
{`${created_by.first_name} ${created_by.last_name}`} | ||
</div> | ||
</div> | ||
|
||
<div className="w-full mx-3 sm:w-auto"> | ||
<div className="text-gray-600 text-sm"> | ||
{t("association_start_date")} | ||
</div> | ||
<div className="font-semibold text-base"> | ||
{start ? formatDateTime(start) : t("not_started")} | ||
</div> | ||
</div> | ||
|
||
{ | ||
<div className="w-full mx-3 sm:w-auto"> | ||
<div className="text-gray-600 text-sm"> | ||
{t("association_end_date")} | ||
</div> | ||
<div className="font-semibold text-base"> | ||
{end ? formatDateTime(end) : "-"} | ||
</div> | ||
</div> | ||
} | ||
</div> | ||
</CardContent> | ||
</Card> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters