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

Disable submit button in round type normal if no value selected #6793

Merged
merged 3 commits into from
Dec 13, 2023
Merged
Changes from 2 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
51 changes: 47 additions & 4 deletions src/Components/Patient/DailyRounds.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const initForm: any = {
patient_category: "",
current_health: 0,
actions: null,
action: "",
review_interval: 0,
admitted_to: "",
taken_at: null,
Expand Down Expand Up @@ -108,9 +109,27 @@ export const DailyRounds = (props: any) => {
const [prevReviewInterval, setPreviousReviewInterval] = useState(-1);
const [prevAction, setPreviousAction] = useState("NO_ACTION");
const [hasPreviousLog, setHasPreviousLog] = useState(false);
const [initialData, setInitialData] = useState<any>({
...initForm,
action: "",
});
const headerText = !id ? "Add Consultation Update" : "Info";
const buttonText = !id ? "Save" : "Continue";

const formFields = [
"physical_examination_info",
"other_details",
"additional_symptoms",
"action",
"review_interval",
"bp",
"pulse",
"resp",
"ventilator_spo2",
"rhythm",
"rhythm_detail",
];

useEffect(() => {
(async () => {
if (patientId) {
Expand All @@ -121,10 +140,21 @@ export const DailyRounds = (props: any) => {
setPreviousReviewInterval(
Number(res.data.last_consultation.review_interval)
);
setPreviousAction(
const getAction =
TELEMEDICINE_ACTIONS.find((action) => action.id === res.data.action)
?.text || "NO_ACTION"
);
?.text || "NO_ACTION";
setPreviousAction(getAction);
setInitialData({
...initialData,
action: getAction,
});
dispatch({
type: "set_form",
form: {
...state.form,
action: getAction,
},
});
}
} else {
setPatientName("");
Expand Down Expand Up @@ -156,6 +186,7 @@ export const DailyRounds = (props: any) => {
admitted_to: res.data.admitted_to ? res.data.admitted_to : "Select",
};
dispatch({ type: "set_form", form: data });
setInitialData(data);
}
setIsLoading(false);
}
Expand Down Expand Up @@ -627,7 +658,19 @@ export const DailyRounds = (props: any) => {

<div className="mt-4 flex flex-col-reverse justify-end gap-2 md:flex-row">
<Cancel onClick={() => goBack()} />
<Submit onClick={(e) => handleSubmit(e)} label={buttonText} />
<Submit
disabled={
state.form.clone_last !== null &&
!state.form.clone_last &&
formFields.every(
(field: string) => state.form[field] == initialData[field]
) &&
(state.form.temperature == initialData.temperature ||
isNaN(state.form.temperature))
}
onClick={(e) => handleSubmit(e)}
label={buttonText}
/>
</div>
</form>
</Page>
Expand Down
Loading