From e7746cf8efa18bba575f4acee18e4855d098963d Mon Sep 17 00:00:00 2001 From: Gigin George Date: Tue, 7 Jan 2025 12:55:51 +0530 Subject: [PATCH 1/8] Update Questionnaire Styling --- .../Questionnaire/QuestionLabel.tsx | 27 +++++ .../QuestionTypes/BooleanQuestion.tsx | 78 ++++++------ .../QuestionTypes/ChoiceQuestion.tsx | 48 +++----- .../QuestionTypes/DateTimeQuestion.tsx | 112 ++++++++---------- .../QuestionTypes/DiagnosisQuestion.tsx | 11 +- .../MedicationRequestQuestion.tsx | 11 +- .../QuestionTypes/NumberQuestion.tsx | 26 ++-- .../QuestionTypes/QuestionGroup.tsx | 2 +- .../QuestionTypes/QuestionInput.tsx | 12 +- .../QuestionTypes/SymptomQuestion.tsx | 11 +- .../QuestionTypes/TextQuestion.tsx | 9 +- 11 files changed, 156 insertions(+), 191 deletions(-) create mode 100644 src/components/Questionnaire/QuestionLabel.tsx diff --git a/src/components/Questionnaire/QuestionLabel.tsx b/src/components/Questionnaire/QuestionLabel.tsx new file mode 100644 index 00000000000..17855845b0f --- /dev/null +++ b/src/components/Questionnaire/QuestionLabel.tsx @@ -0,0 +1,27 @@ +import { Label } from "@/components/ui/label"; + +import type { Question } from "@/types/questionnaire/question"; + +interface QuestionLabelProps { + question: Question; + className?: string; +} + +export function QuestionLabel({ + question, + className = "text-base font-medium block", +}: QuestionLabelProps) { + return ( + + ); +} diff --git a/src/components/Questionnaire/QuestionTypes/BooleanQuestion.tsx b/src/components/Questionnaire/QuestionTypes/BooleanQuestion.tsx index 905a50122da..b2b094790b4 100644 --- a/src/components/Questionnaire/QuestionTypes/BooleanQuestion.tsx +++ b/src/components/Questionnaire/QuestionTypes/BooleanQuestion.tsx @@ -20,48 +20,42 @@ export function BooleanQuestion({ clearError, }: BooleanQuestionProps) { return ( -
- - { - clearError(); - updateQuestionnaireResponseCB({ - ...questionnaireResponse, - values: [ - { - type: "boolean", - value: value === "true", - }, - ], - }); - }} - disabled={disabled} - > -
-
- - -
-
- - -
+ { + clearError(); + updateQuestionnaireResponseCB({ + ...questionnaireResponse, + values: [ + { + type: "boolean", + value: value === "true", + }, + ], + }); + }} + disabled={disabled} + > +
+
+ +
- -
+
+ + +
+
+
); } diff --git a/src/components/Questionnaire/QuestionTypes/ChoiceQuestion.tsx b/src/components/Questionnaire/QuestionTypes/ChoiceQuestion.tsx index 39f3b66697e..4c0f7259bef 100644 --- a/src/components/Questionnaire/QuestionTypes/ChoiceQuestion.tsx +++ b/src/components/Questionnaire/QuestionTypes/ChoiceQuestion.tsx @@ -1,6 +1,5 @@ import { memo } from "react"; -import { Label } from "@/components/ui/label"; import { Select, SelectContent, @@ -30,7 +29,6 @@ export const ChoiceQuestion = memo(function ChoiceQuestion({ questionnaireResponse, updateQuestionnaireResponseCB, disabled = false, - withLabel = true, clearError, index = 0, }: ChoiceQuestionProps) { @@ -52,32 +50,24 @@ export const ChoiceQuestion = memo(function ChoiceQuestion({ }; return ( -
- {withLabel && ( - - )} - -
+ ); }); diff --git a/src/components/Questionnaire/QuestionTypes/DateTimeQuestion.tsx b/src/components/Questionnaire/QuestionTypes/DateTimeQuestion.tsx index b83e593452c..b20629e171c 100644 --- a/src/components/Questionnaire/QuestionTypes/DateTimeQuestion.tsx +++ b/src/components/Questionnaire/QuestionTypes/DateTimeQuestion.tsx @@ -7,7 +7,6 @@ import CareIcon from "@/CAREUI/icons/CareIcon"; import { Button } from "@/components/ui/button"; import { Calendar } from "@/components/ui/calendar"; import { Input } from "@/components/ui/input"; -import { Label } from "@/components/ui/label"; import { Popover, PopoverContent, @@ -15,10 +14,8 @@ import { } from "@/components/ui/popover"; import type { QuestionnaireResponse } from "@/types/questionnaire/form"; -import type { Question } from "@/types/questionnaire/question"; interface DateTimeQuestionProps { - question: Question; questionnaireResponse: QuestionnaireResponse; updateQuestionnaireResponseCB: (response: QuestionnaireResponse) => void; disabled?: boolean; @@ -27,7 +24,6 @@ interface DateTimeQuestionProps { } export function DateTimeQuestion({ - question, questionnaireResponse, updateQuestionnaireResponseCB, disabled, @@ -39,39 +35,39 @@ export function DateTimeQuestion({ : undefined; const handleSelect = (date: Date | undefined) => { - if (!date) { - handleUpdate(undefined); - return; - } + if (!date) return; - // Preserve the time if it exists, otherwise set to current time + clearError(); if (currentValue) { date.setHours(currentValue.getHours()); date.setMinutes(currentValue.getMinutes()); } - handleUpdate(date); - }; - const handleTimeChange = (e: React.ChangeEvent) => { - const timeString = e.target.value; - if (!timeString) return; + updateQuestionnaireResponseCB({ + ...questionnaireResponse, + values: [ + { + type: "dateTime", + value: date.toISOString(), + }, + ], + }); + }; - const [hours, minutes] = timeString.split(":").map(Number); - const newDate = currentValue ? new Date(currentValue) : new Date(); - newDate.setHours(hours); - newDate.setMinutes(minutes); + const handleTimeChange = (event: React.ChangeEvent) => { + const [hours, minutes] = event.target.value.split(":").map(Number); + if (isNaN(hours) || isNaN(minutes)) return; - handleUpdate(newDate); - }; + const date = currentValue || new Date(); + date.setHours(hours); + date.setMinutes(minutes); - const handleUpdate = (date: Date | undefined) => { - clearError(); updateQuestionnaireResponseCB({ ...questionnaireResponse, values: [ { type: "dateTime", - value: date?.toISOString() || "", + value: date.toISOString(), }, ], }); @@ -86,44 +82,38 @@ export function DateTimeQuestion({ }; return ( -
- -
- - - - - - - - - -
+
+ + + + + + + + +
); } diff --git a/src/components/Questionnaire/QuestionTypes/DiagnosisQuestion.tsx b/src/components/Questionnaire/QuestionTypes/DiagnosisQuestion.tsx index c1ad524503b..af85d52b152 100644 --- a/src/components/Questionnaire/QuestionTypes/DiagnosisQuestion.tsx +++ b/src/components/Questionnaire/QuestionTypes/DiagnosisQuestion.tsx @@ -32,10 +32,8 @@ import { } from "@/types/emr/diagnosis/diagnosis"; import { Code } from "@/types/questionnaire/code"; import { QuestionnaireResponse } from "@/types/questionnaire/form"; -import { Question } from "@/types/questionnaire/question"; interface DiagnosisQuestionProps { - question: Question; questionnaireResponse: QuestionnaireResponse; updateQuestionnaireResponseCB: (response: QuestionnaireResponse) => void; disabled?: boolean; @@ -49,7 +47,6 @@ const DIAGNOSIS_INITIAL_VALUE: Partial = { }; export function DiagnosisQuestion({ - question, questionnaireResponse, updateQuestionnaireResponseCB, disabled, @@ -90,11 +87,7 @@ export function DiagnosisQuestion({ }; return ( -
- + <> {diagnoses.length > 0 && (
@@ -123,7 +116,7 @@ export function DiagnosisQuestion({ onSelect={handleAddDiagnosis} disabled={disabled} /> -
+ ); } diff --git a/src/components/Questionnaire/QuestionTypes/MedicationRequestQuestion.tsx b/src/components/Questionnaire/QuestionTypes/MedicationRequestQuestion.tsx index dd9cb4322aa..ab52140001f 100644 --- a/src/components/Questionnaire/QuestionTypes/MedicationRequestQuestion.tsx +++ b/src/components/Questionnaire/QuestionTypes/MedicationRequestQuestion.tsx @@ -25,10 +25,8 @@ import { } from "@/types/emr/medicationRequest"; import { Code } from "@/types/questionnaire/code"; import { QuestionnaireResponse } from "@/types/questionnaire/form"; -import { Question } from "@/types/questionnaire/question"; interface MedicationRequestQuestionProps { - question: Question; questionnaireResponse: QuestionnaireResponse; updateQuestionnaireResponseCB: (response: QuestionnaireResponse) => void; disabled?: boolean; @@ -46,7 +44,6 @@ const MEDICATION_REQUEST_INITIAL_VALUE: MedicationRequest = { }; export function MedicationRequestQuestion({ - question, questionnaireResponse, updateQuestionnaireResponseCB, disabled, @@ -102,11 +99,7 @@ export function MedicationRequestQuestion({ }; return ( -
- + <> {medications.length > 0 && (
    @@ -133,7 +126,7 @@ export function MedicationRequestQuestion({ disabled={disabled} searchPostFix=" clinical drug" /> -
+ ); } diff --git a/src/components/Questionnaire/QuestionTypes/NumberQuestion.tsx b/src/components/Questionnaire/QuestionTypes/NumberQuestion.tsx index 2d1fe05a5a8..354c4745453 100644 --- a/src/components/Questionnaire/QuestionTypes/NumberQuestion.tsx +++ b/src/components/Questionnaire/QuestionTypes/NumberQuestion.tsx @@ -1,7 +1,4 @@ -import { cn } from "@/lib/utils"; - import { Input } from "@/components/ui/input"; -import { Label } from "@/components/ui/label"; import type { QuestionnaireResponse } from "@/types/questionnaire/form"; import type { Question } from "@/types/questionnaire/question"; @@ -11,7 +8,6 @@ interface NumberQuestionProps { questionnaireResponse: QuestionnaireResponse; updateQuestionnaireResponseCB: (response: QuestionnaireResponse) => void; disabled?: boolean; - classes?: string; } export function NumberQuestion({ @@ -19,7 +15,6 @@ export function NumberQuestion({ questionnaireResponse, updateQuestionnaireResponseCB, disabled, - classes, }: NumberQuestionProps) { const handleChange = (value: string) => { const numericValue = @@ -37,19 +32,12 @@ export function NumberQuestion({ }; return ( -
- - handleChange(e.target.value)} - step={question.type === "decimal" ? "0.01" : "1"} - disabled={disabled} - /> -
+ handleChange(e.target.value)} + step={question.type === "decimal" ? "0.01" : "1"} + disabled={disabled} + /> ); } diff --git a/src/components/Questionnaire/QuestionTypes/QuestionGroup.tsx b/src/components/Questionnaire/QuestionTypes/QuestionGroup.tsx index e9f6f2a62e2..8176dbaf294 100644 --- a/src/components/Questionnaire/QuestionTypes/QuestionGroup.tsx +++ b/src/components/Questionnaire/QuestionTypes/QuestionGroup.tsx @@ -118,7 +118,7 @@ export const QuestionGroup = memo(function QuestionGroup({ > {question.text && (
-