From c7f9bf9bf9bae5db1dcfc93a8a160c3ba4fbf5e2 Mon Sep 17 00:00:00 2001 From: Shyam prakash <106866225+shyamprakash123@users.noreply.github.com> Date: Wed, 18 Oct 2023 15:59:28 +0530 Subject: [PATCH] Replaced useDispatch with useQuery and request. (#6344) * Replaced useDispatch with useQuery and request. * Removed all relevant no longer used actions from actions.tsx * Replaced Res to Type * Added TBody. * used abha in place of JSON.parse(value). * Fixed mobile otp issue * Replaced Rdata with Rerror * Fixed link care context --------- Co-authored-by: Khavin Shankar --- src/Components/ABDM/ABHAProfileModal.tsx | 19 +- .../ABDM/ConfigureHealthFacility.tsx | 98 ++++--- src/Components/ABDM/LinkABHANumberModal.tsx | 187 ++++++++----- src/Components/ABDM/LinkCareContextModal.tsx | 19 +- src/Components/ABDM/models.ts | 81 ++++++ .../Notifications/NotificationsList.tsx | 20 +- src/Redux/actions.tsx | 80 ------ src/Redux/api.tsx | 264 +++++++++++------- src/Utils/request/request.ts | 1 + 9 files changed, 445 insertions(+), 324 deletions(-) diff --git a/src/Components/ABDM/ABHAProfileModal.tsx b/src/Components/ABDM/ABHAProfileModal.tsx index 0d6b7d9b90b..cc16fd45b8d 100644 --- a/src/Components/ABDM/ABHAProfileModal.tsx +++ b/src/Components/ABDM/ABHAProfileModal.tsx @@ -5,9 +5,9 @@ import CareIcon from "../../CAREUI/icons/CareIcon"; import DialogModal from "../Common/Dialog"; import QRCode from "qrcode.react"; import { formatDateTime } from "../../Utils/utils"; -import { getAbhaCard } from "../../Redux/actions"; -import { useDispatch } from "react-redux"; import { useRef } from "react"; +import request from "../../Utils/request/request"; +import routes from "../../Redux/api"; interface IProps { patientId?: string; @@ -18,21 +18,24 @@ interface IProps { const ABHAProfileModal = ({ patientId, show, onClose, abha }: IProps) => { const printRef = useRef(null); - const dispatch = useDispatch(); const downloadAbhaCard = async (type: "pdf" | "png") => { if (!patientId) return; - const response = await dispatch(getAbhaCard(patientId, type)); + const { res, data } = await request(routes.abha.getAbhaCard, { + body: { + patient: patientId, + type: type, + }, + }); - if (response.status === 200 && response.data) { + if (res?.status === 200 && data) { if (type === "png") { const downloadLink = document.createElement("a"); - downloadLink.href = - "data:application/octet-stream;base64," + response.data; + downloadLink.href = "data:application/octet-stream;base64," + data; downloadLink.download = "abha.png"; downloadLink.click(); } else { - const htmlPopup = ``; + const htmlPopup = ``; const printWindow = window.open("", "PDF"); printWindow?.document.write(htmlPopup); diff --git a/src/Components/ABDM/ConfigureHealthFacility.tsx b/src/Components/ABDM/ConfigureHealthFacility.tsx index 025a3f0e862..a2b8f254bcb 100644 --- a/src/Components/ABDM/ConfigureHealthFacility.tsx +++ b/src/Components/ABDM/ConfigureHealthFacility.tsx @@ -1,12 +1,12 @@ -import { lazy, useCallback, useEffect, useReducer, useState } from "react"; -import { useDispatch } from "react-redux"; - -import { healthFacilityActions } from "../../Redux/actions"; +import { lazy, useEffect, useReducer, useState } from "react"; import * as Notification from "../../Utils/Notifications.js"; import { navigate } from "raviger"; import { Cancel, Submit } from "../Common/components/ButtonV2"; import TextFormField from "../Form/FormFields/TextFormField"; import { classNames } from "../../Utils/utils"; +import useQuery from "../../Utils/request/useQuery"; +import routes from "../../Redux/api"; +import request from "../../Utils/request/request"; const Loading = lazy(() => import("../Common/Loading")); const initForm = { @@ -40,30 +40,28 @@ const FormReducer = (state = initialState, action: any) => { export const ConfigureHealthFacility = (props: any) => { const [state, dispatch] = useReducer(FormReducer, initialState); const { facilityId } = props; - const dispatchAction: any = useDispatch(); const [isLoading, setIsLoading] = useState(false); - const fetchData = useCallback(async () => { - if (facilityId) { - setIsLoading(true); - const res = await dispatchAction(healthFacilityActions.read(facilityId)); - - if (res?.status === 200 && res?.data) { - const formData = { - ...state.form, - hf_id: res.data.hf_id, - health_facility: res.data, - }; - dispatch({ type: "set_form", form: formData }); - } + const { + data: health_facility, + loading, + refetch, + } = useQuery(routes.abha.getHealthFacility, { + pathParams: { facility__external_id: facilityId }, + }); - setIsLoading(false); - } - }, [dispatchAction, facilityId]); + useEffect(() => { + const formData = { + ...state.form, + hf_id: health_facility?.hf_id, + health_facility: health_facility, + }; + dispatch({ type: "set_form", form: formData }); + }, [health_facility]); useEffect(() => { - fetchData(); - }, [dispatch, fetchData]); + refetch(); + }, [dispatch, refetch]); const handleSubmit = async (e: any) => { e.preventDefault(); @@ -78,27 +76,43 @@ export const ConfigureHealthFacility = (props: any) => { return; } - let res = null; + let response = null; + let responseData = null; if (state.form.health_facility) { - res = await dispatchAction( - healthFacilityActions.partialUpdate(facilityId, { - hf_id: state.form.hf_id, - }) + const { res, data } = await request( + routes.abha.partialUpdateHealthFacility, + { + pathParams: { + facility__external_id: facilityId, + }, + body: { + hf_id: state.form.hf_id, + }, + } ); + response = res; + responseData = data; } else if (state.form.hf_id === state.form.health_facility?.hf_id) { - res = await dispatchAction( - healthFacilityActions.registerService(facilityId) + const { res, data } = await request( + routes.abha.registerHealthFacilityAsService, + { + pathParams: { + facility__external_id: facilityId, + }, + } ); + response = res; + responseData = data; - if (res?.status === 200 && res?.data) { - if (res.data?.registered) { + if (response?.status === 200 && responseData) { + if (responseData?.registered) { dispatch({ type: "set_form", form: { ...state.form, health_facility: { ...state.form?.health_facility, - registered: res.data.registered, + registered: responseData.registered, }, }, }); @@ -112,24 +126,26 @@ export const ConfigureHealthFacility = (props: any) => { }); return; } else { - res = await dispatchAction( - healthFacilityActions.create({ + const { res, data } = await request(routes.abha.createHealthFacility, { + body: { facility: facilityId, hf_id: state.form.hf_id, - }) - ); + }, + }); + response = res; + responseData = data; } setIsLoading(false); - if (res && res.data) { + if (response && responseData) { Notification.Success({ msg: "Health Facility config updated successfully", }); navigate(`/facility/${facilityId}`); } else { - if (res?.data) + if (responseData) Notification.Error({ - msg: "Something went wrong: " + (res.data.detail || ""), + msg: "Something went wrong: " + (responseData.detail || ""), }); } setIsLoading(false); @@ -142,7 +158,7 @@ export const ConfigureHealthFacility = (props: any) => { }); }; - if (isLoading) { + if (loading || isLoading) { return ; } diff --git a/src/Components/ABDM/LinkABHANumberModal.tsx b/src/Components/ABDM/LinkABHANumberModal.tsx index 30b1ff4afa3..367c9815db1 100644 --- a/src/Components/ABDM/LinkABHANumberModal.tsx +++ b/src/Components/ABDM/LinkABHANumberModal.tsx @@ -1,19 +1,6 @@ import * as Notify from "../../Utils/Notifications"; import Dropdown, { DropdownItem } from "../Common/components/Menu"; -import { - checkAndGenerateMobileOtp, - confirmWithAadhaarOtp, - confirmWithMobileOtp, - createHealthId, - generateAadhaarOtp, - initiateAbdmAuthentication, - linkViaQR, - resentAadhaarOtp, - searchByHealthId, - verifyAadhaarOtp, - verifyMobileOtp, -} from "../../Redux/actions"; import { useEffect, useState } from "react"; import ButtonV2 from "../Common/components/ButtonV2"; @@ -24,7 +11,8 @@ import OtpFormField from "../Form/FormFields/OtpFormField"; import QRScanner from "../Common/QRScanner"; import TextFormField from "../Form/FormFields/TextFormField"; import { classNames } from "../../Utils/utils"; -import { useDispatch } from "react-redux"; +import request from "../../Utils/request/request"; +import routes from "../../Redux/api"; export const validateRule = ( condition: boolean, @@ -144,8 +132,6 @@ const ScanABHAQRSection = ({ onSuccess, closeModal, }: ScanABHAQRSectionProps) => { - const dispatch = useDispatch(); - const [qrValue, setQrValue] = useState(""); const [authMethods, setAuthMethods] = useState([]); const [selectedAuthMethod, setSelectedAuthMethod] = useState(""); @@ -187,23 +173,23 @@ const ScanABHAQRSection = ({ try { const abha = JSON.parse(value); - const res = await dispatch(linkViaQR(abha, patientId)); + const { res, data } = await request(routes.abha.linkViaQR, { + body: { ...abha, patientId }, + }); if (res?.status === 200 || res?.status === 202) { Notify.Success({ msg: "Request sent successfully" }); onSuccess?.({ - ...res.data, + ...data, abha_profile: { - ...res.data?.abha_profile, - healthIdNumber: res.data?.abha_profile?.abha_number, - healthId: res.data?.abha_profile?.health_id, + ...data?.abha_profile, + healthIdNumber: data?.abha_profile?.abha_number, + healthId: data?.abha_profile?.health_id, mobile: abha?.mobile, monthOfBirth: - res.data?.abha_profile?.date_of_birth?.split("-")[1], - dayOfBirth: - res.data?.abha_profile?.date_of_birth?.split("-")[2], - yearOfBirth: - res.data?.abha_profile?.date_of_birth?.split("-")[0], + data?.abha_profile?.date_of_birth?.split("-")[1], + dayOfBirth: data?.abha_profile?.date_of_birth?.split("-")[2], + yearOfBirth: data?.abha_profile?.date_of_birth?.split("-")[0], }, }); } else { @@ -256,29 +242,55 @@ const ScanABHAQRSection = ({ disabled={otp.length !== 6} onClick={async () => { let response = null; + let Rdata = null; + let Rerror = null; switch (selectedAuthMethod) { case "MOBILE_OTP": - response = await dispatch( - confirmWithMobileOtp(txnId, otp, patientId) - ); + { + const { res, data, error } = await request( + routes.abha.confirmWithMobileOtp, + { + body: { + otp: otp, + txnId: txnId, + patientId: patientId, + }, + } + ); + response = res; + Rdata = data; + Rerror = error; + } break; case "AADHAAR_OTP": - response = await dispatch( - confirmWithAadhaarOtp(txnId, otp, patientId) - ); + { + const { res, data, error } = await request( + routes.abha.confirmWithAadhaarOtp, + { + body: { + otp: otp, + txnId: txnId, + patientId: patientId, + }, + } + ); + response = res; + Rdata = data; + Rerror = error; + } break; } - if (response.status === 200) { - onSuccess?.(response.data); + if (response?.status === 200) { + onSuccess?.(Rdata); Notify.Success({ msg: "ABHA Number linked successfully", }); } else { Notify.Error({ - msg: response?.message ?? "Something went wrong!", + msg: Rerror ?? "Something went wrong!", }); } }} @@ -290,13 +302,14 @@ const ScanABHAQRSection = ({ {authMethods.map((method) => ( { - const response = await dispatch( - initiateAbdmAuthentication(method, qrValue) + const { res, data } = await request( + routes.abha.initiateAbdmAuthentication, + { body: { authMethod: method, healthid: qrValue } } ); - if (response.status === 200 && response?.data?.txnId) { + if (res?.status === 200 && data?.txnId) { setSelectedAuthMethod(method); - setTxnId(response.data.txnId); + setTxnId(data.txnId); } }} > @@ -308,11 +321,18 @@ const ScanABHAQRSection = ({ { - const response = await dispatch(searchByHealthId(qrValue)); - - if (response.status === 200 && response?.data?.authMethods) { + const { res, data } = await request( + routes.abha.searchByHealthId, + { + body: { + healthId: qrValue, + }, + } + ); + + if (res?.status === 200 && data?.authMethods) { setAuthMethods( - response.data.authMethods?.filter?.((method: string) => + data.authMethods?.filter?.((method: string) => supportedAuthMethods.find( (supported) => supported === method ) @@ -339,8 +359,6 @@ const VerifyAadhaarSection = ({ onVerified, onSignin, }: VerifyAadhaarSectionProps) => { - const dispatch = useDispatch(); - const [aadhaarNumber, setAadhaarNumber] = useState(""); const [aadhaarNumberError, setAadhaarNumberError] = useState(); @@ -382,17 +400,22 @@ const VerifyAadhaarSection = ({ if (!validateAadhaar()) return; setIsSendingOtp(true); - const res = await dispatch(generateAadhaarOtp(aadhaarNumber)); + + const { res, data } = await request(routes.abha.generateAadhaarOtp, { + body: { + aadhaar: aadhaarNumber, + }, + }); setIsSendingOtp(false); - if (res.status === 200 && res.data) { - const { txnId } = res.data; + if (res?.status === 200 && data) { + const { txnId } = data; setTxnId(txnId); Notify.Success({ msg: "OTP has been sent to the mobile number registered with the Aadhar number.", }); } else { - Notify.Error({ msg: JSON.stringify(res.data) }); + Notify.Error({ msg: JSON.stringify(data) }); } }; @@ -400,16 +423,20 @@ const VerifyAadhaarSection = ({ if (!validateAadhaar() || !txnId) return; setIsSendingOtp(true); - const res = await dispatch(resentAadhaarOtp(txnId)); + const { res, data } = await request(routes.abha.generateAadhaarOtp, { + body: { + txnId: txnId, + }, + }); setIsSendingOtp(false); - if (res.status === 200 && res.data.txnId) { - setTxnId(res.data.txnId); + if (res?.status === 200 && data?.txnId) { + setTxnId(data.txnId); Notify.Success({ msg: "OTP has been resent to the mobile number registered with the Aadhar number.", }); } else { - Notify.Error({ msg: JSON.stringify(res.data) }); + Notify.Error({ msg: JSON.stringify(data) }); } }; @@ -430,11 +457,16 @@ const VerifyAadhaarSection = ({ if (!validateOtp() || !txnId) return; setIsVerifyingOtp(true); - const res = await dispatch(verifyAadhaarOtp(txnId, otp)); + const { res, data } = await request(routes.abha.verifyAadhaarOtp, { + body: { + otp: otp, + txnId: txnId, + }, + }); setIsVerifyingOtp(false); - if (res.status === 200 && res.data.txnId) { - setTxnId(res.data.txnId); + if (res?.status === 200 && data?.txnId) { + setTxnId(data.txnId); Notify.Success({ msg: "OTP verified" }); setIsVerified(true); } else { @@ -563,8 +595,6 @@ const VerifyMobileSection = ({ onVerified, patientMobile, }: VerifyMobileSectionProps) => { - const dispatch = useDispatch(); - const [mobile, setMobile] = useState(() => patientMobile || ""); const [mobileError, setMobileError] = useState(); @@ -602,11 +632,16 @@ const VerifyMobileSection = ({ setOtpDispatched(false); setIsSendingOtp(true); - const res = await dispatch(checkAndGenerateMobileOtp(txnId, mobile)); + const { res, data } = await request(routes.abha.checkAndGenerateMobileOtp, { + body: { + mobile: mobile, + txnId: txnId, + }, + }); setIsSendingOtp(false); - if (res.status === 200 && res.data) { - const { txnId, mobileLinked } = res.data; + if (res?.status === 200 && data) { + const { txnId, mobileLinked } = data; setTxnId(txnId); if (mobileLinked) { @@ -621,7 +656,7 @@ const VerifyMobileSection = ({ }); } } else { - Notify.Error({ msg: JSON.stringify(res.data) }); + Notify.Error({ msg: JSON.stringify(data) }); } }; @@ -642,11 +677,16 @@ const VerifyMobileSection = ({ if (!validateOtp()) return; setIsVerifyingOtp(true); - const res = await dispatch(verifyMobileOtp(txnId, otp)); + const { res, data } = await request(routes.abha.verifyMobileOtp, { + body: { + txnId: txnId, + otp: otp, + }, + }); setIsVerifyingOtp(false); - if (res.status === 200 && res.data.txnId) { - setTxnId(res.data.txnId); + if (res?.status === 200 && data?.txnId) { + setTxnId(data.txnId); Notify.Success({ msg: "OTP verified" }); setIsVerified(true); } else { @@ -718,21 +758,24 @@ const CreateHealthIDSection = ({ onCreateSuccess, patientId, }: CreateHealthIDSectionProps) => { - const dispatch = useDispatch(); const [healthId, setHealthId] = useState(""); const [isCreating, setIsCreating] = useState(false); const [isHealthIdInputInFocus, setIsHealthIdInputInFocus] = useState(false); const handleCreateHealthId = async () => { setIsCreating(true); - const res = await dispatch( - createHealthId({ txnId: transactionId, patientId, healthId }) - ); - if (res.status === 200) { + const { res, data } = await request(routes.abha.createHealthId, { + body: { + healthId: healthId, + txnId: transactionId, + patientId: patientId, + }, + }); + if (res?.status === 200) { Notify.Success({ msg: "Abha Address created" }); - onCreateSuccess(res.data); + onCreateSuccess(data); } else { - Notify.Error({ msg: JSON.stringify(res.data) }); + Notify.Error({ msg: JSON.stringify(data) }); } setIsCreating(false); }; diff --git a/src/Components/ABDM/LinkCareContextModal.tsx b/src/Components/ABDM/LinkCareContextModal.tsx index fc0b488954d..36749ff3d23 100644 --- a/src/Components/ABDM/LinkCareContextModal.tsx +++ b/src/Components/ABDM/LinkCareContextModal.tsx @@ -5,9 +5,9 @@ import DateFormField from "../Form/FormFields/DateFormField"; import DialogModal from "../Common/Dialog"; import { PatientModel } from "../Patient/models"; import TextFormField from "../Form/FormFields/TextFormField"; -import { linkCareContext } from "../../Redux/actions"; -import { useDispatch } from "react-redux"; import { useState } from "react"; +import routes from "../../Redux/api.js"; +import request from "../../Utils/request/request.js"; interface IProps { consultationId: string; @@ -25,8 +25,6 @@ const LinkCareContextModal = ({ const [acceptedDisclaimer, setAcceptedDisclaimer] = useState(false); const [isLinkingCareContext, setIsLinkingCareContext] = useState(false); - const dispatch = useDispatch(); - return ( { setIsLinkingCareContext(true); - const res = await dispatch( - linkCareContext(consultationId, { + const { res } = await request(routes.abha.linkCareContext, { + body: { + consultation: consultationId, name: patient?.abha_number_object?.name, gender: patient?.abha_number_object?.gender, dob: patient?.abha_number_object?.date_of_birth, - }) - ); - - if (res.status === 202) { + }, + reattempts: 0, + }); + if (res?.status === 202) { Notification.Success({ msg: "Care Context sucessfully linked!", }); diff --git a/src/Components/ABDM/models.ts b/src/Components/ABDM/models.ts index b01579fba88..f992cc9df4f 100644 --- a/src/Components/ABDM/models.ts +++ b/src/Components/ABDM/models.ts @@ -17,3 +17,84 @@ export interface ICreateHealthIdResponse { healthId?: string; healthIdNumber: string; } + +export interface IHealthFacility { + id: string; + registered: boolean; + external_id: string; + created_date: string; + modified_date: string; + hf_id: string; + facility: string; + detail?: string; +} + +export interface ILinkABHANumber { + abha_profile: { + abha_number: string; + health_id: string; + date_of_birth: string; + }; +} + +export interface IConfirmMobileOtp { + otp: string; + txnId: string; + patientId?: string; + message?: string; +} + +export interface IHealthId { + authMethods?: string[]; +} + +export interface IAadhaarOtp { + txnId: string; +} + +export interface ICheckAndGenerateMobileOtp { + mobileLinked: boolean; + txnId: string; +} + +export interface IAadhaarOtpTBody { + aadhaar?: string; + txnId?: string; +} + +export interface IVerifyAadhaarOtpTBody { + consultation?: string; + name?: string; + gender?: "M" | "F" | "O"; + dob?: string; + otp?: string; + txnId?: string; +} + +export interface IGenerateMobileOtpTBody { + mobile: string; + txnId: string; +} + +export interface ISearchByHealthIdTBody { + healthId: string; +} + +export interface IinitiateAbdmAuthenticationTBody { + authMethod: string; + healthid: string; +} + +export interface IgetAbhaCardTBody { + patient: string; + type: "pdf" | "png"; +} + +export interface IcreateHealthFacilityTBody { + facility: string; + hf_id: string; +} + +export interface IpartialUpdateHealthFacilityTBody { + hf_id: string; +} diff --git a/src/Components/Notifications/NotificationsList.tsx b/src/Components/Notifications/NotificationsList.tsx index 5e3aa65b3ec..5f124516a14 100644 --- a/src/Components/Notifications/NotificationsList.tsx +++ b/src/Components/Notifications/NotificationsList.tsx @@ -353,15 +353,17 @@ export default function NotificationsList({ manageResults = ( <> {data - .filter((notification: any) => showUnread ? notification.read_at === null : true) - .map((result: any) => ( - - ))} + .filter((notification: any) => + showUnread ? notification.read_at === null : true + ) + .map((result: any) => ( + + ))} {isLoading && (
diff --git a/src/Redux/actions.tsx b/src/Redux/actions.tsx index 7a92b1a7658..1d2d6f4f7b6 100644 --- a/src/Redux/actions.tsx +++ b/src/Redux/actions.tsx @@ -6,8 +6,6 @@ import { } from "../Components/Medicine/models"; import { fireRequest, fireRequestForFiles } from "./fireRequest"; -import { ICreateHealthIdRequest } from "../Components/ABDM/models"; - export const getConfig = () => { return fireRequestForFiles("config"); }; @@ -844,54 +842,13 @@ export const operateAsset = (id: string, params: object) => fireRequest("operateAsset", [], params, { external_id: id }); // ABDM related -export const generateAadhaarOtp = (aadhaar: string) => - fireRequest("generateAadhaarOtp", [], { aadhaar }); export const resentAadhaarOtp = (txnId: string) => fireRequest("resendAadhaarOtp", [], { txnId }); -export const verifyAadhaarOtp = (txnId: string, otp: string) => - fireRequest("verifyAadhaarOtp", [], { txnId, otp }); - export const generateMobileOtp = (txnId: string, mobile: string) => fireRequest("generateMobileOtp", [], { txnId, mobile }); -export const checkAndGenerateMobileOtp = (txnId: string, mobile: string) => - fireRequest("checkAndGenerateMobileOtp", [], { txnId, mobile }); - -export const verifyMobileOtp = (txnId: string, otp: string) => - fireRequest("verifyMobileOtp", [], { txnId, otp }); - -export const createHealthId = (data: ICreateHealthIdRequest) => - fireRequest("createHealthId", [], data); - -export const searchByHealthId = (healthId: string) => - fireRequest("searchByHealthId", [], { healthId }); - -export const initiateAbdmAuthentication = ( - authMethod: string, - healthid: string -) => fireRequest("initiateAbdmAuthentication", [], { authMethod, healthid }); - -export const confirmWithAadhaarOtp = ( - txnId: string, - otp: string, - patientId?: string -) => fireRequest("confirmWithAadhaarOtp", [], { txnId, otp, patientId }); - -export const confirmWithMobileOtp = ( - txnId: string, - otp: string, - patientId?: string -) => fireRequest("confirmWithMobileOtp", [], { txnId, otp, patientId }); - -export const linkViaQR = (abha_details: any, patientId?: string) => { - return fireRequest("linkViaQR", [], { - ...abha_details, - patientId, - }); -}; - export const linkCareContext = ( consultationId: string, data: { name?: string; gender?: "M" | "F" | "O"; dob?: string } @@ -902,53 +859,16 @@ export const linkCareContext = ( }); }; -export const getAbhaCard = (patient: string, type: "pdf" | "png") => { - return fireRequest("getAbhaCard", [], { - patient, - type, - }); -}; - export const healthFacilityActions = { list: (params: object) => { return fireRequest("listHealthFacilities", [], params); }, - create: (data: object) => { - return fireRequest("createHealthFacility", [], data); - }, - - read: (id: string) => { - return fireRequest( - "getHealthFacility", - [], - {}, - { facility_id: id }, - undefined, - true - ); - }, - update: (id: string, data: object) => { return fireRequest("updateHealthFacility", [], data, { facility_id: id, }); }, - - partialUpdate: (id: string, data: object) => { - return fireRequest("partialUpdateHealthFacility", [], data, { - facility_id: id, - }); - }, - - registerService: (id: string) => { - return fireRequest( - "registerHealthFacilityAsService", - [], - {}, - { facility_id: id } - ); - }, }; export const listAssetAvailability = (params: object) => diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index a05d461c98d..7e1ef24c058 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -1,5 +1,23 @@ import { IConfig } from "../Common/hooks/useConfig"; - +import { + IAadhaarOtp, + IAadhaarOtpTBody, + ICheckAndGenerateMobileOtp, + IConfirmMobileOtp, + ICreateHealthIdRequest, + ICreateHealthIdResponse, + IGenerateMobileOtpTBody, + IHealthFacility, + IHealthId, + ILinkABHANumber, + ISearchByHealthIdTBody, + IVerifyAadhaarOtpTBody, + IcreateHealthFacilityTBody, + IgetAbhaCardTBody, + IinitiateAbdmAuthenticationTBody, + IpartialUpdateHealthFacilityTBody, +} from "../Components/ABDM/models"; +import { AssetData } from "../Components/Assets/AssetTypes"; import { AssetBedBody, AssetBedModel, @@ -11,7 +29,6 @@ import { AssetUpdate, } from "../Components/Assets/AssetTypes"; import { FacilityModel, LocationModel, WardModel } from "../Components/Facility/models"; - import { IDeleteExternalResult, IExternalResult, @@ -916,108 +933,147 @@ const routes = { TBody: Type(), }, - // ABDM HealthID endpoints - generateAadhaarOtp: { - path: "/api/v1/abdm/healthid/generate_aadhaar_otp/", - method: "POST", - }, - - resendAadhaarOtp: { - path: "/api/v1/abdm/healthid/resend_aadhaar_otp/", - method: "POST", - }, - - verifyAadhaarOtp: { - path: "/api/v1/abdm/healthid/verify_aadhaar_otp/", - method: "POST", - }, - - generateMobileOtp: { - path: "/api/v1/abdm/healthid/generate_mobile_otp/", - method: "POST", - }, - - checkAndGenerateMobileOtp: { - path: "/api/v1/abdm/healthid/check_and_generate_mobile_otp/", - method: "POST", - }, - - // TODO: resend mobile otp - verifyMobileOtp: { - path: "/api/v1/abdm/healthid/verify_mobile_otp/", - method: "POST", - }, - - createHealthId: { - path: "/api/v1/abdm/healthid/create_health_id/", - method: "POST", - }, - - searchByHealthId: { - path: "/api/v1/abdm/healthid/search_by_health_id/", - method: "POST", - }, - - initiateAbdmAuthentication: { - path: "/api/v1/abdm/healthid/auth_init/", - method: "POST", - }, - - confirmWithAadhaarOtp: { - path: "/api/v1/abdm/healthid/confirm_with_aadhaar_otp/", - method: "POST", - }, - - confirmWithMobileOtp: { - path: "/api/v1/abdm/healthid/confirm_with_mobile_otp/", - method: "POST", - }, - - linkViaQR: { - path: "/api/v1/abdm/healthid/link_via_qr/", - method: "POST", - }, - - linkCareContext: { - path: "/api/v1/abdm/healthid/add_care_context/", - method: "POST", - }, - - getAbhaCard: { - path: "/api/v1/abdm/healthid/get_abha_card/", - method: "POST", - }, - - // ABDM Health Facility - - listHealthFacility: { - path: "/api/v1/abdm/health_facility/", - method: "GET", - }, - - createHealthFacility: { - path: "/api/v1/abdm/health_facility/", - method: "POST", - }, - - getHealthFacility: { - path: "/api/v1/abdm/health_facility/{facility_id}/", - method: "GET", - }, - - updateHealthFacility: { - path: "/api/v1/abdm/health_facility/{facility_id}/", - method: "PUT", - }, - - partialUpdateHealthFacility: { - path: "/api/v1/abdm/health_facility/{facility_id}/", - method: "PATCH", - }, - - registerHealthFacilityAsService: { - path: "/api/v1/abdm/health_facility/{facility_id}/register_service/", - method: "POST", + abha: { + // ABDM HealthID endpoints + generateAadhaarOtp: { + path: "/api/v1/abdm/healthid/generate_aadhaar_otp/", + method: "POST", + TRes: Type(), + TBody: Type(), + }, + + resendAadhaarOtp: { + path: "/api/v1/abdm/healthid/resend_aadhaar_otp/", + method: "POST", + TRes: Type(), + TBody: Type(), + }, + + verifyAadhaarOtp: { + path: "/api/v1/abdm/healthid/verify_aadhaar_otp/", + method: "POST", + TRes: Type(), + TBody: Type(), + }, + + generateMobileOtp: { + path: "/api/v1/abdm/healthid/generate_mobile_otp/", + method: "POST", + TRes: Type(), + TBody: Type(), + }, + + checkAndGenerateMobileOtp: { + path: "/api/v1/abdm/healthid/check_and_generate_mobile_otp/", + method: "POST", + TRes: Type(), + TBody: Type(), + }, + + // TODO: resend mobile otp + verifyMobileOtp: { + path: "/api/v1/abdm/healthid/verify_mobile_otp/", + method: "POST", + TRes: Type(), + TBody: Type(), + }, + + createHealthId: { + path: "/api/v1/abdm/healthid/create_health_id/", + method: "POST", + TRes: Type(), + TBody: Type(), + }, + + searchByHealthId: { + path: "/api/v1/abdm/healthid/search_by_health_id/", + method: "POST", + TRes: Type(), + TBody: Type(), + }, + + initiateAbdmAuthentication: { + path: "/api/v1/abdm/healthid/auth_init/", + method: "POST", + TRes: Type(), + TBody: Type(), + }, + + confirmWithAadhaarOtp: { + path: "/api/v1/abdm/healthid/confirm_with_aadhaar_otp/", + method: "POST", + TRes: Type(), + TBody: Type(), + }, + + confirmWithMobileOtp: { + path: "/api/v1/abdm/healthid/confirm_with_mobile_otp/", + method: "POST", + TRes: Type(), + TBody: Type(), + }, + + linkViaQR: { + path: "/api/v1/abdm/healthid/link_via_qr/", + method: "POST", + TRes: Type(), + TBody: Type(), + }, + + linkCareContext: { + path: "/api/v1/abdm/healthid/add_care_context/", + method: "POST", + TRes: Type(), + TBody: Type(), + }, + + getAbhaCard: { + path: "/api/v1/abdm/healthid/get_abha_card/", + method: "POST", + TRes: Type(), + TBody: Type(), + }, + + // ABDM Health Facility + + listHealthFacility: { + path: "/api/v1/abdm/health_facility/", + method: "GET", + }, + + createHealthFacility: { + path: "/api/v1/abdm/health_facility/", + method: "POST", + TRes: Type(), + TBody: Type(), + }, + + getHealthFacility: { + path: "/api/v1/abdm/health_facility/{facility_id}/", + method: "GET", + TRes: Type(), + }, + + updateHealthFacility: { + path: "/api/v1/abdm/health_facility/{facility_id}/", + method: "PUT", + TRes: Type(), + TBody: Type(), + }, + + partialUpdateHealthFacility: { + path: "/api/v1/abdm/health_facility/{facility_id}/", + method: "PATCH", + TRes: Type(), + TBody: Type(), + }, + + registerHealthFacilityAsService: { + path: "/api/v1/abdm/health_facility/{facility_id}/register_service/", + method: "POST", + TRes: Type(), + TBody: Type(), + }, }, // Asset Availability endpoints diff --git a/src/Utils/request/request.ts b/src/Utils/request/request.ts index d428107b64c..7cfb647d4b7 100644 --- a/src/Utils/request/request.ts +++ b/src/Utils/request/request.ts @@ -38,6 +38,7 @@ export default async function request( try { const res = await fetch(url, options); + const data = await getResponseBody(res); result = {