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

Tailwinds Update Status Dialog #5663

Merged
merged 6 commits into from
Jun 28, 2023
Merged
Changes from all commits
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
181 changes: 74 additions & 107 deletions src/Components/Patient/UpdateStatusDialog.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,23 @@
import {
Dialog,
DialogActions,
DialogContent,
DialogTitle,
} from "@material-ui/core";
import React, { useEffect, useState, useReducer } from "react";
import axios from "axios";
import {
SAMPLE_TEST_STATUS,
SAMPLE_TEST_RESULT,
SAMPLE_FLOW_RULES,
} from "../../Common/constants";
import {
LegacyCheckboxField,
LegacySelectField,
} from "../Common/HelperInputFields";
import { SampleTestModel } from "./models";
import * as Notification from "../../Utils/Notifications.js";
import { createUpload } from "../../Redux/actions";
import { useDispatch } from "react-redux";
import { header_content_type, LinearProgressWithLabel } from "./FileUpload";
import { Cancel, Submit } from "../Common/components/ButtonV2";
import { Submit } from "../Common/components/ButtonV2";
import CareIcon from "../../CAREUI/icons/CareIcon";
import ConfirmDialogV2 from "../Common/ConfirmDialogV2";
import { SelectFormField } from "../Form/FormFields/SelectFormField";
import { FieldChangeEvent } from "../Form/FormFields/Utils";
import TextFormField from "../Form/FormFields/TextFormField";
import CheckBoxFormField from "../Form/FormFields/CheckBoxFormField";
import { useTranslation } from "react-i18next";

