{
setOpen(false);
diff --git a/src/pages/Organization/components/EditFacilitySheet.tsx b/src/pages/Organization/components/EditFacilitySheet.tsx
new file mode 100644
index 00000000000..52ec00e5985
--- /dev/null
+++ b/src/pages/Organization/components/EditFacilitySheet.tsx
@@ -0,0 +1,48 @@
+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;
+ trigger?: React.ReactNode;
+}
+
+export default function EditFacilitySheet({ facilityId, trigger }: Props) {
+ const queryClient = useQueryClient();
+ const [open, setOpen] = useState(false);
+
+ return (
+
+ {trigger}
+
+
+ {t("edit_facility")}
+ {t("update_existing_facility")}
+
+
+ {
+ setOpen(false);
+ queryClient.invalidateQueries({
+ queryKey: [["facility", facilityId], "organizationFacilities"],
+ });
+ }}
+ />
+
+
+
+ );
+}
diff --git a/src/pages/Organization/components/OrganizationLayout.tsx b/src/pages/Organization/components/OrganizationLayout.tsx
index 2fd985fd97f..0ea786aec15 100644
--- a/src/pages/Organization/components/OrganizationLayout.tsx
+++ b/src/pages/Organization/components/OrganizationLayout.tsx
@@ -173,7 +173,7 @@ export default function OrganizationLayout({
{/* Navigation */}
-
+
{navItems
.filter((item) => item.visibility)
.map((item) => (
diff --git a/src/pages/Organization/components/OrganizationSelector.tsx b/src/pages/Organization/components/OrganizationSelector.tsx
index 286940c87f9..84d6093cc1c 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";
@@ -17,6 +17,8 @@ interface OrganizationSelectorProps {
onChange: (value: string) => void;
required?: boolean;
authToken?: string;
+ selected?: Organization[];
+ errorMessage?: string;
}
interface AutoCompleteOption {
@@ -26,7 +28,7 @@ interface AutoCompleteOption {
// TODO: Rename to GovtOrganizationSelector
export default function OrganizationSelector(props: OrganizationSelectorProps) {
- const { onChange, required } = props;
+ const { onChange, required, selected } = props;
const [selectedLevels, setSelectedLevels] = useState([]);
const [searchQuery, setSearchQuery] = useState("");
@@ -38,6 +40,22 @@ export default function OrganizationSelector(props: OrganizationSelectorProps) {
}
: {};
+ useEffect(() => {
+ if (selected && selected.length > 0) {
+ let currentOrg = selected[0];
+ if (currentOrg.level_cache === 0) {
+ setSelectedLevels(selected);
+ } else {
+ const levels: Organization[] = [];
+ while (currentOrg && currentOrg.level_cache >= 0) {
+ levels.unshift(currentOrg);
+ currentOrg = currentOrg.parent as unknown as Organization;
+ }
+ setSelectedLevels(levels);
+ }
+ }
+ }, [selected]);
+
const { data: getAllOrganizations } = useQuery({
queryKey: ["organizations-root", searchQuery],
queryFn: query.debounced(organizationApi.list, {
@@ -101,7 +119,19 @@ export default function OrganizationSelector(props: OrganizationSelectorProps) {
};
const handleEdit = (level: number) => {
- setSelectedLevels((prev) => prev.slice(0, level));
+ const newLevels = selectedLevels.slice(0, level);
+ setSelectedLevels(newLevels);
+
+ if (!newLevels.length) {
+ onChange("");
+ } else {
+ const lastOrg = newLevels[newLevels.length - 1];
+ if (!lastOrg.has_children) {
+ onChange(lastOrg.id);
+ } else {
+ onChange("");
+ }
+ }
};
const lastLevel = selectedLevels[selectedLevels.length - 1];
diff --git a/src/types/facility/facility.ts b/src/types/facility/facility.ts
index 4a14964e34a..33157fd50e5 100644
--- a/src/types/facility/facility.ts
+++ b/src/types/facility/facility.ts
@@ -1,4 +1,4 @@
-import { Organization } from "../organization/organization";
+import { Organization } from "@/types/organization/organization";
export interface BaseFacility {
id: string;
@@ -26,6 +26,8 @@ export interface FacilityData {
read_cover_image_url?: string;
features: number[];
geo_organization: Organization;
- pincode: string;
+ latitude: number;
+ longitude: number;
+ pincode: number;
is_public: boolean;
}