Skip to content

Commit

Permalink
usequery failure trigger message update
Browse files Browse the repository at this point in the history
  • Loading branch information
AdityaJ2305 committed Dec 24, 2024
1 parent cbbcb55 commit 7cd082d
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions src/components/Facility/DischargeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,25 +97,28 @@ const DischargeModal = ({
const { goBack } = useAppHistory();

const {
isLoading: consultationLoading,
isLoading: consultationDataLoading,
data: consultationDataFetched,
isError: errorOnConsultationData,
error: errorOnConsultationData,
failureReason: failureReasonOnConsultationData,
} = useQuery({
queryKey: [routes.getConsultation.path, consultationData.id],
queryFn: () =>
query(routes.getConsultation, {
pathParams: { id: consultationData.id },
}),
queryFn: query(routes.getConsultation, {
pathParams: { id: consultationData.id },
}),
enabled: consultationData.id !== undefined,
});

if (!errorOnConsultationData) {
console.log(consultationDataFetched);
if (errorOnConsultationData || failureReasonOnConsultationData) {
Notification.Error({ msg: "Error on fetching consultation data" });
goBack();
}

if (errorOnConsultationData) {
Notification.Error({ msg: "Error loading consultation data" });
goBack();
if (consultationDataLoading) {
return <Loading />;
}
if (consultationDataFetched == undefined) {
return;
}

const discharge_reason =
Expand Down Expand Up @@ -198,8 +201,9 @@ const DischargeModal = ({
? "death_datetime"
: "discharge_date"
];
if (consultationLoading) {
return <Loading />;

if (consultationDataFetched.diagnoses === undefined) {
return;
}

return (
Expand Down Expand Up @@ -330,7 +334,7 @@ const DischargeModal = ({
<FieldLabel>{t("diagnosis_at_discharge")}</FieldLabel>
<EditDiagnosesBuilder
consultationId={consultationData.id}
value={[]}
value={consultationDataFetched.diagnoses}
/>
</div>
)}
Expand Down

0 comments on commit 7cd082d

Please sign in to comment.