Skip to content

Commit

Permalink
Fix empty state in LocationManagement and BedManagement (#6937)
Browse files Browse the repository at this point in the history
* Fix empty state in LocationManagement

* Refactor BedManagement component
  • Loading branch information
Ashesh3 authored Dec 29, 2023
1 parent 22f36fd commit 8197f29
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
2 changes: 1 addition & 1 deletion src/CAREUI/misc/PaginatedList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ interface ItemsProps<TItem> {
const Items = <TItem extends object>(props: ItemsProps<TItem>) => {
const { loading, items } = useContextualized<TItem>();

if (loading) {
if (loading || items.length === 0) {
return null;
}

Expand Down
24 changes: 11 additions & 13 deletions src/Components/Facility/BedManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,24 +182,22 @@ export const BedManagement = (props: BedManagementProps) => {
));
} else if (data?.results.length === 0) {
BedList = (
<p className="flex w-full justify-center border-b border-gray-200 bg-white p-5 text-center text-2xl font-bold text-gray-500">
<p className="flex w-full justify-center bg-white p-5 text-center text-2xl font-bold text-gray-500">
No beds available in this location
</p>
);
}

if (data?.results.length) {
bed = (
<>
<div className="mt-5 flex grow flex-wrap bg-white p-4">{BedList}</div>
{data.count && (
<div className="mt-4 flex w-full justify-center">
<Pagination totalCount={data.count} />
</div>
)}
</>
);
}
bed = (
<>
<div className="mt-5 flex grow flex-wrap bg-white p-4">{BedList}</div>
{Boolean(data?.count && data.count > 0) && (
<div className="mt-4 flex w-full justify-center">
<Pagination totalCount={data?.count ?? 0} />
</div>
)}
</>
);

if (loading) {
return <Loading />;
Expand Down
14 changes: 7 additions & 7 deletions src/Components/Facility/LocationManagement.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ export default function LocationManagement({ facilityId }: Props) {
Add New Location
</ButtonV2>
</div>
<PaginatedList.WhenEmpty className="flex w-full justify-center border-b border-gray-200 bg-white p-5 text-center text-2xl font-bold text-gray-500">
<span>No locations available</span>
</PaginatedList.WhenEmpty>

<PaginatedList.WhenLoading>
<Loading />
</PaginatedList.WhenLoading>
<div className="w-full @container">
<PaginatedList.WhenEmpty className="flex w-full justify-center border-b border-gray-200 bg-white p-5 text-center text-2xl font-bold text-gray-500">
<span>No locations available</span>
</PaginatedList.WhenEmpty>

<PaginatedList.WhenLoading>
<Loading />
</PaginatedList.WhenLoading>
<PaginatedList.Items<LocationModel> className="my-8 grid gap-3 @4xl:grid-cols-2 @6xl:grid-cols-3 @[100rem]:grid-cols-4 lg:mx-8">
{(item) => <Location {...item} />}
</PaginatedList.Items>
Expand Down

0 comments on commit 8197f29

Please sign in to comment.