From 595de993c1a3266dd18f66982ca1799f396a49c6 Mon Sep 17 00:00:00 2001 From: vivek Date: Tue, 23 Jan 2024 00:57:20 +0530 Subject: [PATCH] replace useDispatch in dailyroundslistdetials --- .../Patient/DailyRoundListDetails.tsx | 78 +++++++------------ src/Redux/api.tsx | 2 + 2 files changed, 30 insertions(+), 50 deletions(-) diff --git a/src/Components/Patient/DailyRoundListDetails.tsx b/src/Components/Patient/DailyRoundListDetails.tsx index 8f313c0a51d..02ad9aa47fa 100644 --- a/src/Components/Patient/DailyRoundListDetails.tsx +++ b/src/Components/Patient/DailyRoundListDetails.tsx @@ -1,75 +1,53 @@ -import { lazy, useCallback, useState } from "react"; -import { useDispatch } from "react-redux"; +import { lazy, useState } from "react"; import { CONSCIOUSNESS_LEVEL, CURRENT_HEALTH_CHANGE, SYMPTOM_CHOICES, } from "../../Common/constants"; -import { statusType, useAbortableEffect } from "../../Common/utils"; -import { getConsultationDailyRoundsDetails } from "../../Redux/actions"; import { DailyRoundsModel } from "./models"; import Page from "../Common/components/Page"; import ButtonV2 from "../Common/components/ButtonV2"; import { formatDateTime } from "../../Utils/utils"; +import useQuery from "../../Utils/request/useQuery"; +import routes from "../../Redux/api"; const Loading = lazy(() => import("../Common/Loading")); const symptomChoices = [...SYMPTOM_CHOICES]; const currentHealthChoices = [...CURRENT_HEALTH_CHANGE]; export const DailyRoundListDetails = (props: any) => { const { facilityId, patientId, consultationId, id } = props; - const dispatch: any = useDispatch(); const [dailyRoundListDetailsData, setDailyRoundListDetails] = useState({}); - const [isLoading, setIsLoading] = useState(false); - const fetchpatient = useCallback( - async (status: statusType) => { - setIsLoading(true); - const res = await dispatch( - getConsultationDailyRoundsDetails({ consultationId, id }) - ); - if (!status.aborted) { - if (res && res.data) { - const currentHealth = currentHealthChoices.find( - (i) => i.text === res.data.current_health - ); + const { loading: isLoading } = useQuery(routes.getDailyReport, { + pathParams: { consultationId, id }, + onResponse: ({ res, data }) => { + if (res && data) { + const currentHealth = currentHealthChoices.find( + (i) => i.text === data.current_health + ); - const data: DailyRoundsModel = { - ...res.data, - temperature: Number(res.data.temperature) - ? res.data.temperature - : "", - additional_symptoms_text: "", - medication_given: - Object.keys(res.data.medication_given).length === 0 - ? [] - : res.data.medication_given, - current_health: currentHealth - ? currentHealth.desc - : res.data.current_health, - }; - if (res.data.additional_symptoms?.length) { - const symptoms = res.data.additional_symptoms.map( - (symptom: number) => { - const option = symptomChoices.find((i) => i.id === symptom); - return option ? option.text.toLowerCase() : symptom; - } - ); - data.additional_symptoms_text = symptoms.join(", "); - } - setDailyRoundListDetails(data); + const tdata: DailyRoundsModel = { + ...data, + temperature: Number(data.temperature) ? data.temperature : "", + additional_symptoms_text: "", + medication_given: data.medication_given ?? [], + + current_health: currentHealth + ? currentHealth.desc + : data.current_health, + }; + if (data.additional_symptoms?.length) { + const symptoms = data.additional_symptoms.map((symptom: number) => { + const option = symptomChoices.find((i) => i.id === symptom); + return option ? option.text.toLowerCase() : symptom; + }); + tdata.additional_symptoms_text = symptoms.join(", "); } - setIsLoading(false); + setDailyRoundListDetails(tdata); } }, - [consultationId, dispatch, id] - ); - useAbortableEffect( - (status: statusType) => { - fetchpatient(status); - }, - [dispatch, fetchpatient] - ); + }); if (isLoading) { return ; diff --git a/src/Redux/api.tsx b/src/Redux/api.tsx index 7402c93e582..feacfd5a19f 100644 --- a/src/Redux/api.tsx +++ b/src/Redux/api.tsx @@ -531,6 +531,8 @@ const routes = { getDailyReport: { path: "/api/v1/consultation/{consultationId}/daily_rounds/{id}/", + method: "GET", + TRes: Type(), }, dailyRoundsAnalyse: { path: "/api/v1/consultation/{consultationId}/daily_rounds/analyse/",