From 7cadb292d7d95b4705f0638772140d245b085d7d Mon Sep 17 00:00:00 2001 From: Khavin Shankar Date: Mon, 1 Dec 2025 17:32:54 +0530 Subject: [PATCH 1/2] use meta from props for handling config instead of envs --- .../ConfigureHealthFacilityForm.tsx | 15 ++++++++++---- src/components/GenerateScanAndShareQR.tsx | 7 ++++--- .../pluggables/EncounterActions.tsx | 3 ++- .../pluggables/FacilityHomeActions.tsx | 20 ++++++++++++------- ...PatientDetailsTabDemographyGeneralInfo.tsx | 10 ++++++---- .../pluggables/PatientHomeActions.tsx | 3 ++- .../pluggables/PatientRegistrationForm.tsx | 9 +++++---- .../pluggables/PatientSearchActions.tsx | 3 ++- src/config.ts | 4 ---- src/types/meta.ts | 14 +++++++++++++ src/vite-env.d.ts | 8 +++----- 11 files changed, 62 insertions(+), 34 deletions(-) create mode 100644 src/types/meta.ts diff --git a/src/components/ConfigureHealthFacilityForm.tsx b/src/components/ConfigureHealthFacilityForm.tsx index dd436af..e58bedb 100644 --- a/src/components/ConfigureHealthFacilityForm.tsx +++ b/src/components/ConfigureHealthFacilityForm.tsx @@ -26,6 +26,7 @@ import { GenerateScanAndShareQR } from "./GenerateScanAndShareQR"; import { HealthFacility } from "@/types/healthFacility"; import { I18NNAMESPACE } from "@/lib/constants"; import { Input } from "@/components/ui/input"; +import { Meta } from "@/types/meta"; import { apis } from "@/apis"; import { toast } from "@/lib/utils"; import { useForm } from "react-hook-form"; @@ -34,6 +35,7 @@ import { zodResolver } from "@hookform/resolvers/zod"; type ConfigureHealthFacilityFormProps = { facilityId: string; onSuccess?: (data: HealthFacility) => void; + meta?: Meta; }; const configureHealthFacilityFormSchema = z.object({ @@ -44,9 +46,11 @@ type ConfigureHealthFacilityFormValues = z.infer< typeof configureHealthFacilityFormSchema >; -export const ConfigureHealthFacilityForm: FC< - ConfigureHealthFacilityFormProps -> = ({ facilityId, onSuccess }) => { +export const ConfigureHealthFacilityForm: FC = ({ + facilityId, + onSuccess, + meta, +}) => { const { t } = useTranslation(I18NNAMESPACE); const { data: healthFacility, refetch } = useQuery({ @@ -221,7 +225,10 @@ export const ConfigureHealthFacilityForm: FC< {healthFacility && ( - + )} ); diff --git a/src/components/GenerateScanAndShareQR.tsx b/src/components/GenerateScanAndShareQR.tsx index 9040ce7..8042b28 100644 --- a/src/components/GenerateScanAndShareQR.tsx +++ b/src/components/GenerateScanAndShareQR.tsx @@ -13,7 +13,6 @@ import { Button } from "./ui/button"; import { I18NNAMESPACE } from "@/lib/constants"; import { Input } from "@/components/ui/input"; import { QRCodeSVG } from "qrcode.react"; -import { scanAndShareUrl } from "@/config"; import { useForm } from "react-hook-form"; import { useTranslation } from "react-i18next"; import { z } from "zod"; @@ -21,6 +20,7 @@ import { zodResolver } from "@hookform/resolvers/zod"; type GenerateScanAndShareQRProps = { healthFacilityId: string; + scanAndShareUrl?: string; }; const scanAndShareQrFormSchema = z.object({ @@ -29,6 +29,7 @@ const scanAndShareQrFormSchema = z.object({ export const GenerateScanAndShareQR: FC = ({ healthFacilityId, + scanAndShareUrl, }) => { const { t } = useTranslation(I18NNAMESPACE); @@ -84,7 +85,7 @@ export const GenerateScanAndShareQR: FC = ({ document.body.removeChild(downloadLink); }; - function onSubmit(_values: z.infer) { + function onSubmit() { downloadQR(); } @@ -135,7 +136,7 @@ export const GenerateScanAndShareQR: FC = ({ /> - {!!scanAndShareQrForm.watch("counterName") && ( + {!!scanAndShareQrForm.watch("counterName") && scanAndShareQrValue && (
= ({ +const EncounterActions: FC> = ({ encounter, className, }) => { diff --git a/src/components/pluggables/FacilityHomeActions.tsx b/src/components/pluggables/FacilityHomeActions.tsx index 35e2acb..54928ac 100644 --- a/src/components/pluggables/FacilityHomeActions.tsx +++ b/src/components/pluggables/FacilityHomeActions.tsx @@ -1,9 +1,4 @@ import { FC, useState } from "react"; -import { useTranslation } from "react-i18next"; -import { Button } from "@/components/ui/button"; -import { Facility } from "@/types/facility"; -import { SettingsIcon } from "lucide-react"; -import { ConfigureHealthFacilityForm } from "../ConfigureHealthFacilityForm"; import { Sheet, SheetContent, @@ -12,15 +7,25 @@ import { SheetTitle, SheetTrigger, } from "@/components/ui/sheet"; -import { useQueryClient } from "@tanstack/react-query"; + +import { Button } from "@/components/ui/button"; +import { ConfigureHealthFacilityForm } from "../ConfigureHealthFacilityForm"; +import { Facility } from "@/types/facility"; import { I18NNAMESPACE } from "@/lib/constants"; +import { SettingsIcon } from "lucide-react"; +import { WithMeta } from "@/types/meta"; +import { useQueryClient } from "@tanstack/react-query"; +import { useTranslation } from "react-i18next"; type FacilityHomeActionsProps = { facility: Facility; className?: string; }; -const FacilityHomeActions: FC = ({ facility }) => { +const FacilityHomeActions: FC> = ({ + facility, + __meta, +}) => { const { t } = useTranslation(I18NNAMESPACE); const queryClient = useQueryClient(); @@ -59,6 +64,7 @@ const FacilityHomeActions: FC = ({ facility }) => { }); setOpen(false); }} + meta={__meta} />
diff --git a/src/components/pluggables/PatientDetailsTabDemographyGeneralInfo.tsx b/src/components/pluggables/PatientDetailsTabDemographyGeneralInfo.tsx index 712a30e..0709803 100644 --- a/src/components/pluggables/PatientDetailsTabDemographyGeneralInfo.tsx +++ b/src/components/pluggables/PatientDetailsTabDemographyGeneralInfo.tsx @@ -1,11 +1,13 @@ +import { FileDownIcon, ImageDownIcon } from "lucide-react"; +import { useMutation, useQuery } from "@tanstack/react-query"; + +import { Button } from "@/components/ui/button"; import { FC } from "react"; import { I18NNAMESPACE } from "@/lib/constants"; import { Patient } from "@/types/patient"; +import { WithMeta } from "@/types/meta"; import { apis } from "@/apis"; -import { useMutation, useQuery } from "@tanstack/react-query"; import { useTranslation } from "react-i18next"; -import { Button } from "@/components/ui/button"; -import { ImageDownIcon, FileDownIcon } from "lucide-react"; type PatientDetailsTabDemographyGeneralInfoProps = { patientData: Patient; @@ -14,7 +16,7 @@ type PatientDetailsTabDemographyGeneralInfoProps = { }; const PatientDetailsTabDemographyGeneralInfo: FC< - PatientDetailsTabDemographyGeneralInfoProps + WithMeta > = ({ patientId }) => { const { t } = useTranslation(I18NNAMESPACE); diff --git a/src/components/pluggables/PatientHomeActions.tsx b/src/components/pluggables/PatientHomeActions.tsx index 51092eb..1449617 100644 --- a/src/components/pluggables/PatientHomeActions.tsx +++ b/src/components/pluggables/PatientHomeActions.tsx @@ -3,6 +3,7 @@ import { useMutation, useQuery } from "@tanstack/react-query"; import { FC } from "react"; import { LinkAbhaNumber } from "@/components/LinkAbhaNumber"; import { Patient } from "@/types/patient"; +import { WithMeta } from "@/types/meta"; import { apis } from "@/apis"; import { toast } from "@/lib/utils"; @@ -12,7 +13,7 @@ type PatientHomeActionsProps = { className?: string; }; -const PatientHomeActions: FC = ({ +const PatientHomeActions: FC> = ({ patient, facilityId, className, diff --git a/src/components/pluggables/PatientRegistrationForm.tsx b/src/components/pluggables/PatientRegistrationForm.tsx index 8bb707c..36ad7c0 100644 --- a/src/components/pluggables/PatientRegistrationForm.tsx +++ b/src/components/pluggables/PatientRegistrationForm.tsx @@ -6,8 +6,8 @@ import { Label } from "@/components/ui/label"; import { LinkAbhaNumber } from "../LinkAbhaNumber"; import { ShowAbhaProfile } from "../LinkAbhaNumber/ShowAbhaProfile"; import { UseFormReturn } from "react-hook-form"; +import { WithMeta } from "@/types/meta"; import { apis } from "@/apis"; -import { enforceAbhaNumberLinking } from "@/config"; import { toast } from "@/lib/utils"; type PatientRegistrationFormProps = { @@ -16,10 +16,11 @@ type PatientRegistrationFormProps = { patientId?: string; }; -const PatientRegistrationForm: FC = ({ +const PatientRegistrationForm: FC> = ({ form, facilityId, patientId, + __meta, }) => { const queryClient = useQueryClient(); @@ -89,9 +90,9 @@ const PatientRegistrationForm: FC = ({ return (
= ({ +const PatientSearchActions: FC> = ({ facilityId, className, }) => { diff --git a/src/config.ts b/src/config.ts index b703f05..e69de29 100644 --- a/src/config.ts +++ b/src/config.ts @@ -1,4 +0,0 @@ -export const scanAndShareUrl = import.meta.env.REACT_SCAN_AND_SHARE_URL; - -export const enforceAbhaNumberLinking = - import.meta.env.REACT_ENFORCE_ABHA_NUMBER_LINKING === "true"; \ No newline at end of file diff --git a/src/types/meta.ts b/src/types/meta.ts new file mode 100644 index 0000000..9429b2b --- /dev/null +++ b/src/types/meta.ts @@ -0,0 +1,14 @@ +export type MetaConfig = { + enforceAbhaNumberLinking?: boolean; + scanAndShareUrl?: string; +}; + +export type Meta = { + name?: string; + url?: string; + config?: MetaConfig; +}; + +export type WithMeta = T & { + __meta?: Meta; +}; diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts index 60fce75..ffc9c31 100644 --- a/src/vite-env.d.ts +++ b/src/vite-env.d.ts @@ -1,13 +1,11 @@ /// /// -interface ImportMetaEnv { - readonly REACT_SCAN_AND_SHARE_URL: string; - readonly REACT_ENFORCE_ABHA_NUMBER_LINKING: string; -} +// eslint-disable-next-line @typescript-eslint/no-empty-object-type +interface ImportMetaEnv {} declare global { - var __CORE_ENV__: { + const __CORE_ENV__: { readonly apiUrl: string; }; } From c92329132ca63a1dd46a11c64370c869b8a05eed Mon Sep 17 00:00:00 2001 From: Khavin Shankar Date: Thu, 19 Feb 2026 13:38:34 +0530 Subject: [PATCH 2/2] added types for window meta config --- .../LinkAbhaNumber/CreateWithAadhaar.tsx | 8 ++++--- src/vite-env.d.ts | 22 +++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/src/components/LinkAbhaNumber/CreateWithAadhaar.tsx b/src/components/LinkAbhaNumber/CreateWithAadhaar.tsx index 17bf907..0dfd301 100644 --- a/src/components/LinkAbhaNumber/CreateWithAadhaar.tsx +++ b/src/components/LinkAbhaNumber/CreateWithAadhaar.tsx @@ -40,7 +40,6 @@ import { QRCodeSVG } from "qrcode.react"; import { Textarea } from "@/components/ui/textarea"; import { apis } from "@/apis"; import { cn } from "@/lib/utils"; -import { faceAuthUrl } from "@/config"; import { toast } from "@/lib/utils"; import { useForm } from "react-hook-form"; import { useLinkAbhaNumberContext } from "."; @@ -168,6 +167,8 @@ const EnterAadhaar: FC = ({ setMemory, goTo }) => { const { t } = useTranslation(I18NNAMESPACE); const { healthFacility, currentUser } = useLinkAbhaNumberContext(); + const faceAuthUrl = window.__CARE_PLUGIN_RUNTIME__?.meta?.care_abdm_fe?.config?.faceAuthUrl; + const form = useForm({ resolver: zodResolver(enterAadhaarFormSchema), defaultValues: { @@ -342,7 +343,7 @@ const EnterAadhaar: FC = ({ setMemory, goTo }) => { > {t("verify_with_bio")} - + }
@@ -894,6 +895,7 @@ const VerifyAadhaarWithFace: FC = ({ }) => { const { t } = useTranslation(I18NNAMESPACE); const [isPolling, setIsPolling] = useState(false); + const faceAuthUrl = window?.__CARE_PLUGIN_RUNTIME__?.meta?.care_abdm_fe?.config?.faceAuthUrl; const form = useForm({ resolver: zodResolver(verifyAadhaarWithFaceFormSchema), diff --git a/src/vite-env.d.ts b/src/vite-env.d.ts index ffc9c31..a765633 100644 --- a/src/vite-env.d.ts +++ b/src/vite-env.d.ts @@ -4,8 +4,30 @@ // eslint-disable-next-line @typescript-eslint/no-empty-object-type interface ImportMetaEnv {} +interface CareAbdmFePluginConfig { + faceAuthUrl?: string; + enforceAbhaNumberLinking?: boolean; + scanAndShareUrl?: string; +} + +interface CarePluginRuntimeMeta { + care_abdm_fe?: { + config?: CareAbdmFePluginConfig; + }; +} + +interface CarePluginRuntime { + meta?: CarePluginRuntimeMeta; +} + declare global { const __CORE_ENV__: { readonly apiUrl: string; }; + + interface Window { + __CARE_PLUGIN_RUNTIME__?: CarePluginRuntime; + } } + +export {};