Skip to content

Commit

Permalink
sampleTestCard
Browse files Browse the repository at this point in the history
  • Loading branch information
konavivekramakrishna committed Jan 23, 2024
1 parent 72db334 commit dc3ff5e
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
29 changes: 17 additions & 12 deletions src/Components/Patient/SampleTestCard.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
import { navigate } from "raviger";
import { useState } from "react";
import { SampleTestModel } from "./models";
import { useDispatch } from "react-redux";
import { SAMPLE_TEST_STATUS } from "../../Common/constants";
import { patchSample } from "../../Redux/actions";
import * as Notification from "../../Utils/Notifications";
import UpdateStatusDialog from "./UpdateStatusDialog";
import _ from "lodash-es";
import { formatDateTime } from "../../Utils/utils";
import ButtonV2 from "../Common/components/ButtonV2";
import { NonReadOnlyUsers } from "../../Utils/AuthorizeFor";
import RelativeDateUserMention from "../Common/RelativeDateUserMention";
import request from "../../Utils/request/request";
import routes from "../../Redux/api";

interface SampleDetailsProps {
facilityId: number;
Expand All @@ -21,7 +21,6 @@ interface SampleDetailsProps {

export const SampleTestCard = (props: SampleDetailsProps) => {
const { itemData, handleApproval, facilityId, patientId } = props;
const dispatch: any = useDispatch();

const [statusDialog, setStatusDialog] = useState<{
show: boolean;
Expand All @@ -43,15 +42,21 @@ export const SampleTestCard = (props: SampleDetailsProps) => {
sampleData.date_of_result = new Date().toISOString();
}
const statusName = SAMPLE_TEST_STATUS.find((i) => i.id === status)?.desc;

const res = await dispatch(patchSample(sampleData, { id: sample.id }));
if (res && (res.status === 201 || res.status === 200)) {
window.location.reload();
Notification.Success({
msg: `Success - ${statusName}`,
});
}
dismissUpdateStatus();
await request(routes.patchSample, {
pathParams: {
id: sample.id || 0,
},
body: sampleData,
onResponse: ({ res }) => {
if (res?.ok) {
window.location.reload();
Notification.Success({
msg: `Success - ${statusName}`,
});
}
dismissUpdateStatus();
},
});
};

const showUpdateStatus = (sample: SampleTestModel) => {
Expand Down
2 changes: 1 addition & 1 deletion src/Redux/api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ const routes = {
path: "/api/v1/test_sample/",
},
getTestSample: {
path: "/api/v1/test_sample/{id}",
path: "/api/v1/test_sample/{id}/",
method: "GET",
TRes: Type<SampleTestModel>(),
},
Expand Down

0 comments on commit dc3ff5e

Please sign in to comment.