Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PRMDR 294 (Partial) - PDF Actions Nav #88

Merged
merged 11 commits into from
Oct 13, 2023
Merged
14 changes: 14 additions & 0 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"sass": "^1.66.1",
"serve": "^14.2.1",
"typescript": "^4.9.5",
"usehooks-ts": "^2.9.1",
"util": "^0.12.5",
"web-vitals": "^2.1.4"
},
Expand Down
113 changes: 98 additions & 15 deletions app/src/pages/lloydGeorgeRecordPage/LloydGeorgeRecordPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,17 @@ 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';

enum LG_RECORD_STAGE {
RECORD = 0,
DOWNLOAD_ALL = 1,
}

function LloydGeorgeRecordPage() {
const [patientDetails] = usePatientDetailsContext();
const [downloadStage, setDownloadStage] = useState(DOWNLOAD_STAGE.INITIAL);
Expand All @@ -23,6 +31,13 @@ function LloydGeorgeRecordPage() {
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))
Expand Down Expand Up @@ -83,27 +98,83 @@ function LloydGeorgeRecordPage() {
setNumberOfFiles,
setTotalFileSizeInByte,
]);
const handleMoreActions = () => {
setShowActionsMenu(!showActionsMenu);
};

const downloadAllHandler = () => {
setStage(LG_RECORD_STAGE.DOWNLOAD_ALL);
};

const pdfCardDescription = (
const actionLinks = [
{ 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 = () => (
<>
<span style={{ marginBottom: 16 }}>Last updated: {lastUpdated}</span>
<span style={{ color: '#4C6272' }}>
{numberOfFiles} files | File size: {formatFileSize(totalFileSizeInByte)} | File
format: PDF
</span>
<div>
<div style={{ marginBottom: 16 }}>Last updated: {lastUpdated}</div>
<div style={{ color: '#4C6272' }}>
{numberOfFiles} files | File size: {formatFileSize(totalFileSizeInByte)} | File
format: PDF
</div>
</div>
<div className="lg-actions">
<div
className={`nhsuk-select lg-actions-select ${
showActionsMenu ? 'lg-actions-select--selected' : ''
}`}
onClick={handleMoreActions}
style={{ background: '#fff' }}
>
<div
className={`lg-actions-select_border ${
showActionsMenu ? 'lg-actions-select_border--selected' : ''
}`}
/>
<span className="lg-actions-select_placeholder">Select an action...</span>
<Chevron className="lg-actions-select_icon" />
</div>
{showActionsMenu && (
<div ref={actionsRef}>
<Card className="lg-actions-menu">
<Card.Content>
<ol>
{actionLinks.map((link, i) => (
<li key={link.label + i}>
<Link
to="#"
onClick={(e) => {
e.preventDefault();
link.handler();
}}
>
{link.label}
</Link>
</li>
))}
</ol>
</Card.Content>
</Card>
</div>
)}
</div>
</>
);
const displayPdfCardDescription = () => {
const PdfCardDescription = () => {
if (downloadStage === DOWNLOAD_STAGE.SUCCEEDED) {
return pdfCardDescription;
return <PdfCardDetails />;
} else if (downloadStage === DOWNLOAD_STAGE.FAILED) {
return 'No documents are available';
return <span>No documents are available</span>;
} else {
return 'Loading...';
return <span> Loading...</span>;
}
};

return (
const RecordStage = () => (
<>
{fullScreen && (
<BackLink
Expand All @@ -119,13 +190,11 @@ function LloydGeorgeRecordPage() {
{!fullScreen ? (
<>
<Card style={{ marginBottom: 0 }}>
<Card.Content>
<Card.Content style={{ position: 'relative' }}>
<Card.Heading style={{ fontWeight: '700', fontSize: '24px' }}>
Lloyd George record
</Card.Heading>
<Card.Description style={{ fontSize: '16px' }}>
{displayPdfCardDescription()}
</Card.Description>
<PdfCardDescription />
</Card.Content>
</Card>
{downloadStage === DOWNLOAD_STAGE.SUCCEEDED && (
Expand Down Expand Up @@ -162,6 +231,20 @@ function LloydGeorgeRecordPage() {
)}
</>
);
const DownloadAllStage = () => (
<>
<h1>Downloading documents</h1>
<h2>Alex Cool Bloggs</h2>
<h3>NHS number: 1428571428</h3>
</>
);

switch (stage) {
case LG_RECORD_STAGE.RECORD:
return <RecordStage />;
case LG_RECORD_STAGE.DOWNLOAD_ALL:
return <DownloadAllStage />;
}
}

export default LloydGeorgeRecordPage;
65 changes: 65 additions & 0 deletions app/src/styles/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,71 @@
font-size: 24px;
}

.lg-actions {
position: absolute;
top: 32px;
right: 32px;
&-select {
border-color: #000;
position: relative;
box-sizing: border-box;
border: none;
padding: 0;
width: 182.5px;
@media (max-width: 640px) {
width: 161.5px;
}
@media (max-width: 480px) {
display: none;
}
&_border {
border: solid black 2px;
width: 100%;
height: 100%;
&--selected {
border-width: 4px;
}
}
&:focus,
&:active,
&--selected {
box-shadow: 0px 0px 0px 4px #ffeb3b;
}
&_placeholder {
position: absolute;
top: 50%;
transform: translateY(-50%);
left: 10px;
box-sizing: border-box;
}
&_icon {
height: 9px;
width: auto;
position: absolute;
top: 50%;
transform: translateY(-50%);
right: 5px;
box-sizing: border-box;
}

cursor: pointer;
}
&-menu {
position: absolute;
right: 0px;
z-index: 1000;
width: 252.5px;
box-shadow: 0 10px 10px rgba(0, 0, 0, 0.3);
ol {
padding-left: 0;
li {
font-size: 16px;
list-style-type: none;
}
}
}
}

@-moz-document url-prefix() {
#pdf-viewer {
margin-top: 6px;
Expand Down
6 changes: 6 additions & 0 deletions app/src/styles/down-chevron.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading