From 441a9f1f4ef4c5393547b076dcde91e68664b7e6 Mon Sep 17 00:00:00 2001 From: Rithvik Nishad Date: Wed, 21 Jun 2023 12:12:03 +0530 Subject: [PATCH] Tailwinds `SampleTest.tsx` (#5653) * fixes #4984 * adds more padding below icmr ref * wrap lines for overflowing texts for all ButtonV2 * fixes testing_facility handleSubmit * whitespace-pre-wrap only for submit and cancel. --- src/Components/Common/components/ButtonV2.tsx | 4 +- src/Components/Patient/SampleTest.tsx | 462 ++++++------------ 2 files changed, 145 insertions(+), 321 deletions(-) diff --git a/src/Components/Common/components/ButtonV2.tsx b/src/Components/Common/components/ButtonV2.tsx index a236ec96135..38018144246 100644 --- a/src/Components/Common/components/ButtonV2.tsx +++ b/src/Components/Common/components/ButtonV2.tsx @@ -176,7 +176,7 @@ export const Submit = ({ label = "Submit", ...props }: CommonButtonProps) => { children={ <> - {t(label)} + {t(label)} } {...props} @@ -196,7 +196,7 @@ export const Cancel = ({ label = "Cancel", ...props }: CommonButtonProps) => { children={ <> - {t(label)} + {t(label)} } {...props} diff --git a/src/Components/Patient/SampleTest.tsx b/src/Components/Patient/SampleTest.tsx index 20ffd2388ea..9d3cbea5eaf 100644 --- a/src/Components/Patient/SampleTest.tsx +++ b/src/Components/Patient/SampleTest.tsx @@ -1,33 +1,22 @@ -import { Card, CardContent } from "@material-ui/core"; import { navigate } from "raviger"; import loadable from "@loadable/component"; -import { useReducer, useCallback, useState, useEffect } from "react"; +import { useReducer, useState, useEffect } from "react"; import { useDispatch } from "react-redux"; import { SAMPLE_TYPE_CHOICES, ICMR_CATEGORY } from "../../Common/constants"; -import { - createSampleTest, - getAllFacilities, - getPatient, -} from "../../Redux/actions"; +import { createSampleTest, getPatient } from "../../Redux/actions"; import * as Notification from "../../Utils/Notifications.js"; -import { statusType, useAbortableEffect } from "../../Common/utils"; -import { - LegacyCheckboxField, - LegacySelectField, - LegacyTextInputField, -} from "../Common/HelperInputFields"; -import { SampleTestModel, FacilityNameModel } from "./models"; -import Typography from "@material-ui/core/Typography"; -import Container from "@material-ui/core/Container"; +import { SampleTestModel } from "./models"; import { Cancel, Submit } from "../Common/components/ButtonV2"; import { FieldLabel } from "../Form/FormFields/FormField"; import TextAreaFormField from "../Form/FormFields/TextAreaFormField"; import useAppHistory from "../../Common/hooks/useAppHistory"; +import { SelectFormField } from "../Form/FormFields/SelectFormField"; +import TextFormField from "../Form/FormFields/TextFormField"; +import CheckBoxFormField from "../Form/FormFields/CheckBoxFormField"; +import { FieldChangeEvent } from "../Form/FormFields/Utils"; +import Page from "../Common/components/Page"; +import { FacilitySelect } from "../Common/FacilitySelect"; const Loading = loadable(() => import("../Common/Loading")); -const PageTitle = loadable(() => import("../Common/PageTitle")); - -const icmrCategories = [...ICMR_CATEGORY]; -const sampleTestTypes = [...SAMPLE_TYPE_CHOICES]; const initForm: SampleTestModel = { isFastTrack: false, @@ -77,62 +66,17 @@ const sampleTestFormReducer = (state = initialState, action: any) => { } }; -export const SampleTest = (props: any) => { +export const SampleTest = ({ facilityId, patientId }: any) => { const { goBack } = useAppHistory(); const dispatchAction: any = useDispatch(); - const { facilityId, patientId } = props; const [state, dispatch] = useReducer(sampleTestFormReducer, initialState); const [isLoading, setIsLoading] = useState(false); - const [facilityNames, setFacilityNames] = useState>( - [] - ); const [facilityName, setFacilityName] = useState(""); const [patientName, setPatientName] = useState(""); const headerText = "Request Sample"; const buttonText = "Confirm your request to send sample for testing"; - const fetchFacilityNames = useCallback( - async (status: statusType) => { - const coronaLabType = 950; - const labType = 9; - setIsLoading(true); - const LabList = await dispatchAction( - getAllFacilities({ facility_type: labType }) - ); - - const CoronaLabList = await dispatchAction( - getAllFacilities({ facility_type: coronaLabType }) - ); - - if ( - !status.aborted && - LabList.data.results && - CoronaLabList.data.results - ) { - setFacilityNames([ - ...LabList.data.results, - ...CoronaLabList.data.results, - ]); - dispatch({ - type: "set_form", - form: { - ...state.form, - testing_facility: LabList.data.results[0]?.id, - }, - }); - } - setIsLoading(false); - }, - [dispatchAction] - ); - useAbortableEffect( - (status: statusType) => { - fetchFacilityNames(status); - }, - [dispatch, fetchFacilityNames] - ); - useEffect(() => { async function fetchPatientName() { if (patientId) { @@ -212,7 +156,7 @@ export const SampleTest = (props: any) => { diff_diagnosis: state.form.diff_diagnosis ? state.form.diff_diagnosis : undefined, - testing_facility: state.form.testing_facility, + testing_facility: state.form.testing_facility?.id, doctor_name: state.form.doctor_name ? state.form.doctor_name : undefined, @@ -238,264 +182,144 @@ export const SampleTest = (props: any) => { } }; - const handleChange = (e: any) => { - const form = { ...state.form }; - form[e.target.name] = e.target.value; - dispatch({ type: "set_form", form }); + const handleFormFieldChange = (e: FieldChangeEvent) => { + dispatch({ type: "set_form", form: { ...state.form, [e.name]: e.value } }); }; - const handleTextAreaChange = (e: any) => { - const form = { ...state.form }; - form[e.name] = e.value; - dispatch({ type: "set_form", form }); - }; - - const handleCheckboxFieldChange = (e: any) => { - const form = { ...state.form }; - const { checked, name } = e.target; - form[name] = checked; - dispatch({ type: "set_form", form }); - }; + const field = (name: string, label: string) => ({ + name, + label, + value: state.form[name], + onChange: handleFormFieldChange, + error: state.errors[name], + }); if (isLoading) { return ; } return ( -
- -
- - -
handleSubmit(e)}> -
-
-
- Sample Test Type* - -
- {state.form.sample_type === "OTHER TYPE" && ( -
- -
- )} -
-
-
- ICMR Category (for COVID Test) - -
- - - Reference below to know more about ICMR Categories - - -
  • - Cat 0 - Repeat Sample of Positive Case / Follow Up case -
  • -
  • - Cat 1 - Symptomatic International Traveller in last 14 - days -
  • -
  • Cat 2 - Symptomatic contact of lab confirmed Case
  • -
  • Cat 3 - Symptomatic Healthcare Worker
  • -
  • - Cat 4 - Hospitalized SARI (Severe Acute Respiratory - illness Patient) -
  • -
  • - Cat 5a - Asymptomatic Direct and High Risk contact of - confirmed case - family Member -
  • -
  • - Cat 5b - Asymptomatic Healthcare worker in contact with - confirmed case without adequate protection -
  • -
    -
    -
    -
    -
    - Label - -
    -
    - Testing Facility Name - { - return { id: e.id, name: e.name }; - })} - optionValue="name" - optionKey="id" - onChange={handleChange} - errors={state.errors.testing_facility} - /> -
    -
    - -
    - {state.form.isFastTrack && ( -
    - - Provide reasons for fast-track testing - - -
    - )} -
    -
    -
    -
    - Doctor's Name - -
    -
    - -
    - {state.form.is_atypical_presentation && ( -
    - -
    - )} -
    - -
    -
    - -
    -
    - -
    -
    -
    -
    - -
    -
    - -
    -
    - -
    -
    -
    - goBack()} /> - -
    -
    -
    -
    -
    -
    + +
    + option.text} + optionValue={(option) => option.id} + /> + + {state.form.sample_type === "OTHER TYPE" && ( + + )} + + option} + optionValue={(option) => option} + /> +
    +

    + Refer below to know more about ICMR Categories +

    + +
  • Cat 0 - Repeat Sample of Positive Case / Follow Up case
  • +
  • Cat 1 - Symptomatic International Traveller in last 14 days
  • +
  • Cat 2 - Symptomatic contact of lab confirmed Case
  • +
  • Cat 3 - Symptomatic Healthcare Worker
  • +
  • + Cat 4 - Hospitalized SARI (Severe Acute Respiratory illness + Patient) +
  • +
  • + Cat 5a - Asymptomatic Direct and High Risk contact of confirmed + case - family Member +
  • +
  • + Cat 5b - Asymptomatic Healthcare worker in contact with confirmed + case without adequate protection +
  • +
    +
    + + +
    + Testing Facility + + dispatch({ + type: "set_form", + form: { ...state.form, testing_facility: selected }, + }) + } + facilityType={950} + selected={state.form.testing_facility} + errors={state.errors.testing_facility} + showAll + multiple={false} + /> +
    + + {state.form.isFastTrack && ( + + )} + + + + {state.form.is_atypical_presentation && ( +
    + +
    + )} + + + + + + + +
    + goBack()} /> + +
    + +
    ); };