diff --git a/cypress/e2e/assets_spec/AssetHomepage.cy.ts b/cypress/e2e/assets_spec/AssetHomepage.cy.ts index 57c315bb0c4..bf608cdab9f 100644 --- a/cypress/e2e/assets_spec/AssetHomepage.cy.ts +++ b/cypress/e2e/assets_spec/AssetHomepage.cy.ts @@ -78,7 +78,9 @@ describe("Asset Tab", () => { it("Next/Previous Page", () => { assetPagination.navigateToNextPage(); + assetPagination.verifyNextUrl(); assetPagination.navigateToPreviousPage(); + assetPagination.verifyPreviousUrl(); }); it("Import new asset", () => { diff --git a/cypress/e2e/facility_spec/FacilityHomepage.cy.ts b/cypress/e2e/facility_spec/FacilityHomepage.cy.ts index e2a12b01a05..b8fb0afd9d9 100644 --- a/cypress/e2e/facility_spec/FacilityHomepage.cy.ts +++ b/cypress/e2e/facility_spec/FacilityHomepage.cy.ts @@ -81,7 +81,9 @@ describe("Facility Homepage Function", () => { it("Search a facility in homepage and pagination", () => { // pagination of the facility page assetPagination.navigateToNextPage(); + assetPagination.verifyNextUrl(); assetPagination.navigateToPreviousPage(); + assetPagination.verifyPreviousUrl(); // search for a facility manageUserPage.typeFacilitySearch(facilityName); facilityPage.verifyFacilityBadgeContent(facilityName); diff --git a/cypress/pageobject/Asset/AssetPagination.ts b/cypress/pageobject/Asset/AssetPagination.ts index 3fff457d8cf..f2a4103b065 100644 --- a/cypress/pageobject/Asset/AssetPagination.ts +++ b/cypress/pageobject/Asset/AssetPagination.ts @@ -2,12 +2,18 @@ export class AssetPagination { navigateToNextPage() { // only works for desktop mode cy.get("button#next-pages").click(); + } + + verifyNextUrl() { cy.url().should("include", "page=2"); } navigateToPreviousPage() { // only works for desktop mode cy.get("button#prev-pages").click(); + } + + verifyPreviousUrl() { cy.url().should("include", "page=1"); } } diff --git a/src/Components/Facility/BedManagement.tsx b/src/Components/Facility/BedManagement.tsx index 5816ff58d4b..628e273b883 100644 --- a/src/Components/Facility/BedManagement.tsx +++ b/src/Components/Facility/BedManagement.tsx @@ -1,7 +1,6 @@ import { useState } from "react"; import ButtonV2 from "../Common/components/ButtonV2"; import { BedModel } from "./models"; -import { ReactElement } from "react"; import * as Notification from "../../Utils/Notifications.js"; import { LOCATION_BED_TYPES } from "../../Common/constants"; import BedDeleteDialog from "./BedDeleteDialog"; @@ -14,6 +13,8 @@ import useQuery from "../../Utils/request/useQuery"; import useFilters from "../../Common/hooks/useFilters"; import useAuthUser from "../../Common/hooks/useAuthUser"; import Loading from "@/Components/Common/Loading"; +import PaginatedList from "@/CAREUI/misc/PaginatedList"; +import { useTranslation } from "react-i18next"; interface BedManagementProps { facilityId: string; locationId: string; @@ -30,17 +31,16 @@ interface BedRowProps { isOccupied: boolean; } -const BedRow = (props: BedRowProps) => { - const { - id, - facilityId, - name, - description, - triggerRerender, - locationId, - bedType, - isOccupied, - } = props; +const BedCard = ({ + id, + facilityId, + name, + description, + triggerRerender, + locationId, + bedType, + isOccupied, +}: BedRowProps) => { const [bedData, setBedData] = useState<{ show: boolean; name: string; @@ -52,6 +52,7 @@ const BedRow = (props: BedRowProps) => { name, }); }; + const { t } = useTranslation(); const allowedUser = ["DistrictAdmin", "StateAdmin"].includes( authUser.user_type, @@ -80,19 +81,17 @@ const BedRow = (props: BedRowProps) => { handleCancel={handleDeleteCancel} handleOk={handleDeleteConfirm} /> -
-
-
-

- {name} -

{" "} -   +
+
+
+
+

+ {name} +

+
{LOCATION_BED_TYPES.find((item) => item.id === bedType) && (

@@ -108,45 +107,55 @@ const BedRow = (props: BedRowProps) => { : "bg-primary-100 text-primary-600" } mb-1 ml-1 inline-flex w-fit items-center rounded-md px-2.5 py-0.5 text-sm font-medium capitalize leading-5`} > - {isOccupied ? "Occupied" : "Vacant"} + {isOccupied ? t("occupied") : t("vacant")}

-

{description}

+ {description && ( +

+ {description} +

+ )}
-
- - - Edit - - handleDelete(name, id)} - authorizeFor={AuthorizeFor(["DistrictAdmin", "StateAdmin"])} - variant="danger" - border - ghost - className="w-full lg:w-auto" - tooltip={ - !allowedUser - ? "Contact your admin to delete the bed" - : isOccupied - ? "Bed is occupied" - : undefined - } - tooltipClassName=" text-xs w-full lg:w-auto" - > - - Delete - + +
+
+ + + {t("edit")} + +
+
+ handleDelete(name, id)} + authorizeFor={AuthorizeFor(["DistrictAdmin", "StateAdmin"])} + variant="secondary" + border + className="w-full" + tooltip={ + !allowedUser + ? "Contact your admin to delete the bed" + : isOccupied + ? "Bed is occupied" + : undefined + } + tooltipClassName=" text-xs w-full lg:w-auto" + > + + {t("delete")} + +
@@ -155,9 +164,8 @@ const BedRow = (props: BedRowProps) => { export const BedManagement = (props: BedManagementProps) => { const { facilityId, locationId } = props; - let bed: ReactElement | null = null; - let BedList: ReactElement[] | ReactElement = []; - const { qParams, Pagination, resultsPerPage } = useFilters({}); + const { qParams, resultsPerPage } = useFilters({}); + const { t } = useTranslation(); const { data: location } = useQuery(routes.getFacilityAssetLocation, { pathParams: { @@ -166,77 +174,80 @@ export const BedManagement = (props: BedManagementProps) => { }, }); - const { loading, data, refetch } = useQuery(routes.listFacilityBeds, { - query: { - facility: facilityId, - location: locationId, - limit: resultsPerPage, - offset: (qParams.page ? qParams.page - 1 : 0) * resultsPerPage, - }, - }); - - if (data?.results.length) { - BedList = data.results.map((bedItem: BedModel) => ( - - )); - } else if (data?.results.length === 0) { - BedList = ( -

- No beds available in this location -

- ); - } - - bed = ( - <> -
{BedList}
- {Boolean(data?.count && data.count > 0) && ( -
- -
- )} - - ); - - if (loading) { - return ; - } - return ( - -
-
- - - Add New Bed(s) - -
- {bed} -
-
+ {({ refetch }) => ( + + + {t("add_new_beds")} + + } + backUrl={`/facility/${facilityId}/location/${locationId}`} + > +
+ + + {t("add_new_beds")} + +
+
+ + {t("no_beds_available")} + + + + + + className="my-8 grid grid-cols-1 gap-3 @xl:grid-cols-2 @4xl:grid-cols-3 @6xl:grid-cols-4"> + {(bedItem: BedModel) => ( + + )} + +
+
+ +
+
+ )} + ); }; diff --git a/src/Locale/en.json b/src/Locale/en.json index 50093251818..9826b7532fa 100644 --- a/src/Locale/en.json +++ b/src/Locale/en.json @@ -261,6 +261,7 @@ "add_beds_to_configure_presets": "Add beds to this location to configure presets for them.", "add_details_of_patient": "Add Details of Patient", "add_location": "Add Location", + "add_new_beds": "Add New Bed(s)", "add_new_user": "Add New User", "add_notes": "Add notes", "add_policy": "Add Insurance Policy", @@ -844,6 +845,7 @@ "no": "No", "no_attachments_found": "This communication has no attachments.", "no_bed_types_found": "No Bed Types found", + "no_beds_available": "No beds available", "no_changes": "No changes", "no_changes_made": "No changes made", "no_consultation_updates": "No consultation updates", @@ -887,6 +889,7 @@ "nutrition": "Nutrition", "occupancy": "Occupancy", "occupation": "Occupation", + "occupied": "Occupied", "on": "On", "ongoing_medications": "Ongoing Medications", "only_indian_mobile_numbers_supported": "Currently only Indian numbers are supported", @@ -1218,6 +1221,7 @@ "user_management": "User Management", "username": "Username", "users": "Users", + "vacant": "Vacant", "vehicle_preference": "Vehicle preference", "vendor_name": "Vendor Name", "verify_and_link": "Verify and Link",