Skip to content

Commit

Permalink
Merge branch 'develop' into orgtabs_count_with_header
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaJ2305 authored Jan 22, 2025
2 parents 27d4b0e + 39caada commit 95c0ec3
Show file tree
Hide file tree
Showing 13 changed files with 401 additions and 261 deletions.
6 changes: 3 additions & 3 deletions cypress/e2e/facility_spec/facility_creation.cy.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { FacilityCreation } from "../../pageObject/facility/FacilityCreation";
import { generatePhoneNumber } from "../../utils/commonUtils";
import { generateFacilityData } from "../../utils/facilityData";
import { FacilityCreation } from "@/cypress/pageObject/facility/FacilityCreation";
import { generatePhoneNumber } from "@/cypress/utils/commonUtils";
import { generateFacilityData } from "@/cypress/utils/facilityData";

const LOCATION_HIERARCHY = {
localBody: "Aluva",
Expand Down
2 changes: 1 addition & 1 deletion cypress/e2e/patient_spec/patient_creation.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
generateAddress,
generateName,
generatePhoneNumber,
} from "../../utils/commonUtils";
} from "@/cypress/utils/commonUtils";

const facilityCreation = new FacilityCreation();
const ENCOUNTER_TYPE = "Observation";
Expand Down
1 change: 1 addition & 0 deletions public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1777,6 +1777,7 @@
"required_quantity": "Required Quantity",
"reschedule": "Reschedule",
"reschedule_appointment": "Reschedule Appointment",
"reschedule_appointment_with": "Reschedule Appointment with",
"rescheduled": "Rescheduled",
"rescheduling": "Rescheduling...",
"resend_otp": "Resend OTP",
Expand Down
15 changes: 15 additions & 0 deletions src/Routers/PatientRouter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ const AppointmentRoutes = {
facilityId: string;
staffId: string;
}) => <ScheduleAppointment facilityId={facilityId} staffId={staffId} />,
"/facility/:facilityId/appointments/:staffId/reschedule/:appointmentId": ({
facilityId,
staffId,
appointmentId,
}: {
facilityId: string;
staffId: string;
appointmentId: string;
}) => (
<ScheduleAppointment
facilityId={facilityId}
staffId={staffId}
appointmentId={appointmentId}
/>
),
"/facility/:facilityId/appointments/:staffId/patient-select": ({
facilityId,
staffId,
Expand Down
79 changes: 79 additions & 0 deletions src/hooks/useGovtOrganizationLevel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import { useQuery } from "@tanstack/react-query";
import { useState } from "react";

import { FilterState } from "@/hooks/useFilters";

import query from "@/Utils/request/query";
import { Organization } from "@/types/organization/organization";
import organizationApi from "@/types/organization/organizationApi";

interface UseGovtOrganizationLevelProps {
index: number;
onChange: (filter: FilterState, index: number) => void;
parentId: string;
authToken?: string;
}

interface AutoCompleteOption {
label: string;
value: string;
}

export function useGovtOrganizationLevel({
index,
onChange,
parentId,
authToken,
}: UseGovtOrganizationLevelProps) {
const [searchQuery, setSearchQuery] = useState("");

const headers = authToken
? {
headers: {
Authorization: `Bearer ${authToken}`,
},
}
: {};

const { data: organizations, isLoading } = useQuery({
queryKey: ["organizations-level", parentId, searchQuery],
queryFn: query.debounced(organizationApi.list, {
queryParams: {
org_type: "govt",
parent: parentId,
name: searchQuery || undefined,
limit: 200,
},
...headers,
}),
});

const handleChange = (value: string) => {
const selectedOrg = organizations?.results?.find(
(org: Organization) => org.id === value,
);

if (selectedOrg) {
onChange({ organization: selectedOrg.id }, index);
}
setSearchQuery("");
};

const handleSearch = (query: string) => {
setSearchQuery(query);
};

const options: AutoCompleteOption[] =
organizations?.results?.map((org: Organization) => ({
label: org.name,
value: org.id,
})) || [];

return {
options,
handleChange,
handleSearch,
organizations: organizations?.results,
isLoading,
};
}
10 changes: 7 additions & 3 deletions src/hooks/useOrganizationLevel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ interface UseOrganizationLevelProps {
selectedLevels: Organization[];
setOrgTypes: React.Dispatch<React.SetStateAction<string[]>>;
onChange: (Filter: FilterState, index?: number) => void;
getParentId: (index: number) => string;
}

export function useOrganizationLevel({
Expand All @@ -22,17 +21,22 @@ export function useOrganizationLevel({
selectedLevels,
setOrgTypes,
onChange,
getParentId,
}: UseOrganizationLevelProps) {
const [levelSearch, setLevelSearch] = useState("");

const { data: availableOrgs } = useQuery<{ results: Organization[] }>({
const getParentId = (index: number) => {
if (index === 0) return "0";
return selectedLevels[index - 1]?.id;
};

const { data: availableOrgs } = useQuery({
queryKey: ["organizations-available", getParentId(index), levelSearch],
queryFn: query.debounced(organizationApi.getPublicOrganizations, {
queryParams: {
...(index > 0 && { parent: getParentId(index) }),
...(index === 0 && { level_cache: 1 }),
name: levelSearch || undefined,
limit: 200,
},
}),
enabled:
Expand Down
26 changes: 10 additions & 16 deletions src/pages/Facility/FacilitiesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,17 @@ export function FacilitiesPage() {
});

const { t } = useTranslation();
const [selectedOrgs, setSelectedOrgs] = useState<string[]>(() => {
return qParams.organization ? [qParams.organization] : [];
});
const [selectedOrg, setSelectedOrg] = useState<string | undefined>(
qParams.organization,
);

useEffect(() => {
if (selectedOrgs.length > 0) {
const lastSelected = selectedOrgs[selectedOrgs.length - 1];
updateQuery({ organization: lastSelected });
if (selectedOrg) {
updateQuery({ organization: selectedOrg });
} else {
updateQuery({ organization: undefined });
}
}, [selectedOrgs]);
}, [selectedOrg]);

const { data: facilitiesResponse, isLoading } = useQuery<
PaginatedResponse<FacilityData>
Expand Down Expand Up @@ -73,18 +72,13 @@ export function FacilitiesPage() {
<div className="flex flex-col items-start justify-between gap-5 mt-4 xl:flex-row">
<OrganizationFilter
skipLevels={[]}
selected={selectedOrgs}
onChange={(filter, level) => {
selected={qParams.organization}
onChange={(filter) => {
if ("organization" in filter) {
if (filter.organization) {
setSelectedOrgs((prev) => {
const newOrgId = filter.organization as string;
const newOrgs = prev.slice(0, level);
newOrgs.push(newOrgId);
return newOrgs;
});
setSelectedOrg(filter.organization as string);
} else {
setSelectedOrgs([]);
setSelectedOrg(undefined);
}
}
if ("facility_type" in filter) {
Expand Down
Loading

0 comments on commit 95c0ec3

Please sign in to comment.