Skip to content

Commit

Permalink
Consultation Form: Minor fixes for action field (#5340)
Browse files Browse the repository at this point in the history
* fixes #5335

* minor fix

* fix action not loaded when editing consultation

* fix minor issue

* minor hack to fix merge form state

* fix issue with dropdown

* skip prefill from patient if not update

---------

Co-authored-by: Mohammed Nihal <[email protected]>
  • Loading branch information
rithviknishad and nihal467 authored Apr 14, 2023
1 parent da0e2a6 commit f5d8cf9
Showing 1 changed file with 24 additions and 5 deletions.
29 changes: 24 additions & 5 deletions src/Components/Facility/ConsultationForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ type FormDetails = {
prn_prescription: PRNPrescriptionType[];
investigation: InvestigationType[];
is_telemedicine: BooleanStrings;
action: string;
action?: string;
assigned_to: string;
assigned_to_object: UserModel | null;
special_instruction: string;
Expand All @@ -114,7 +114,8 @@ type FormDetails = {

type Action =
| { type: "set_form"; form: FormDetails }
| { type: "set_error"; errors: FormDetails };
| { type: "set_error"; errors: FormDetails }
| { type: "set_form_field"; field: keyof FormDetails; value: any };

const initForm: FormDetails = {
symptoms: [],
Expand Down Expand Up @@ -147,7 +148,7 @@ const initForm: FormDetails = {
prn_prescription: [],
investigation: [],
is_telemedicine: "false",
action: "PENDING",
action: undefined,
assigned_to: "",
assigned_to_object: null,
special_instruction: "",
Expand Down Expand Up @@ -189,7 +190,7 @@ const consultationFormReducer = (state = initialState, action: Action) => {
case "set_form": {
return {
...state,
form: action.form,
form: { ...state.form, ...action.form },
};
}
case "set_error": {
Expand All @@ -198,6 +199,15 @@ const consultationFormReducer = (state = initialState, action: Action) => {
errors: action.errors,
};
}
case "set_form_field": {
return {
...state,
form: {
...state.form,
[action.field]: action.value,
},
};
}
}
};

Expand Down Expand Up @@ -270,6 +280,14 @@ export const ConsultationForm = (props: any) => {
if (res.data) {
setPatientName(res.data.name);
setFacilityName(res.data.facility_object.name);
if (isUpdate) {
dispatch({
type: "set_form_field",
field: "action",
value: TELEMEDICINE_ACTIONS.find((a) => a.id === res.data.action)
?.text,
});
}
}
} else {
setPatientName("");
Expand Down Expand Up @@ -1266,13 +1284,14 @@ export const ConsultationForm = (props: any) => {
{...selectField("review_interval")}
label="Review After"
options={REVIEW_AT_CHOICES}
position="above"
/>
</div>
<div className="flex-1" ref={fieldRef["action"]}>
<SelectFormField
{...field("action")}
label="Action"
required
position="above"
options={TELEMEDICINE_ACTIONS}
optionLabel={(option) => option.desc}
optionValue={(option) => option.text}
Expand Down

0 comments on commit f5d8cf9

Please sign in to comment.