From 1eb095d4006d97963069f30ad28171b553fd3b6b Mon Sep 17 00:00:00 2001 From: SilverD3 Date: Mon, 4 Nov 2024 15:55:41 +0100 Subject: [PATCH] chore:code improvement --- .../laboratory/examForm/ExamForm.tsx | 2 +- .../patientExams/ExamForm/ExamForm.tsx | 2 +- .../examRowTable/ExamRowTable.tsx | 24 +++++++++++-------- .../patientExams/examRowTable/types.ts | 2 +- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/components/accessories/laboratory/examForm/ExamForm.tsx b/src/components/accessories/laboratory/examForm/ExamForm.tsx index 95d4f7ba6..c8520c4dc 100644 --- a/src/components/accessories/laboratory/examForm/ExamForm.tsx +++ b/src/components/accessories/laboratory/examForm/ExamForm.tsx @@ -415,7 +415,7 @@ const ExamForm: FC = ({ diff --git a/src/components/accessories/patientExams/ExamForm/ExamForm.tsx b/src/components/accessories/patientExams/ExamForm/ExamForm.tsx index ae93c8991..e2dc0836a 100644 --- a/src/components/accessories/patientExams/ExamForm/ExamForm.tsx +++ b/src/components/accessories/patientExams/ExamForm/ExamForm.tsx @@ -288,7 +288,7 @@ const ExamForm: FC = ({ diff --git a/src/components/accessories/patientExams/examRowTable/ExamRowTable.tsx b/src/components/accessories/patientExams/examRowTable/ExamRowTable.tsx index 44f36e8b2..29c639204 100644 --- a/src/components/accessories/patientExams/examRowTable/ExamRowTable.tsx +++ b/src/components/accessories/patientExams/examRowTable/ExamRowTable.tsx @@ -12,14 +12,14 @@ import TableHead from "@mui/material/TableHead"; import TableRow from "@mui/material/TableRow"; import { useAppSelector } from "libraries/hooks/redux"; import { debounce, isEmpty } from "lodash"; -import React, { FC, useCallback } from "react"; +import React, { ChangeEvent, FC, useCallback } from "react"; import { IState } from "../../../../types"; import "./styles.scss"; import { IEditableTableProps } from "./types"; const ExamRowTable: FC = ({ rows, - onBlur, + onChange, headerData, title, disabled = false, @@ -29,16 +29,22 @@ const ExamRowTable: FC = ({ state.laboratories.getLabWithRowsByCode.data?.laboratoryRowList ); - const handleOnBlur = (value: string, checked: boolean) => { - debounceUpdate(value, checked); - }; - // eslint-disable-next-line react-hooks/exhaustive-deps const debounceUpdate = useCallback( - debounce((value: string, checked: boolean) => onBlur(value, checked), 100), + debounce( + (value: string, checked: boolean) => onChange(value, checked), + 100 + ), [] ); + const handleChange = useCallback( + (value: string) => (_: ChangeEvent, checked: boolean) => { + debounceUpdate(value, checked); + }, + [debounceUpdate] + ); + return ( = ({ { - handleOnBlur(row.label, value); - }} + onChange={handleChange(row.label)} defaultChecked={ !isEmpty( labToEditRows?.filter((e) => e === row.label) ?? [] diff --git a/src/components/accessories/patientExams/examRowTable/types.ts b/src/components/accessories/patientExams/examRowTable/types.ts index 20ee00c83..b89cd2f5c 100644 --- a/src/components/accessories/patientExams/examRowTable/types.ts +++ b/src/components/accessories/patientExams/examRowTable/types.ts @@ -1,6 +1,6 @@ export interface IEditableTableProps { rows: Array<{ label: string; value: string }>; - onBlur: (value: string, checked: boolean) => void; + onChange: (value: string, checked: boolean) => void; fieldValues?: string[]; headerData: Array<{ label: string;