diff --git a/src/components/accessories/dashboard/admissions/admissionByAgeType/AdmissionByAgeType.tsx b/src/components/accessories/dashboard/admissions/admissionByAgeType/AdmissionByAgeType.tsx index 665bd756c..1f614c09f 100644 --- a/src/components/accessories/dashboard/admissions/admissionByAgeType/AdmissionByAgeType.tsx +++ b/src/components/accessories/dashboard/admissions/admissionByAgeType/AdmissionByAgeType.tsx @@ -1,5 +1,5 @@ import { useAppDispatch } from "libraries/hooks/redux"; -import React, { FC, useEffect, useRef, useState } from "react"; +import React, { FC, useEffect, useRef } from "react"; import { useTranslation } from "react-i18next"; import { useAdmByAgeTypeData } from "../../../../../libraries/dashboardUtils/admissions/useAdmByAgeTypeData"; import { getAdmissions } from "../../../../../state/admissions"; @@ -14,6 +14,7 @@ import { IOwnProps } from "../types"; import { Skeleton } from "@mui/material"; import { getAgeTypes } from "state/types/ageTypes"; import "../../card/styles.scss"; +import { useDisplaySize } from "../../hooks"; export const AdmissionsByAgeType: FC = ({ onRemove, @@ -35,14 +36,7 @@ export const AdmissionsByAgeType: FC = ({ const { total, success, status, ageTypeStatus, data, csvData } = useAdmByAgeTypeData(); - const [displaySize, setDisplaySize] = useState<{ - width: number; - height: number; - }>(); - - const onSizeChange = (width: number, height: number) => { - setDisplaySize({ width: width - 1, height: height - 73 }); - }; + const { displaySize, onSizeChange } = useDisplaySize(); const downloadOptions = ( = ({ actions={actions} sizeChangeHandler={onSizeChange} > - + = ({ actions={actions} sizeChangeHandler={onSizeChange} > - + = ({ onRemove, @@ -35,14 +36,7 @@ export const AdmissionsByTypes: FC = ({ const { total, success, status, admissionTypeStatus, data, csvData } = useAdmByAdmTypeData(); - const [displaySize, setDisplaySize] = useState<{ - width: number; - height: number; - }>(); - - const onSizeChange = (width: number, height: number) => { - setDisplaySize({ width: width - 1, height: height - 73 }); - }; + const { displaySize, onSizeChange } = useDisplaySize(); const downloadOptions = ( = ({ actions={actions} sizeChangeHandler={onSizeChange} > - + = ({ onRemove, @@ -35,14 +36,7 @@ export const AdmissionsByWards: FC = ({ const { total, success, status, wardStatus, data, csvData } = useAdmByAdmWardData(); - const [displaySize, setDisplaySize] = useState<{ - width: number; - height: number; - }>(); - - const onSizeChange = (width: number, height: number) => { - setDisplaySize({ width: width - 1, height: height - 73 }); - }; + const { displaySize, onSizeChange } = useDisplaySize(); const downloadOptions = ( = ({ actions={actions} sizeChangeHandler={onSizeChange} > - + = ({ onRemove, @@ -35,14 +36,7 @@ export const DischargesByAgeTypes: FC = ({ const { total, success, status, ageTypeStatus, data, csvData } = useDisByAgeTypeData(); - const [displaySize, setDisplaySize] = useState<{ - width: number; - height: number; - }>(); - - const onSizeChange = (width: number, height: number) => { - setDisplaySize({ width: width - 1, height: height - 73 }); - }; + const { displaySize, onSizeChange } = useDisplaySize(); const downloadOptions = ( = ({ actions={actions} sizeChangeHandler={onSizeChange} > - + = ({ onRemove, @@ -29,14 +30,7 @@ export const DischargesBySex: FC = ({ const { total, success, status, data, csvData } = useDisBySexData(); - const [displaySize, setDisplaySize] = useState<{ - width: number; - height: number; - }>(); - - const onSizeChange = (width: number, height: number) => { - setDisplaySize({ width: width - 1, height: height - 73 }); - }; + const { displaySize, onSizeChange } = useDisplaySize(); const downloadOptions = ( = ({ actions={actions} sizeChangeHandler={onSizeChange} > - + = ({ onRemove, @@ -35,14 +36,7 @@ export const DischargesByTypes: FC = ({ const { total, success, status, dischargeTypeStatus, data, csvData } = useDisByDisTypeData(); - const [displaySize, setDisplaySize] = useState<{ - width: number; - height: number; - }>(); - - const onSizeChange = (width: number, height: number) => { - setDisplaySize({ width: width - 1, height: height - 73 }); - }; + const { displaySize, onSizeChange } = useDisplaySize(); const downloadOptions = ( = ({ actions={actions} sizeChangeHandler={onSizeChange} > - + = ({ onRemove, @@ -36,14 +37,7 @@ export const DischargesByWards: FC = ({ useDisByWardData(); const cardRef = useRef(null); - const [displaySize, setDisplaySize] = useState<{ - width: number; - height: number; - }>(); - - const onSizeChange = (width: number, height: number) => { - setDisplaySize({ width: width - 1, height: height - 73 }); - }; + const { displaySize, onSizeChange } = useDisplaySize(); const downloadOptions = ( = ({ actions={actions} sizeChangeHandler={onSizeChange} > - + { + const [displaySize, setDisplaySize] = useState<{ + width: number; + height: number; + }>(); + + const onSizeChange = useCallback( + (width: number, height: number) => { + setDisplaySize({ width: width - 1, height: height - 73 }); + }, + [setDisplaySize] + ); + + return { displaySize, onSizeChange }; +}; diff --git a/src/components/accessories/dashboard/opds/opdByAgeTypes/OpdByAgeTypes.tsx b/src/components/accessories/dashboard/opds/opdByAgeTypes/OpdByAgeTypes.tsx index 11fd77e74..f5e1b572d 100644 --- a/src/components/accessories/dashboard/opds/opdByAgeTypes/OpdByAgeTypes.tsx +++ b/src/components/accessories/dashboard/opds/opdByAgeTypes/OpdByAgeTypes.tsx @@ -1,6 +1,6 @@ import { Skeleton } from "@mui/material"; import { useAppDispatch } from "libraries/hooks/redux"; -import React, { FC, useEffect, useRef, useState } from "react"; +import React, { FC, useEffect, useRef } from "react"; import { useTranslation } from "react-i18next"; import { useOpdByAgeTypeData } from "../../../../../libraries/dashboardUtils/opds/useOpdByAgeTypeData"; import { searchOpds } from "../../../../../state/opds"; @@ -14,6 +14,7 @@ import { IOwnProps } from "../types"; import { getAgeTypes } from "state/types/ageTypes"; import "../../card/styles.scss"; +import { useDisplaySize } from "../../hooks"; export const OpdByAgeTypes: FC = ({ onRemove, @@ -32,14 +33,7 @@ export const OpdByAgeTypes: FC = ({ const { status, ageTypeStatus, data, success, total, csvData } = useOpdByAgeTypeData(); - const [displaySize, setDisplaySize] = useState<{ - width: number; - height: number; - }>(); - - const onSizeChange = (width: number, height: number) => { - setDisplaySize({ width: width - 1, height: height - 73 }); - }; + const { displaySize, onSizeChange } = useDisplaySize(); const downloadOptions = ( = ({ actions={actions} sizeChangeHandler={onSizeChange} > - + = ({ onRemove, @@ -29,14 +30,7 @@ export const OpdBySex: FC = ({ const { status, data, success, total, csvData } = useOpdBySexData(); - const [displaySize, setDisplaySize] = useState<{ - width: number; - height: number; - }>(); - - const onSizeChange = (width: number, height: number) => { - setDisplaySize({ width: width - 1, height: height - 73 }); - }; + const { displaySize, onSizeChange } = useDisplaySize(); const downloadOptions = ( = ({ actions={actions} sizeChangeHandler={onSizeChange} > - +