Skip to content

Commit

Permalink
use request in patientprivacy
Browse files Browse the repository at this point in the history
  • Loading branch information
Pranshu1902 committed Mar 7, 2024
1 parent 5300669 commit c5a09b2
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions src/Components/Patient/PatientPrivacyToggle.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
import * as Notification from "../../Utils/Notifications.js";
import CareIcon from "../../CAREUI/icons/CareIcon.js";
import { ConsultationModel } from "../Facility/models.js";
import { useDispatch } from "react-redux";
import { useEffect, useState } from "react";
import { UserRole } from "../../Common/constants.js";
import { getConsultationBed } from "../../Redux/actions.js";
import useAuthUser from "../../Common/hooks/useAuthUser.js";
import request from "../../Utils/request/request.js";
import routes from "../../Redux/api.js";
Expand All @@ -17,7 +15,6 @@ export default function PatientPrivacyToggle(props: PatientPrivacyToggleProps) {
const { consultationId, consultation, fetchPatientData } = props;
const [privacy, setPrivacy] = useState<boolean>(false);
const user = useAuthUser();
const dispatch: any = useDispatch();

//condititonally render the privacy toggle button depending on user role
const allowPrivacyToggle = () => {
Expand Down Expand Up @@ -47,22 +44,20 @@ export default function PatientPrivacyToggle(props: PatientPrivacyToggleProps) {
return;
}
const bedId = consultation?.current_bed?.bed_object?.id;
const consultationBedID = consultation?.current_bed?.id;
const consultationBedID = consultation?.current_bed?.id ?? "";
try {
const res = await dispatch(
getConsultationBed(
consultationId,
bedId as string,
consultationBedID as string
)
);
const { res, data } = await request(routes.getConsultationBed, {
body: { consultation: consultationId, bed: bedId },
pathParams: { external_id: consultationBedID },
});

if (
res &&
res.status === 200 &&
res?.data &&
(res.data?.privacy == true || res.data?.privacy == false)
data &&
(data?.privacy == true || data?.privacy == false)
) {
setPrivacy(res.data.privacy);
setPrivacy(data.privacy);
} else {
Notification.Error({
msg: "Failed to fetch privacy",
Expand Down

0 comments on commit c5a09b2

Please sign in to comment.