diff --git a/public/locale/en.json b/public/locale/en.json index b3b7800d687..6680adb2352 100644 --- a/public/locale/en.json +++ b/public/locale/en.json @@ -1873,6 +1873,7 @@ "select_eligible_policy": "Select an Eligible Insurance Policy", "select_facility": "Select Facility", "select_facility_description": "Select the healthcare facility that will provide the requested resource.", + "select_facility_feature": "Select Facility Features", "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", diff --git a/src/components/Facility/FacilityForm.tsx b/src/components/Facility/FacilityForm.tsx index 858842bcd41..45002d88bb2 100644 --- a/src/components/Facility/FacilityForm.tsx +++ b/src/components/Facility/FacilityForm.tsx @@ -19,6 +19,7 @@ import { FormMessage, } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; +import { MultiSelect } from "@/components/ui/multi-select"; import { Select, SelectContent, @@ -29,7 +30,6 @@ import { import { Textarea } from "@/components/ui/textarea"; import { FacilityModel } from "@/components/Facility/models"; -import { MultiSelectFormField } from "@/components/Form/FormFields/SelectFormField"; import { useStateAndDistrictFromPincode } from "@/hooks/useStateAndDistrictFromPincode"; @@ -112,7 +112,6 @@ export default function FacilityForm(props: FacilityProps) { onSubmitSuccess?.(); }, }); - const { mutate: updateFacility, isPending: isUpdatePending } = useMutation({ mutationFn: mutate(routes.updateFacility, { pathParams: { id: facilityId || "" }, @@ -148,8 +147,8 @@ export default function FacilityForm(props: FacilityProps) { } }; - const handleFeatureChange = (value: any) => { - const { value: features }: { value: Array } = value; + const handleFeatureChange = (value: string[]) => { + const features = value.map((val) => Number(val)); form.setValue("features", features); }; @@ -273,7 +272,6 @@ export default function FacilityForm(props: FacilityProps) { )} /> - )} /> - ( - - Features - - o.name} - optionValue={(o) => o.id} - onChange={handleFeatureChange} - error={form.formState.errors.features?.message} - id="facility-features" - /> - - - - )} + render={({ field }) => { + return ( + + {t("features")} + + ({ + value: obj.id.toString(), + label: obj.name, + icon: obj.icon, + }))} + onValueChange={handleFeatureChange} + value={field.value.map((val) => val.toString())} + placeholder={t("select_facility_feature")} + id="facility-features" + /> + + + + ); + }} /> @@ -519,6 +518,7 @@ export default function FacilityForm(props: FacilityProps) { + + setIsPopoverOpen(false)} + onWheel={(e) => e.stopPropagation()} + > + + + + + + {t("select_all")} + + {options.map((option) => { + const isSelected = selectedValues.includes(option.value); + return ( + toggleOption(option.value)} + className="cursor-pointer" + > + + {option?.icon && ( + + )} + {option.label} + + ); + })} + + + +
+ {selectedValues.length > 0 && ( + <> + + {t("clear")} + + + + )} + setIsPopoverOpen(false)} + className="flex-1 justify-center cursor-pointer max-w-full" + > + {t("close")} + +
+
+
+
+
+ + + ); + }, +); + +MultiSelect.displayName = "MultiSelect";