From a986afe6a8cb828cc9e95f4538bd6cbb18415716 Mon Sep 17 00:00:00 2001 From: Rio Knightley <128376976+RioKnightleyNHS@users.noreply.github.com> Date: Fri, 13 Oct 2023 16:31:56 +0100 Subject: [PATCH] PRMDR 294 (Partial) Upload component seperation (#89) --- .../blocks/lgRecordStage/LgRecordStage.tsx | 189 ++++++++++++++++++ .../LloydGeorgeRecordPage.tsx | 188 ++--------------- 2 files changed, 208 insertions(+), 169 deletions(-) create mode 100644 app/src/components/blocks/lgRecordStage/LgRecordStage.tsx diff --git a/app/src/components/blocks/lgRecordStage/LgRecordStage.tsx b/app/src/components/blocks/lgRecordStage/LgRecordStage.tsx new file mode 100644 index 000000000..dc953fc43 --- /dev/null +++ b/app/src/components/blocks/lgRecordStage/LgRecordStage.tsx @@ -0,0 +1,189 @@ +import React, { useRef, useState } from 'react'; +import { PatientDetails } from '../../../types/generic/patientDetails'; +import { BackLink, Card, Details } from 'nhsuk-react-components'; +import { getFormattedDate } from '../../../helpers/utils/formatDate'; +import { DOWNLOAD_STAGE } from '../../../types/generic/downloadStage'; +import PdfViewer from '../../generic/pdfViewer/PdfViewer'; +import formatFileSize from '../../../helpers/utils/formatFileSize'; +import { PdfActionLink } from '../../../pages/lloydGeorgeRecordPage/LloydGeorgeRecordPage'; +import { ReactComponent as Chevron } from '../../../styles/down-chevron.svg'; +import { useOnClickOutside } from 'usehooks-ts'; +import { Link } from 'react-router-dom'; + +type Props = { + patientDetails: PatientDetails; + downloadStage: DOWNLOAD_STAGE; + lloydGeorgeUrl: string; + lastUpdated: string; + numberOfFiles: number; + totalFileSizeInByte: number; + actionLinks: Array; +}; + +function LgRecordStage({ + patientDetails, + downloadStage, + lloydGeorgeUrl, + lastUpdated, + numberOfFiles, + totalFileSizeInByte, + actionLinks, +}: Props) { + const [fullScreen, setFullScreen] = useState(false); + const handleMoreActions = () => { + setShowActionsMenu(!showActionsMenu); + }; + + const [showActionsMenu, setShowActionsMenu] = useState(false); + const dob: String = patientDetails?.birthDate + ? getFormattedDate(new Date(patientDetails.birthDate)) + : ''; + + const nhsNumber: String = + patientDetails?.nhsNumber.slice(0, 3) + + ' ' + + patientDetails?.nhsNumber.slice(3, 6) + + ' ' + + patientDetails?.nhsNumber.slice(6, 10); + const actionsRef = useRef(null); + useOnClickOutside(actionsRef, (e) => { + setShowActionsMenu(false); + }); + + const PdfCardDetails = () => ( + <> +
+
Last updated: {lastUpdated}
+
+ {numberOfFiles} files | File size: {formatFileSize(totalFileSizeInByte)} | File + format: PDF +
+
+
+
+
+ Select an action... + +
+ {showActionsMenu && ( +
+ + +
    + {actionLinks.map((link, i) => ( +
  1. + { + e.preventDefault(); + link.handler(); + }} + > + {link.label} + +
  2. + ))} +
+
+
+
+ )} +
+ + ); + + const PdfCardDescription = () => { + if (downloadStage === DOWNLOAD_STAGE.SUCCEEDED) { + return ; + } else if (downloadStage === DOWNLOAD_STAGE.FAILED) { + return No documents are available; + } else { + return Loading...; + } + }; + + return ( + <> + {fullScreen && ( + { + setFullScreen(false); + }} + > + Go back + + )} +
+

+ {`${patientDetails?.givenName} ${patientDetails?.familyName}`} +

+

+ NHS number: {nhsNumber} +

+

+ Date of birth: {dob} +

