-
Location Details
+
{t("location_details")}
@@ -386,7 +486,7 @@ export default function CreateFacilityForm({
{/* Visibility Settings */}
-
Visibility Settings
+ {t("visibility_settings")}
)}
/>
-
- {!organizationId && (
- (
-
- Organization
-
-
-
-
-
- )}
- />
- )}
diff --git a/src/components/Facility/FacilityHome.tsx b/src/components/Facility/FacilityHome.tsx
index 1dbaf401e40..8fe87a6d78f 100644
--- a/src/components/Facility/FacilityHome.tsx
+++ b/src/components/Facility/FacilityHome.tsx
@@ -31,6 +31,7 @@ import request from "@/Utils/request/request";
import uploadFile from "@/Utils/request/uploadFile";
import { getAuthorizationHeader } from "@/Utils/request/utils";
import { sleep } from "@/Utils/utils";
+import EditFacilitySheet from "@/pages/Organization/components/EditFacilitySheet";
import { FacilityData } from "@/types/facility/facility";
import type {
Organization,
@@ -234,6 +235,7 @@ export const FacilityHome = ({ facilityId }: Props) => {
{hasPermissionToEditCoverImage && (
setEditCoverImage(true)}
>
@@ -241,12 +243,13 @@ export const FacilityHome = ({ facilityId }: Props) => {
)}
- navigate(`/facility/${facilityId}/update`)
- }
+ className=" cursor-pointer"
+ onSelect={(e) => {
+ e.preventDefault();
+ }}
>
- {t("update_facility")}
+
{/* TODO: get permissions from backend */}
{/* {hasPermissionToDeleteFacility && (
diff --git a/src/pages/Appointments/AppointmentDetail.tsx b/src/pages/Appointments/AppointmentDetail.tsx
index 93ba489a65d..cfcec8c2bef 100644
--- a/src/pages/Appointments/AppointmentDetail.tsx
+++ b/src/pages/Appointments/AppointmentDetail.tsx
@@ -46,7 +46,6 @@ import { Separator } from "@/components/ui/separator";
import Loading from "@/components/Common/Loading";
import Page from "@/components/Common/Page";
-import { FacilityModel } from "@/components/Facility/models";
import routes from "@/Utils/request/api";
import mutate from "@/Utils/request/mutate";
@@ -61,6 +60,7 @@ import {
formatAppointmentSlotTime,
printAppointment,
} from "@/pages/Appointments/utils";
+import { FacilityData } from "@/types/facility/facility";
import {
Appointment,
AppointmentStatuses,
@@ -207,7 +207,7 @@ const AppointmentDetails = ({
facility,
}: {
appointment: Appointment;
- facility: FacilityModel;
+ facility: FacilityData;
}) => {
const { patient, user } = appointment;
const { t } = useTranslation();
diff --git a/src/pages/Appointments/components/AppointmentTokenCard.tsx b/src/pages/Appointments/components/AppointmentTokenCard.tsx
index 9f563852a82..7dc65f84c3f 100644
--- a/src/pages/Appointments/components/AppointmentTokenCard.tsx
+++ b/src/pages/Appointments/components/AppointmentTokenCard.tsx
@@ -4,17 +4,16 @@ import { useTranslation } from "react-i18next";
import { Card } from "@/components/ui/card";
import { Label } from "@/components/ui/label";
-import { FacilityModel } from "@/components/Facility/models";
-
import { formatName, formatPatientAge } from "@/Utils/utils";
import { formatAppointmentSlotTime } from "@/pages/Appointments/utils";
import { getFakeTokenNumber } from "@/pages/Scheduling/utils";
+import { FacilityData } from "@/types/facility/facility";
import { Appointment } from "@/types/scheduling/schedule";
interface Props {
id?: string;
appointment: Appointment;
- facility: FacilityModel;
+ facility: FacilityData;
}
const AppointmentTokenCard = ({ id, appointment, facility }: Props) => {
diff --git a/src/pages/Appointments/utils.ts b/src/pages/Appointments/utils.ts
index 4b131e50382..2ff300cd8b8 100644
--- a/src/pages/Appointments/utils.ts
+++ b/src/pages/Appointments/utils.ts
@@ -10,8 +10,6 @@ import {
import { TFunction } from "i18next";
import { toast } from "sonner";
-import { FacilityModel } from "@/components/Facility/models";
-
import query from "@/Utils/request/query";
import {
dateQueryString,
@@ -20,6 +18,7 @@ import {
getMonthStartAndEnd,
} from "@/Utils/utils";
import { getFakeTokenNumber } from "@/pages/Scheduling/utils";
+import { FacilityData } from "@/types/facility/facility";
import {
Appointment,
AvailabilityHeatmapResponse,
@@ -142,7 +141,7 @@ export const printAppointment = ({
appointment,
}: {
t: TFunction;
- facility: FacilityModel;
+ facility: FacilityData;
appointment: Appointment;
}) => {
const patient = appointment.patient;
diff --git a/src/pages/Organization/OrganizationFacilities.tsx b/src/pages/Organization/OrganizationFacilities.tsx
index 82055af8caf..7cf6c3ba269 100644
--- a/src/pages/Organization/OrganizationFacilities.tsx
+++ b/src/pages/Organization/OrganizationFacilities.tsx
@@ -17,6 +17,7 @@ import query from "@/Utils/request/query";
import { BaseFacility } from "@/types/facility/facility";
import AddFacilitySheet from "./components/AddFacilitySheet";
+import EditFacilitySheet from "./components/EditFacilitySheet";
import OrganizationLayout from "./components/OrganizationLayout";
interface Props {
@@ -114,62 +115,65 @@ export default function OrganizationFacilities({
) : (
facilities?.results?.map((facility: BaseFacility) => (
-
-
-
- {facility.read_cover_image_url ? (
-
- ) : (
-
- )}
-
-
-
-
-
-
- {facility.name}
-
-
- {facility.facility_type}
-
+
+ {facility.read_cover_image_url ? (
+
+ ) : (
+
+ )}
+
+
+
+
+
+
+ {facility.name}
+
+
+ {facility.facility_type}
-
-
-
+
+
+
+
+
+
+
+
))
)}
diff --git a/src/pages/Organization/components/AddFacilitySheet.tsx b/src/pages/Organization/components/AddFacilitySheet.tsx
index 4474baaffe8..33bd5d40f6f 100644
--- a/src/pages/Organization/components/AddFacilitySheet.tsx
+++ b/src/pages/Organization/components/AddFacilitySheet.tsx
@@ -1,4 +1,5 @@
import { useQueryClient } from "@tanstack/react-query";
+import { t } from "i18next";
import { useState } from "react";
import CareIcon from "@/CAREUI/icons/CareIcon";
@@ -13,7 +14,7 @@ import {
SheetTrigger,
} from "@/components/ui/sheet";
-import CreateFacilityForm from "@/components/Facility/CreateFacilityForm";
+import FacilityForm from "@/components/Facility/FacilityForm";
interface Props {
organizationId: string;
@@ -28,18 +29,16 @@ export default function AddFacilitySheet({ organizationId }: Props) {
- Add Facility
+ {t("add_facility")}
- Add New Facility
-
- Create a new facility and add it to the organization.
-
+ {t("add_new_facility")}
+ {t("create_new_facility")}
-
{
setOpen(false);
diff --git a/src/pages/Organization/components/EditFacilitySheet.tsx b/src/pages/Organization/components/EditFacilitySheet.tsx
new file mode 100644
index 00000000000..8f09002e3db
--- /dev/null
+++ b/src/pages/Organization/components/EditFacilitySheet.tsx
@@ -0,0 +1,49 @@
+import { useQueryClient } from "@tanstack/react-query";
+import { t } from "i18next";
+import { useState } from "react";
+
+import {
+ Sheet,
+ SheetContent,
+ SheetDescription,
+ SheetHeader,
+ SheetTitle,
+ SheetTrigger,
+} from "@/components/ui/sheet";
+
+import FacilityForm from "@/components/Facility/FacilityForm";
+
+interface Props {
+ organizationId?: string;
+ facilityId: string;
+}
+
+export default function EditFacilitySheet({ facilityId }: Props) {
+ const queryClient = useQueryClient();
+ const [open, setOpen] = useState(false);
+
+ return (
+
+
+
+ {t("edit_facility")}
+
+
+
+
+ {t("edit_facility")}
+ {t("update_existing_facility")}
+
+
+ {
+ setOpen(false);
+ queryClient.invalidateQueries({ queryKey: ["currentUser"] });
+ }}
+ />
+
+
+
+ );
+}
diff --git a/src/pages/Organization/components/OrganizationSelector.tsx b/src/pages/Organization/components/OrganizationSelector.tsx
index 286940c87f9..7d0c2683bc9 100644
--- a/src/pages/Organization/components/OrganizationSelector.tsx
+++ b/src/pages/Organization/components/OrganizationSelector.tsx
@@ -1,6 +1,6 @@
import { useQuery } from "@tanstack/react-query";
import { t } from "i18next";
-import { useState } from "react";
+import { useEffect, useState } from "react";
import CareIcon from "@/CAREUI/icons/CareIcon";
@@ -9,14 +9,18 @@ import { Button } from "@/components/ui/button";
import { Label } from "@/components/ui/label";
import query from "@/Utils/request/query";
-import { Organization } from "@/types/organization/organization";
+import {
+ Organization,
+ OrganizationParent,
+} from "@/types/organization/organization";
import organizationApi from "@/types/organization/organizationApi";
interface OrganizationSelectorProps {
- value?: string;
+ value?: Organization | string;
onChange: (value: string) => void;
required?: boolean;
authToken?: string;
+ parentSelectedLevels?: Organization[];
}
interface AutoCompleteOption {
@@ -26,10 +30,30 @@ interface AutoCompleteOption {
// TODO: Rename to GovtOrganizationSelector
export default function OrganizationSelector(props: OrganizationSelectorProps) {
- const { onChange, required } = props;
+ const { value, onChange, required, parentSelectedLevels } = props;
const [selectedLevels, setSelectedLevels] = useState([]);
const [searchQuery, setSearchQuery] = useState("");
+ useEffect(() => {
+ if (value && parentSelectedLevels?.length == 0) {
+ const parsedValue = typeof value === "string" ? JSON.parse(value) : value;
+
+ if (typeof parsedValue === "object") {
+ const levels: Organization[] = [];
+ let current: OrganizationParent = parsedValue;
+
+ while (current.parent) {
+ levels.unshift(current as Organization);
+ current = current.parent;
+ }
+
+ setSelectedLevels(levels);
+ }
+ } else if (parentSelectedLevels) {
+ setSelectedLevels(parentSelectedLevels);
+ }
+ }, [value, parentSelectedLevels]);
+
const headers = props.authToken
? {
headers: {
@@ -149,7 +173,7 @@ export default function OrganizationSelector(props: OrganizationSelectorProps) {
)}
(),
},
};
+
+export function useFetchOrganizationByName(name: string, parentId?: string) {
+ return useQuery({
+ queryKey: ["organization", name, parentId],
+ queryFn: async () => {
+ const data = await query(organizationApi.list, {
+ queryParams: {
+ org_type: "govt",
+ parent: parentId || "",
+ name: name,
+ },
+ })({ signal: new AbortController().signal });
+
+ return data.results?.[0] || null;
+ },
+ enabled: name != undefined,
+ });
+}
+
+export default organizationApi;