Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Public Facilities Filters #9748

Merged
merged 22 commits into from
Jan 14, 2025
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
faa4abe
WIP: organization filter
Jacobjeevan Jan 2, 2025
099e91e
Merge branch 'develop' into organizationFilter
Jacobjeevan Jan 4, 2025
3abdfd9
Organization Filter
Jacobjeevan Jan 4, 2025
2349c84
Merge branch 'develop' into organizationFilter
Jacobjeevan Jan 5, 2025
db940f2
minor fixes
Jacobjeevan Jan 5, 2025
bc0560a
Merge branch 'develop' into organizationFilter
Jacobjeevan Jan 6, 2025
a57dfa6
Tweak logic to work with levels from BE than hardcoded
Jacobjeevan Jan 6, 2025
c4ca814
Merge branch 'develop' into organizationFilter
Jacobjeevan Jan 6, 2025
be5bcaa
Update organisation filter and search bar styling on public facilitie…
vinutv Jan 7, 2025
2b62571
Merge branch 'develop' into organizationFilter
Jacobjeevan Jan 8, 2025
5ff2f0f
added query for root level, styling changes
Jacobjeevan Jan 8, 2025
31986af
moved logic to sep file&hook as per cursor suggestion
Jacobjeevan Jan 8, 2025
5537247
coderabbit suggestions
Jacobjeevan Jan 8, 2025
3ca311d
additional styling changes
Jacobjeevan Jan 8, 2025
def05a4
mobile responsiveness edits
Jacobjeevan Jan 8, 2025
f1f9b55
Merge branch 'develop' into organizationFilter
nihal467 Jan 9, 2025
04b8c10
Merge branch 'develop' into organizationFilter
Jacobjeevan Jan 11, 2025
06dba7b
switch to debounced query
Jacobjeevan Jan 11, 2025
cfd445c
styling and fixes
Jacobjeevan Jan 11, 2025
c3eb888
Merge branch 'develop' into organizationFilter
Jacobjeevan Jan 11, 2025
e0f4527
Merge branch 'develop' into organizationFilter
Jacobjeevan Jan 13, 2025
03ee501
disable facility type filter if location is not selected
Jacobjeevan Jan 13, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion public/locale/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,6 @@
"facility_not_found": "Facility Not Found",
"facility_organizations": "Facility Organizations",
"facility_preference": "Facility preference",
"facility_search_placeholder": "Search by Facility / District Name",
"facility_search_placeholder_text": "Search by Facility name",
"facility_type": "Facility Type",
"failed_to_create_appointment": "Failed to create an appointment",
Expand Down Expand Up @@ -1605,14 +1604,17 @@
"select": "Select",
"select_all": "Select All",
"select_date": "Select date",
"select_district": "Select District",
"select_eligible_policy": "Select an Eligible Insurance Policy",
"select_facility_for_discharged_patients_warning": "Facility needs to be selected to view discharged patients.",
"select_facility_type": "Select Facility Type",
"select_for_administration": "Select for Administration",
"select_groups": "Select Groups",
"select_investigation": "Select Investigations (all investigations will be selected by default)",
"select_investigation_groups": "Select Investigation Groups",
"select_investigations": "Select Investigations",
"select_local_body": "Select Local Body",
"select_localbody": "Select Local Body",
"select_patient": "Select Patient",
"select_policy": "Select an Insurance Policy",
"select_policy_to_add_items": "Select a Policy to Add Items",
Expand All @@ -1623,6 +1625,7 @@
"select_skills": "Select and add some skills",
"select_time": "Select time",
"select_time_slot": "Select time slot",
"select_ward": "Select Ward",
"select_wards": "Select wards",
"self_booked": "Self-booked",
"send": "Send",
Expand Down
2 changes: 1 addition & 1 deletion src/components/Common/UserSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export default function UserSelector({
</Button>
</PopoverTrigger>
<PopoverContent
className="p-0 w-[var(--radix-popover-trigger-width)] max-w-[--radix-popover-content-available-width]"
className="p-0 w-[var(--radix-popover-trigger-width)]"
align="start"
sideOffset={4}
>
Expand Down
11 changes: 9 additions & 2 deletions src/components/ui/autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ interface AutocompleteProps {
placeholder?: string;
noOptionsMessage?: string;
disabled?: boolean;
align?: "start" | "center" | "end";
popoverClassName?: string;
}

export default function Autocomplete({
Expand All @@ -41,12 +43,14 @@ export default function Autocomplete({
placeholder = "Select...",
noOptionsMessage = "No options found",
disabled,
align = "center",
popoverClassName,
}: AutocompleteProps) {
const [open, setOpen] = React.useState(false);

return (
<Popover open={open} onOpenChange={setOpen} modal={true}>
<PopoverTrigger asChild>
<PopoverTrigger asChild className={popoverClassName}>
<Button
title={
value
Expand All @@ -67,7 +71,10 @@ export default function Autocomplete({
<CaretSortIcon className="ml-2 size-4 shrink-0 opacity-50" />
</Button>
</PopoverTrigger>
<PopoverContent className="w-full p-0 pointer-events-auto">
<PopoverContent
className="sm:w-full p-0 pointer-events-auto w-[var(--radix-popover-trigger-width)]"
align={align}
>
<Command>
<CommandInput
placeholder="Search option..."
Expand Down
3 changes: 0 additions & 3 deletions src/pages/Appoinments/PatientRegistration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import { useForm } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { z } from "zod";

import CareIcon from "@/CAREUI/icons/CareIcon";

import { Button } from "@/components/ui/button";
import {
Form,
Expand Down Expand Up @@ -235,7 +233,6 @@ export function PatientRegistration(props: PatientRegistrationProps) {
)
}
>
<CareIcon icon="l-square-shape" className="h-4 w-4 mr-1" />
<span className="text-sm underline">{t("back")}</span>
</Button>
</div>
Expand Down
3 changes: 0 additions & 3 deletions src/pages/Appoinments/PatientSelect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import { navigate } from "raviger";
import { useState } from "react";
import { useTranslation } from "react-i18next";

import CareIcon from "@/CAREUI/icons/CareIcon";

import { Button } from "@/components/ui/button";

import Loading from "@/components/Common/Loading";
Expand Down Expand Up @@ -210,7 +208,6 @@ export default function PatientSelect({
)
}
>
<CareIcon icon="l-square-shape" className="h-4 w-4 mr-1" />
<span className="text-sm underline">{t("back")}</span>
</Button>
</div>
Expand Down
1 change: 0 additions & 1 deletion src/pages/Appoinments/Schedule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,6 @@ export function ScheduleAppointment(props: AppointmentsProps) {
className="border border-secondary-400"
>
<Link href={`/facility/${facilityId}`}>
<CareIcon icon="l-square-shape" className="h-4 w-4 mr-1" />
<span className="text-sm underline">{t("back")}</span>
</Link>
</Button>
Expand Down
5 changes: 1 addition & 4 deletions src/pages/Appoinments/auth/PatientLogin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ import { useForm } from "react-hook-form";
import { useTranslation } from "react-i18next";
import { z } from "zod";

import CareIcon from "@/CAREUI/icons/CareIcon";

import { Button } from "@/components/ui/button";
import {
Form,
Expand Down Expand Up @@ -293,8 +291,7 @@ export default function PatientLogin({
)
}
>
<CareIcon icon="l-square-shape" className="h-4 w-4 mr-1" />
<span className="text-sm underline">Back</span>
<span className="text-sm underline">{t("back")}</span>
</Button>
{page === "send" ? renderPhoneNumberForm() : renderVerifyForm()}
</div>
Expand Down
55 changes: 46 additions & 9 deletions src/pages/Facility/FacilitiesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import careConfig from "@careConfig";
import { useQuery } from "@tanstack/react-query";
import dayjs from "dayjs";
import { Link, navigate } from "raviger";
import { useEffect, useState } from "react";
import { useTranslation } from "react-i18next";

import { Button } from "@/components/ui/button";
Expand All @@ -13,14 +14,15 @@ import { FacilityModel } from "@/components/Facility/models";

import useFilters from "@/hooks/useFilters";

import { CarePatientTokenKey } from "@/common/constants";
import { LocalStorageKeys } from "@/common/constants";
import { RESULTS_PER_PAGE_LIMIT } from "@/common/constants";

import routes from "@/Utils/request/api";
import query from "@/Utils/request/query";
import { PaginatedResponse } from "@/Utils/request/types";
import { TokenData } from "@/types/auth/otpToken";

import OrganizationFilter from "../Organization/components/OrganizationFilter";
import { FacilityCard } from "./components/FacilityCard";

export function FacilitiesPage() {
Expand All @@ -31,21 +33,34 @@ export function FacilitiesPage() {
});

const tokenData: TokenData = JSON.parse(
localStorage.getItem(CarePatientTokenKey) || "{}",
localStorage.getItem(LocalStorageKeys.patientTokenKey) || "{}",
);

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

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

const { data: facilitiesResponse, isLoading } = useQuery<
PaginatedResponse<FacilityModel>
>({
queryKey: ["facilities", qParams],
queryFn: query(routes.getAllFacilities, {
queryParams: {
name: qParams.search,
...(qParams.facility_type && { facility_type: qParams.facility_type }),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Inconsistent search parameter naming.

The code uses search in some places and name in others. Consider standardizing to one naming convention.

       queryParams: {
-        name: qParams.search,
+        search: qParams.search,
         ...(qParams.facility_type && { facility_type: qParams.facility_type }),
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
name: qParams.search,
...(qParams.facility_type && { facility_type: qParams.facility_type }),
search: qParams.search,
...(qParams.facility_type && { facility_type: qParams.facility_type }),

...(qParams.organization && {
organization: qParams.organization,
}),

page: qParams.page,
limit: RESULTS_PER_PAGE_LIMIT,
offset: (qParams.page - 1) * RESULTS_PER_PAGE_LIMIT,
Expand All @@ -68,7 +83,7 @@ export function FacilitiesPage() {
className="text-sm font-medium hover:bg-gray-100 rounded-full px-6"
onClick={() => navigate("/patient/home")}
>
Patient Dashboard
{t("patient_dashboard")}
</Button>
</div>
</header>
Expand All @@ -82,7 +97,7 @@ export function FacilitiesPage() {
className="text-sm font-medium hover:bg-gray-100 rounded-full px-6"
onClick={() => navigate("/login")}
>
Sign in
{t("sign_in")}
</Button>
</div>
</header>
Expand All @@ -99,20 +114,42 @@ export function FacilitiesPage() {
</Link>
<GetLoginHeader />
</div>
<div className="flex flex-col justify-between sm:flex-row items-center gap-4 mb-6">
<div className="flex flex-col justify-between sm:flex-row items-center gap-5 mb-6">
<OrganizationFilter
skipLevels={[]}
selected={selectedOrgs}
onChange={(filter, level) => {
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;
});
} else {
setSelectedOrgs([]);
}
}
if ("facility_type" in filter) {
updateQuery({ facility_type: filter.facility_type });
}
}}
className="flex flex-row w-full"
/>
<SearchByMultipleFields
id="facility-search"
options={[
{
key: "facility_search_text",
type: "text" as const,
placeholder: t("facility_search_placeholder_text"),
value: qParams.name || "",
value: qParams.search || "",
shortcutKey: "f",
},
]}
className="w-full sm:w-1/2"
onSearch={(key, value) => updateQuery({ name: value })}
className="w-[calc(100vw-1rem)] sm:w-3/12"
onSearch={(key, value) => updateQuery({ search: value })}
clearSearch={clearSearch}
enableOptionButtons={false}
/>
Expand Down
1 change: 0 additions & 1 deletion src/pages/Facility/FacilityDetailsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ export function FacilityDetailsPage({ id }: Props) {
className="border border-secondary-400"
>
<Link href="/facilities">
<CareIcon icon="l-square-shape" className="h-4 w-4 mr-1" />
<span className="text-sm underline">{t("back")}</span>
</Link>
</Button>
Expand Down
Loading
Loading