diff --git a/src/Components/Shifting/ShiftDetails.tsx b/src/Components/Shifting/ShiftDetails.tsx index 3832bf87319..776f18b8b71 100644 --- a/src/Components/Shifting/ShiftDetails.tsx +++ b/src/Components/Shifting/ShiftDetails.tsx @@ -5,6 +5,7 @@ import { SHIFTING_CHOICES_PEACETIME, SHIFTING_CHOICES_WARTIME, } from "../../Common/constants"; + import { Link, navigate } from "raviger"; import { useState } from "react"; import ButtonV2 from "../Common/components/ButtonV2"; @@ -506,7 +507,7 @@ export default function ShiftDetails(props: { id: string }) { title={t("shifting_details")} backUrl="/shifting/board" options={ -
+
{ const initForm: any = { shifting_approving_facility_object: null, assigned_facility_object: null, - emergency: "false", - is_kasp: "false", - is_up_shift: "true", - reason: "", - vehicle_preference: "", - comments: "", + emergency: 'false', + is_kasp: 'false', + is_up_shift: 'true', + reason: '', + vehicle_preference: '', + comments: '', assigned_facility_type: null, preferred_vehicle_choice: null, - assigned_to: "", - initial_status: "", - patient_category: "", - ambulance_driver_name: "", - ambulance_phone_number: "", - ambulance_number: "", + assigned_to: '', + initial_status: '', + patient_category: '', + ambulance_driver_name: '', + ambulance_phone_number: '', + ambulance_number: '', }; const initError = Object.assign( {}, - ...Object.keys(initForm).map((k) => ({ [k]: "" })), + ...Object.keys(initForm).map((k) => ({ [k]: '' })), ); const initialState = { @@ -91,13 +91,13 @@ export const ShiftDetailsUpdate = (props: patientShiftProps) => { const shiftFormReducer = (state = initialState, action: any) => { switch (action.type) { - case "set_form": { + case 'set_form': { return { ...state, form: action.form, }; } - case "set_error": { + case 'set_error': { return { ...state, errors: action.errors, @@ -113,21 +113,21 @@ export const ShiftDetailsUpdate = (props: patientShiftProps) => { let requiredFields: any = { assigned_facility_object: { condition: [ - "DESTINATION APPROVED", - "PATIENT TO BE PICKED UP", - "TRANSFER IN PROGRESS", - "COMPLETED", + 'DESTINATION APPROVED', + 'PATIENT TO BE PICKED UP', + 'TRANSFER IN PROGRESS', + 'COMPLETED', ].includes(state.form.status), - errorText: t("please_select_a_facility"), + errorText: t('please_select_a_facility'), }, status: { - errorText: t("please_select_status"), + errorText: t('please_select_status'), }, patient_category: { - errorText: t("please_select_patient_category"), + errorText: t('please_select_patient_category'), }, reason: { - errorText: t("please_enter_a_reason_for_the_shift"), + errorText: t('please_enter_a_reason_for_the_shift'), }, }; @@ -135,16 +135,16 @@ export const ShiftDetailsUpdate = (props: patientShiftProps) => { requiredFields = { ...requiredFields, shifting_approving_facility_object: { - errorText: t("shifting_approving_facility_can_not_be_empty"), + errorText: t('shifting_approving_facility_can_not_be_empty'), }, assigned_facility_type: { - errorText: t("please_select_facility_type"), + errorText: t('please_select_facility_type'), }, preferred_vehicle_choice: { - errorText: t("please_select_preferred_vehicle_type"), + errorText: t('please_select_preferred_vehicle_type'), }, breathlessness_level: { - errorText: t("please_select_breathlessness_level"), + errorText: t('please_select_breathlessness_level'), }, }; } @@ -163,18 +163,18 @@ export const ShiftDetailsUpdate = (props: patientShiftProps) => { Object.keys(requiredFields).forEach((field) => { if ( (!state.form[field] || !/\S+/.test(state.form[field])) && - ("condition" in requiredFields[field] + ('condition' in requiredFields[field] ? requiredFields[field].condition : true) ) { errors[field] = requiredFields[field].errorText; isInvalidForm = true; } else { - errors[field] = ""; + errors[field] = ''; } }); - dispatch({ type: "set_error", errors }); + dispatch({ type: 'set_error', errors }); return !isInvalidForm; }; @@ -183,14 +183,14 @@ export const ShiftDetailsUpdate = (props: patientShiftProps) => { ) => { const user = event.value; const form = { ...state.form }; - form["assigned_to"] = user?.id; + form['assigned_to'] = user?.id; SetAssignedUser(user); - dispatch({ type: "set_form", form }); + dispatch({ type: 'set_form', form }); }; const handleFormFieldChange = (event: FieldChangeEvent) => { dispatch({ - type: "set_form", + type: 'set_form', form: { ...state.form, [event.name]: event.value }, }); }; @@ -199,29 +199,29 @@ export const ShiftDetailsUpdate = (props: patientShiftProps) => { const form = { ...state.form }; const { name, value } = e; form[name] = value; - dispatch({ type: "set_form", form }); + dispatch({ type: 'set_form', form }); }; const setFacility = (selected: any, name: string) => { const form = { ...state.form }; form[name] = selected; - dispatch({ type: "set_form", form }); + dispatch({ type: 'set_form', form }); }; const handleSubmit = async (discharged = false) => { const validForm = validateForm(); if (validForm) { - if (!discharged && state.form.status === "PATIENT EXPIRED") { + if (!discharged && state.form.status === 'PATIENT EXPIRED') { setDischargeReason( - DISCHARGE_REASONS.find((i) => i.text == "Expired")?.id, + DISCHARGE_REASONS.find((i) => i.text == 'Expired')?.id, ); setShowDischargeModal(true); return; } - if (!discharged && state.form.status === "COMPLETED") { + if (!discharged && state.form.status === 'COMPLETED') { setDischargeReason( - DISCHARGE_REASONS.find((i) => i.text == "Referred")?.id, + DISCHARGE_REASONS.find((i) => i.text == 'Referred')?.id, ); setShowDischargeModal(true); return; @@ -237,9 +237,9 @@ export const ShiftDetailsUpdate = (props: patientShiftProps) => { ? state.form?.assigned_facility_object?.name : null, patient: state.form.patient_object?.id, - emergency: [true, "true"].includes(state.form.emergency), - is_kasp: [true, "true"].includes(state.form.is_kasp), - is_up_shift: [true, "true"].includes(state.form.is_up_shift), + emergency: [true, 'true'].includes(state.form.emergency), + is_kasp: [true, 'true'].includes(state.form.is_kasp), + is_up_shift: [true, 'true'].includes(state.form.is_up_shift), reason: state.form.reason, vehicle_preference: state.form.vehicle_preference, comments: state.form.comments, @@ -250,14 +250,14 @@ export const ShiftDetailsUpdate = (props: patientShiftProps) => { patient_category: state.form.patient_category, ambulance_driver_name: state.form.ambulance_driver_name, ambulance_phone_number: - state.form.ambulance_phone_number === "+91" - ? "" + state.form.ambulance_phone_number === '+91' + ? '' : parsePhoneNumber(state.form.ambulance_phone_number), ambulance_number: state.form.ambulance_number, }; if (state.form.status !== state.form.initial_status) { - data["status"] = state.form.status; + data['status'] = state.form.status; } const { res, data: shiftData } = await request(routes.updateShift, { @@ -266,9 +266,9 @@ export const ShiftDetailsUpdate = (props: patientShiftProps) => { }); setIsLoading(false); if (res?.ok && shiftData) { - dispatch({ type: "set_form", form: shiftData }); + dispatch({ type: 'set_form', form: shiftData }); Notification.Success({ - msg: t("shift_request_updated_successfully"), + msg: t('shift_request_updated_successfully'), }); navigate(`/shifting/${props.id}`); @@ -287,18 +287,18 @@ export const ShiftDetailsUpdate = (props: patientShiftProps) => { (d.patient as PatientModel).last_consultation as ConsultationModel, ); if (d.assigned_facility_external) - d["assigned_facility_object"] = { + d['assigned_facility_object'] = { name: String(data.assigned_facility_external), }; - d["initial_status"] = data.status; - d["status"] = qParams.status || data.status; + d['initial_status'] = data.status; + d['status'] = qParams.status || data.status; const patient_category = (d.patient as PatientModel).last_consultation?.last_daily_round ?.patient_category ?? (d.patient as PatientModel).last_consultation?.category; - d["patient_category"] = - PATIENT_CATEGORIES.find((c) => c.text === patient_category)?.id ?? ""; - dispatch({ type: "set_form", form: d }); + d['patient_category'] = + PATIENT_CATEGORIES.find((c) => c.text === patient_category)?.id ?? ''; + dispatch({ type: 'set_form', form: d }); setIsLoading(false); } }, @@ -312,7 +312,7 @@ export const ShiftDetailsUpdate = (props: patientShiftProps) => { } return ( - + setShowDischargeModal(false)} @@ -327,7 +327,7 @@ export const ShiftDetailsUpdate = (props: patientShiftProps) => {
{ // disable all options except `Destination Approved` for non-admin destination facility users home_facility === state.form.assigned_facility_object?.id && USER_TYPES.findIndex((type) => user_type === type) < - USER_TYPES.findIndex((type) => type === "DistrictAdmin") && - !["DESTINATION APPROVED"].includes(option.text) + USER_TYPES.findIndex((type) => type === 'DistrictAdmin') && + !['DESTINATION APPROVED'].includes(option.text) } optionSelectedLabel={(option) => option.text} onChange={handleFormFieldChange} @@ -355,7 +355,7 @@ export const ShiftDetailsUpdate = (props: patientShiftProps) => { ) : ( { {careConfig.wartimeShifting && (
- {t("name_of_shifting_approving_facility")} + {t('name_of_shifting_approving_facility')} { facilityType={1300} selected={state.form.shifting_approving_facility_object} setSelected={(obj) => - setFacility(obj, "shifting_approving_facility_object") + setFacility(obj, 'shifting_approving_facility_object') } errors={state.errors.shifting_approving_facility_object} /> @@ -384,40 +384,40 @@ export const ShiftDetailsUpdate = (props: patientShiftProps) => {
- {t("what_facility_assign_the_patient_to")} + {t('what_facility_assign_the_patient_to')} - setFacility(obj, "assigned_facility_object") + setFacility(obj, 'assigned_facility_object') } errors={state.errors.assigned_facility_object} />
option.label} optionValue={(option) => option.value} @@ -427,10 +427,10 @@ export const ShiftDetailsUpdate = (props: patientShiftProps) => { option.value} optionLabel={(option) => option.label} @@ -439,12 +439,12 @@ export const ShiftDetailsUpdate = (props: patientShiftProps) => { )} option.value} optionLabel={(option) => option.label} @@ -465,7 +465,7 @@ export const ShiftDetailsUpdate = (props: patientShiftProps) => { <> option} @@ -477,7 +477,7 @@ export const ShiftDetailsUpdate = (props: patientShiftProps) => { option} @@ -489,7 +489,7 @@ export const ShiftDetailsUpdate = (props: patientShiftProps) => { option} @@ -504,9 +504,9 @@ export const ShiftDetailsUpdate = (props: patientShiftProps) => { className="md:col-span-2" rows={5} name="reason" - label={t("reason_for_shift")} + label={t('reason_for_shift')} required - placeholder={t("type_your_reason_here") + "*"} + placeholder={t('type_your_reason_here') + '*'} value={state.form.reason} onChange={handleFormFieldChange} error={state.errors.reason} @@ -530,7 +530,7 @@ export const ShiftDetailsUpdate = (props: patientShiftProps) => { handleFormFieldChange(event); }} error={state.errors.ambulance_phone_number} - types={["mobile", "landline"]} + types={['mobile', 'landline']} /> { className="md:col-span-2" rows={5} name="comments" - label={t("any_other_comments")} - placeholder={t("type_any_extra_comments_here")} + label={t('any_other_comments')} + placeholder={t('type_any_extra_comments_here')} value={state.form.comments} onChange={handleFormFieldChange} error={state.errors.comments}