diff --git a/src/components/accessories/laboratory/ChangeLabStatus.tsx b/src/components/accessories/laboratory/ChangeLabStatus.tsx index d08971245..9f646852d 100644 --- a/src/components/accessories/laboratory/ChangeLabStatus.tsx +++ b/src/components/accessories/laboratory/ChangeLabStatus.tsx @@ -1,91 +1,91 @@ -import { useState } from "react"; -import { ChangeLabStatusProps } from "./types"; -import { - AppBar, - Button, - Dialog, - DialogActions, - DialogContent, - IconButton, - Toolbar, - Typography, -} from "@material-ui/core"; -import React from "react"; -import { GridCloseIcon } from "@material-ui/data-grid"; -import { useTranslation } from "react-i18next"; -import { Check, Close } from "@material-ui/icons"; - -export const ChangeLabStatus: React.FC = ({ - status, - labCode, - onClick, - onClose, - isOpen = false, -}) => { - const [open, setOpen] = useState(isOpen); - - const { t } = useTranslation(); - const handleClose = () => { - if (onClose) { - onClose(); - } - setOpen(false); - }; - - const handleClick = () => { - onClick(); - handleClose(); - }; - - return ( - - - - - {t("lab.changestatus")} - - { - handleClose(); - }} - aria-label="close" - > - - - - - -
-

- {t("lab.changelabstatusto", { - code: labCode, - status: t("lab.statuses." + status), - })} - . {t("common.continue")} -

-
-
- - - - -
- ); -}; +import { useState } from "react"; +import { ChangeLabStatusProps } from "./types"; +import { + AppBar, + Button, + Dialog, + DialogActions, + DialogContent, + IconButton, + Toolbar, + Typography, +} from "@material-ui/core"; +import React from "react"; +import { GridCloseIcon } from "@material-ui/data-grid"; +import { useTranslation } from "react-i18next"; +import { Check, Close } from "@material-ui/icons"; + +export const ChangeLabStatus: React.FC = ({ + status, + labCode, + onClick, + onClose, + isOpen = false, +}) => { + const [open, setOpen] = useState(isOpen); + + const { t } = useTranslation(); + const handleClose = () => { + if (onClose) { + onClose(); + } + setOpen(false); + }; + + const handleClick = () => { + onClick(); + handleClose(); + }; + + return ( + + + + + {t("lab.changestatus")} + + { + handleClose(); + }} + aria-label="close" + > + + + + + +
+

+ {t("lab.changelabstatusto", { + code: labCode, + status: t("lab.statuses." + status.toLowerCase()), + })} + . {t("common.continue")} +

+
+
+ + + + +
+ ); +}; diff --git a/src/components/accessories/laboratory/EditLaboratoryContent.tsx b/src/components/accessories/laboratory/EditLaboratoryContent.tsx index 7f2494961..f899a17a1 100644 --- a/src/components/accessories/laboratory/EditLaboratoryContent.tsx +++ b/src/components/accessories/laboratory/EditLaboratoryContent.tsx @@ -10,8 +10,10 @@ import "./styles.scss"; import { useEffect } from "react"; import { updateLabFields } from "../../../libraries/formDataHandling/functions"; import { + createLabReset, getLabWithRowsByCode, getLabWithRowsByCodeReset, + updateLabReset, } from "../../../state/laboratories/actions"; import { getExams } from "../../../state/exams/actions"; import ExamForm from "./examForm/ExamForm"; @@ -36,18 +38,18 @@ export const EditLaboratoryContent: FC = () => { if (id) { dispatch(getLabWithRowsByCode(parseInt(id))); } - }, [id]); + }, [id, dispatch]); useEffect(() => { if (labToEdit?.patientCode) { dispatch(getPatientThunk(labToEdit.patientCode.toString())); } - }, [labWithRows]); + }, [labWithRows, dispatch, labToEdit?.patientCode]); const handleReset = useCallback(() => { dispatch(getLabWithRowsByCodeReset()); navigate(0); - }, [dispatch]); + }, [dispatch, navigate]); const patient = useSelector( (state: IState) => state.patients.selectedPatient.data @@ -68,7 +70,16 @@ export const EditLaboratoryContent: FC = () => { useEffect(() => { dispatch(getExams()); - }, []); + }, [dispatch]); + + const handleBack = useCallback(() => { + if (creationMode) { + dispatch(createLabReset()); + } else { + dispatch(updateLabReset()); + } + navigate(-1); + }, [navigate, dispatch, creationMode]); return ( <> @@ -76,9 +87,7 @@ export const EditLaboratoryContent: FC = () => {
{t("nav.laboratory")}