Skip to content

Commit

Permalink
Replaced useDispatch with useQuery/request in Treatment Summary and T…
Browse files Browse the repository at this point in the history
…ransfer Patient. (#7084)

* replace useDispatch with useQuery/request in TreatmentSummary page

* replace useDispatch with useQuery/request in TransferPatientDialog

* remove unused fire request

---------

Co-authored-by: Rithvik Nishad <[email protected]>
  • Loading branch information
sriharsh05 and rithviknishad authored Feb 6, 2024
1 parent db35822 commit 1773a15
Show file tree
Hide file tree
Showing 5 changed files with 302 additions and 362 deletions.
27 changes: 14 additions & 13 deletions src/Components/Facility/TransferPatientDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { FieldLabel } from "../Form/FormFields/FormField";
import { OptionsType } from "../../Common/constants";
import { SelectFormField } from "../Form/FormFields/SelectFormField";
import { navigate } from "raviger";
import { transferPatient } from "../../Redux/actions";
import { useDispatch } from "react-redux";
import { dateQueryString } from "../../Utils/utils.js";
import dayjs from "dayjs";
import request from "../../Utils/request/request.js";
import routes from "../../Redux/api.js";

interface Props {
patientList: Array<DupPatientModel>;
Expand Down Expand Up @@ -60,7 +60,6 @@ const patientFormReducer = (state = initialState, action: any) => {

const TransferPatientDialog = (props: Props) => {
const { patientList, handleOk, handleCancel, facilityId } = props;
const dispatchAction: any = useDispatch();
const [isLoading, setIsLoading] = useState(false);
const [state, dispatch] = useReducer(patientFormReducer, initialState);
const patientOptions: Array<OptionsType> = patientList.map((patient) => {
Expand Down Expand Up @@ -114,15 +113,17 @@ const TransferPatientDialog = (props: Props) => {
const validForm = validateForm();
if (validForm) {
setIsLoading(true);
const data = {
date_of_birth: dateQueryString(state.form.date_of_birth),
facility: facilityId,
};
const res = await dispatchAction(
transferPatient(data, { id: state.form.patient })
);
const { res, data } = await request(routes.transferPatient, {
body: {
facility: facilityId,
date_of_birth: dateQueryString(state.form.date_of_birth),
},
pathParams: {
id: state.form.patient,
},
});
setIsLoading(false);
if (res && res.data && res.status === 200) {
if (res?.ok && data) {
dispatch({ type: "set_form", form: initForm });
handleOk();

Expand All @@ -132,10 +133,10 @@ const TransferPatientDialog = (props: Props) => {
msg: `Patient ${patientName} transferred successfully`,
});
const newFacilityId =
res.data && res.data.facility_object && res.data.facility_object.id;
data && data.facility_object && data.facility_object.id;
if (newFacilityId) {
navigate(
`/facility/${newFacilityId}/patient/${res.data.patient}/consultation`
`/facility/${newFacilityId}/patient/${data.patient}/consultation`
);
} else {
navigate("/facility");
Expand Down
Loading

0 comments on commit 1773a15

Please sign in to comment.