+
+ {!fullScreen ? ( + <> + + + + Lloyd George record + + + + + {downloadStage === DOWNLOAD_STAGE.SUCCEEDED && ( + <> +
+ + View record + + + +
+ + )} + + ) : ( + + )} + + ); +} + +export default LgRecordStage; diff --git a/app/src/pages/lloydGeorgeRecordPage/LloydGeorgeRecordPage.tsx b/app/src/pages/lloydGeorgeRecordPage/LloydGeorgeRecordPage.tsx index d40f0e568..12a465f67 100644 --- a/app/src/pages/lloydGeorgeRecordPage/LloydGeorgeRecordPage.tsx +++ b/app/src/pages/lloydGeorgeRecordPage/LloydGeorgeRecordPage.tsx @@ -1,24 +1,21 @@ import React, { useEffect, useRef, useState } from 'react'; import { usePatientDetailsContext } from '../../providers/patientProvider/PatientProvider'; -import { getFormattedDate } from '../../helpers/utils/formatDate'; import { useNavigate } from 'react-router'; -import { BackLink, Card, Details } from 'nhsuk-react-components'; import { useBaseAPIUrl } from '../../providers/configProvider/ConfigProvider'; -import PdfViewer from '../../components/generic/pdfViewer/PdfViewer'; import { DOWNLOAD_STAGE } from '../../types/generic/downloadStage'; -import formatFileSize from '../../helpers/utils/formatFileSize'; import useBaseAPIHeaders from '../../helpers/hooks/useBaseAPIHeaders'; -import { useOnClickOutside } from 'usehooks-ts'; -import { ReactComponent as Chevron } from '../../styles/down-chevron.svg'; -import { Link } from 'react-router-dom'; import { getFormattedDatetime } from '../../helpers/utils/formatDatetime'; import getLloydGeorgeRecord from '../../helpers/requests/getLloydGeorgeRecord'; +import LgRecordStage from '../../components/blocks/lgRecordStage/LgRecordStage'; enum LG_RECORD_STAGE { RECORD = 0, DOWNLOAD_ALL = 1, } - +export type PdfActionLink = { + label: string; + handler: () => void; +}; function LloydGeorgeRecordPage() { const [patientDetails] = usePatientDetailsContext(); const [downloadStage, setDownloadStage] = useState(DOWNLOAD_STAGE.INITIAL); @@ -26,44 +23,12 @@ function LloydGeorgeRecordPage() { const [totalFileSizeInByte, setTotalFileSizeInByte] = useState(0); const [lastUpdated, setLastUpdated] = useState(''); const [lloydGeorgeUrl, setLloydGeorgeUrl] = useState(''); - const [fullScreen, setFullScreen] = useState(false); const navigate = useNavigate(); const baseUrl = useBaseAPIUrl(); const baseHeaders = useBaseAPIHeaders(); const mounted = useRef(false); - const actionsRef = useRef(null); - const [showActionsMenu, setShowActionsMenu] = useState(false); const [stage, setStage] = useState(LG_RECORD_STAGE.RECORD); - useOnClickOutside(actionsRef, (e) => { - setShowActionsMenu(false); - }); - - const dob: String = patientDetails?.birthDate - ? getFormattedDate(new Date(patientDetails.birthDate)) - : ''; - - const nhsNumber: String = - patientDetails?.nhsNumber.slice(0, 3) + - ' ' + - patientDetails?.nhsNumber.slice(3, 6) + - ' ' + - patientDetails?.nhsNumber.slice(6, 10); - - const patientInfo = ( -
-

- {`${patientDetails?.givenName} ${patientDetails?.familyName}`} -

-

- NHS number: {nhsNumber} -

-

- Date of birth: {dob} -

-
- ); - useEffect(() => { const search = async () => { setDownloadStage(DOWNLOAD_STAGE.PENDING); @@ -102,144 +67,17 @@ function LloydGeorgeRecordPage() { setNumberOfFiles, setTotalFileSizeInByte, ]); - const handleMoreActions = () => { - setShowActionsMenu(!showActionsMenu); - }; - const downloadAllHandler = () => { setStage(LG_RECORD_STAGE.DOWNLOAD_ALL); }; - const actionLinks = [ + const actionLinks: Array = [ { label: 'See all files', handler: () => null }, { label: 'Download all files', handler: downloadAllHandler }, { label: 'Delete a selection of files', handler: () => null }, { label: 'Delete file', handler: () => null }, ]; - const PdfCardDetails = () => ( - <> -
-
Last updated: {lastUpdated}
-
- {numberOfFiles} files | File size: {formatFileSize(totalFileSizeInByte)} | File - format: PDF -
-
-
-
-
- Select an action... - -
- {showActionsMenu && ( -
- - -
    - {actionLinks.map((link, i) => ( -
  1. - { - e.preventDefault(); - link.handler(); - }} - > - {link.label} - -
  2. - ))} -
-
-
-
- )} -
- - ); - const PdfCardDescription = () => { - if (downloadStage === DOWNLOAD_STAGE.SUCCEEDED) { - return ; - } else if (downloadStage === DOWNLOAD_STAGE.FAILED) { - return No documents are available; - } else { - return Loading...; - } - }; - - const RecordStage = () => ( - <> - {fullScreen && ( - { - setFullScreen(false); - }} - > - Go back - - )} - <>{patientInfo} - {!fullScreen ? ( - <> - - - - Lloyd George record - - - - - {downloadStage === DOWNLOAD_STAGE.SUCCEEDED && ( - <> -
- - View record - - - -
- - )} - - ) : ( - - )} - - ); const DownloadAllStage = () => ( <>

Downloading documents

@@ -250,7 +88,19 @@ function LloydGeorgeRecordPage() { switch (stage) { case LG_RECORD_STAGE.RECORD: - return ; + return ( + patientDetails && ( + + ) + ); case LG_RECORD_STAGE.DOWNLOAD_ALL: return ; }