-
Notifications
You must be signed in to change notification settings - Fork 496
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into issue#6530
- Loading branch information
Showing
21 changed files
with
721 additions
and
704 deletions.
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
import { useState } from "react"; | ||
import { getBedTypes } from "../../Common/constants"; | ||
import routes from "../../Redux/api"; | ||
import { NonReadOnlyUsers } from "../../Utils/AuthorizeFor"; | ||
import useQuery from "../../Utils/request/useQuery"; | ||
import DialogModal from "../Common/Dialog"; | ||
import ButtonV2 from "../Common/components/ButtonV2"; | ||
import { BedCapacity } from "./BedCapacity"; | ||
import BedTypeCard from "./BedTypeCard"; | ||
import useConfig from "../../Common/hooks/useConfig"; | ||
|
||
export const FacilityBedCapacity = (props: any) => { | ||
const [bedCapacityModalOpen, setBedCapacityModalOpen] = useState(false); | ||
const config = useConfig(); | ||
|
||
const capacityQuery = useQuery(routes.getCapacity, { | ||
pathParams: { facilityId: props.facilityId }, | ||
}); | ||
|
||
let capacityList: any = null; | ||
if (!capacityQuery.data || !capacityQuery.data.results.length) { | ||
capacityList = ( | ||
<h5 className="mt-4 flex w-full items-center justify-center rounded-lg bg-white p-4 text-xl font-bold text-gray-500 shadow"> | ||
No Bed Types Found | ||
</h5> | ||
); | ||
} else { | ||
const totalBedCount = capacityQuery.data.results.reduce( | ||
(acc, x) => acc + (x.total_capacity ? x.total_capacity : 0), | ||
0 | ||
); | ||
const totalOccupiedBedCount = capacityQuery.data.results.reduce( | ||
(acc, x) => acc + (x.current_capacity ? x.current_capacity : 0), | ||
0 | ||
); | ||
|
||
capacityList = ( | ||
<div className="mt-4 grid w-full gap-7 lg:grid-cols-2 xl:grid-cols-3 2xl:grid-cols-4"> | ||
<BedTypeCard | ||
label="Total Beds" | ||
used={totalOccupiedBedCount} | ||
total={totalBedCount} | ||
handleUpdate={() => { | ||
return; | ||
}} | ||
/> | ||
{getBedTypes(config).map((x) => { | ||
const res = capacityQuery.data?.results.find((data) => { | ||
return data.room_type === x.id; | ||
}); | ||
if ( | ||
res && | ||
res.current_capacity !== undefined && | ||
res.total_capacity !== undefined | ||
) { | ||
const removeCurrentBedType = (bedTypeId: number | undefined) => { | ||
if (capacityQuery.data !== undefined) { | ||
capacityQuery.data.results.filter((i) => i.id !== bedTypeId); | ||
capacityQuery.refetch(); | ||
} | ||
}; | ||
return ( | ||
<BedTypeCard | ||
facilityId={props.facilityId} | ||
bedCapacityId={res.id} | ||
key={`bed_${res.id}`} | ||
room_type={res.room_type} | ||
label={x.text} | ||
used={res.current_capacity} | ||
total={res.total_capacity} | ||
lastUpdated={res.modified_date} | ||
removeBedType={removeCurrentBedType} | ||
handleUpdate={() => { | ||
capacityQuery.refetch(); | ||
}} | ||
/> | ||
); | ||
} | ||
})} | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div> | ||
<div className="mt-5 rounded bg-white p-3 shadow-sm md:p-6"> | ||
<div className="justify-between md:flex md:border-b md:pb-2"> | ||
<div className="mb-2 text-xl font-semibold">Bed Capacity</div> | ||
<ButtonV2 | ||
className="w-full md:w-auto" | ||
onClick={() => setBedCapacityModalOpen(true)} | ||
authorizeFor={NonReadOnlyUsers} | ||
> | ||
<i className="fas fa-bed mr-2 text-white" /> | ||
Add More Bed Types | ||
</ButtonV2> | ||
</div> | ||
<div>{capacityList}</div> | ||
</div> | ||
|
||
{bedCapacityModalOpen && ( | ||
<DialogModal | ||
show={bedCapacityModalOpen} | ||
onClose={() => setBedCapacityModalOpen(false)} | ||
title="Add Bed Capacity" | ||
className="max-w-md md:min-w-[600px]" | ||
> | ||
<BedCapacity | ||
facilityId={props.facilityId} | ||
handleClose={() => setBedCapacityModalOpen(false)} | ||
handleUpdate={async () => { | ||
capacityQuery.refetch(); | ||
}} | ||
/> | ||
</DialogModal> | ||
)} | ||
</div> | ||
); | ||
}; |
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
Oops, something went wrong.