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

Replaced useDispatch with useQuerry on DailyRoundListDetails #6696

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
26 changes: 16 additions & 10 deletions src/Components/Patient/DailyRoundListDetails.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { lazy, useCallback, useState } from "react";
import { useDispatch } from "react-redux";
import routes from "../../Redux/api";
import useQuery from "../../Utils/request/useQuery";
import { 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";
Expand All @@ -11,23 +11,29 @@ const Loading = lazy(() => import("../Common/Loading"));
const symptomChoices = [...SYMPTOM_CHOICES];
const currentHealthChoices = [...CURRENT_HEALTH_CHANGE];

function useConsultationQuery(consultationId: any, id: any) {
rithviknishad marked this conversation as resolved.
Show resolved Hide resolved
return useQuery(routes.getDailyReport, {
pathParams: {
consultationId,
id,
},
});
}
rithviknishad marked this conversation as resolved.
Show resolved Hide resolved

export const DailyRoundListDetails = (props: any) => {
const { facilityId, patientId, consultationId, id } = props;
const dispatch: any = useDispatch();
const [dailyRoundListDetailsData, setDailyRoundListDetails] =
useState<DailyRoundsModel>({});
const [isLoading, setIsLoading] = useState(false);
rithviknishad marked this conversation as resolved.
Show resolved Hide resolved

const res = useConsultationQuery(consultationId, id);
const fetchpatient = useCallback(
async (status: statusType) => {
setIsLoading(true);
rithviknishad marked this conversation as resolved.
Show resolved Hide resolved
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
(i) => i.text === res.data?.current_health
);

const data: DailyRoundsModel = {
Expand All @@ -37,7 +43,7 @@ export const DailyRoundListDetails = (props: any) => {
: "",
additional_symptoms_text: "",
medication_given:
Object.keys(res.data.medication_given).length === 0
Object.keys(res.data.medication_given ?? {}).length === 0
? []
: res.data.medication_given,
current_health: currentHealth
Expand All @@ -58,13 +64,13 @@ export const DailyRoundListDetails = (props: any) => {
setIsLoading(false);
}
},
[consultationId, dispatch, id]
[consultationId, id]
);
useAbortableEffect(
(status: statusType) => {
fetchpatient(status);
},
[dispatch, fetchpatient]
[fetchpatient]
rithviknishad marked this conversation as resolved.
Show resolved Hide resolved
);

if (isLoading) {
Expand Down
4 changes: 3 additions & 1 deletion src/Redux/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ import { Prescription } from "../Components/Medicine/models";

import { UserModel } from "../Components/Users/models";
import { PaginatedResponse } from "../Utils/request/types";
import { PatientModel } from "../Components/Patient/models";
import { PatientModel, DailyRoundsModel } from "../Components/Patient/models";
import { IComment, IResource } from "../Components/Resource/models";

/**
Expand Down Expand Up @@ -441,6 +441,8 @@ const routes = {

getDailyReport: {
path: "/api/v1/consultation/{consultationId}/daily_rounds/{id}/",
method: "GET",
TRes: Type<DailyRoundsModel>(),
},
dailyRoundsAnalyse: {
path: "/api/v1/consultation/{consultationId}/daily_rounds/analyse/",
Expand Down