interface Props {
sample: SampleTestModel;
Expand All @@ -34,14 +30,6 @@ const statusChoices = [...SAMPLE_TEST_STATUS];

const statusFlow = { ...SAMPLE_FLOW_RULES };

const resultTypes = [
{
id: 0,
text: "Select",
},
...SAMPLE_TEST_RESULT,
];

const initForm: any = {
confirm: false,
status: 0,
Expand All @@ -67,6 +55,7 @@ const updateStatusReducer = (state = initialState, action: any) => {
};

const UpdateStatusDialog = (props: Props) => {
const { t } = useTranslation();
const { sample, handleOk, handleCancel } = props;
const [state, dispatch] = useReducer(updateStatusReducer, initialState);
const [file, setfile] = useState<File>();
Expand All @@ -91,14 +80,6 @@ const UpdateStatusDialog = (props: Props) => {
dispatch({ type: "set_form", form });
}, []);

const newStatusChoices = [
{
id: 0,
desc: "Select",
},
...validStatusChoices,
];

const okClicked = () => {
handleOk(sample, state.form.status, state.form.result);
dispatch({ type: "set_form", form: initForm });
Expand All @@ -109,7 +90,7 @@ const UpdateStatusDialog = (props: Props) => {
dispatch({ type: "set_form", form: initForm });
};

const handleChange = (name: string, value: any) => {
const handleChange = ({ name, value }: FieldChangeEvent<unknown>) => {
const form = { ...state.form };
form[name] = name === "status" || name === "result" ? Number(value) : value;
form.disabled =
Expand Down Expand Up @@ -150,12 +131,6 @@ const UpdateStatusDialog = (props: Props) => {
});
};

const handleEscKeyPress = (event: any) => {
if (event.key === "Escape") {
cancelClicked();
}
};

const onFileChange = (e: React.ChangeEvent<HTMLInputElement>): any => {
if (e.target.files == null) {
throw new Error("Error finding e.target.files");
Expand Down Expand Up @@ -188,89 +163,81 @@ const UpdateStatusDialog = (props: Props) => {
};

return (
<Dialog open={true} onKeyDown={(e) => handleEscKeyPress(e)}>
<DialogTitle id="test-sample-title">
Update Sample Test Status
</DialogTitle>
<DialogContent>
<div className="grid gap-4 grid-cols-1 md:grid-cols-3">
<div className="font-semibold leading-relaxed">Current Status :</div>
<div className="md:col-span-2">{currentStatus?.desc}</div>
<div className="font-semibold leading-relaxed">New Status :</div>
<div className="md:col-span-2">
<LegacySelectField
name="status"
variant="standard"
optionValue="desc"
value={state.form.status}
options={newStatusChoices}
onChange={(e: any) => handleChange(e.target.name, e.target.value)}
<ConfirmDialogV2
title="Update Sample Test Status"
show
onClose={cancelClicked}
onConfirm={okClicked}
disabled={state.form.disabled}
action="Update Status"
>
<div className="mt-4 flex flex-col">
<TextFormField
label="Current Status"
name="currentStatus"
value={currentStatus?.desc}
disabled
onChange={handleChange}
/>
<SelectFormField
label="New Status"
name="status"
value={state.form.status}
options={validStatusChoices}
optionLabel={(i) => i.desc}
optionValue={(i) => i.id}
onChange={handleChange}
/>
{Number(state.form.status) === 7 && (
<>
<SelectFormField
label="Result"
name="result"
value={state.form.result}
options={SAMPLE_TEST_RESULT}
optionLabel={(i) => i.text}
optionValue={(i) => i.id}
onChange={handleChange}
/>
</div>
{Number(state.form.status) === 7 && (
<>
<div className="font-semibold leading-relaxed text-right">
Result :
</div>
<div className="md:col-span-2">
<LegacySelectField
name="result"
variant="standard"
value={state.form.result}
options={resultTypes}
onChange={(e: any) =>
handleChange(e.target.name, e.target.value)
}
/>
</div>
</>
)}
{Number(state.form.status) === 7 && (
<>
<div className="font-semibold leading-relaxed text-right">
Upload Report :
</div>
<div className="md:col-span-2">
<input title="reportFile" onChange={onFileChange} type="file" />
</div>
<div className="col-start-2 col-span-2">
{uploadStarted && (
<LinearProgressWithLabel value={uploadPercent} />
)}
</div>
<div className="flex justify-end col-start-2 col-span-2">
<span className="font-semibold leading-relaxed">
Upload Report :
</span>
{uploadStarted ? (
<LinearProgressWithLabel value={uploadPercent} />
) : (
<div className="flex flex-wrap justify-between gap-2 mt-3 mb-4">
<label className="max-w-full font-medium h-min inline-flex whitespace-pre items-center gap-2 transition-all duration-200 ease-in-out cursor-pointer disabled:cursor-not-allowed disabled:bg-gray-200 disabled:text-gray-500 outline-offset-1 button-size-default justify-center button-shape-square button-primary-default">
<CareIcon className="care-l-file-upload-alt text-lg" />
<span className="truncate max-w-full">
{file ? file.name : t("choose_file")}
</span>
<input
title="changeFile"
onChange={onFileChange}
type="file"
hidden
/>
</label>
<Submit
type="submit"
onClick={handleUpload}
disabled={uploadDone}
>
<CareIcon className="care-l-cloud-upload text-2xl font-bold" />
<CareIcon className="care-l-cloud-upload text-lg" />
<span>Upload</span>
</Submit>
</div>
</>
)}
<div className="md:col-span-3">
<LegacyCheckboxField
checked={state.form.confirm}
onChange={(e: any) =>
handleChange(e.target.name, e.target.checked)
}
name="confirm"
label="I agree to update the sample test status."
/>
</div>
</div>
</DialogContent>
<DialogActions style={{ justifyContent: "space-between" }}>
<Cancel onClick={cancelClicked} />
<Submit
onClick={okClicked}
disabled={state.form.disabled}
label="Update Status"
)}
</>
)}
<CheckBoxFormField
label="I agree to update the sample test status."
name="confirm"
value={state.form.confirm}
onChange={handleChange}
/>
</DialogActions>
</Dialog>
</div>
</ConfirmDialogV2>
);
};

Expand Down