Skip to content

Commit

Permalink
PRMDR-655 Update color of completion screens (#283)
Browse files Browse the repository at this point in the history
Update confirmation colors
  • Loading branch information
RioKnightleyNHS authored Feb 8, 2024
1 parent 6d52e0b commit 17e1998
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 28 deletions.
Binary file added app/public/dev/testFile.pdf
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { LG_RECORD_STAGE } from '../../../types/blocks/lloydGeorgeStages';
import useBaseAPIUrl from '../../../helpers/hooks/useBaseAPIUrl';
import usePatient from '../../../helpers/hooks/usePatient';
import { errorToParams } from '../../../helpers/utils/errorToParams';
import { isMock } from '../../../helpers/utils/isLocal';

export type Props = {
docType: DOCUMENT_TYPE;
Expand Down Expand Up @@ -70,7 +71,12 @@ function DeleteDocumentsStage({

const handleYesOption = async () => {
setDeletionStage(SUBMISSION_STATE.PENDING);

const onSuccess = () => {
setDeletionStage(SUBMISSION_STATE.SUCCEEDED);
if (setDownloadStage) {
setDownloadStage(DOWNLOAD_STAGE.FAILED);
}
};
try {
const response: DeleteResponse = await deleteAllDocuments({
docType: docType,
Expand All @@ -80,19 +86,20 @@ function DeleteDocumentsStage({
});

if (response.status === 200) {
setDeletionStage(SUBMISSION_STATE.SUCCEEDED);
if (setDownloadStage) {
setDownloadStage(DOWNLOAD_STAGE.FAILED);
}
onSuccess();
}
} catch (e) {
const error = e as AxiosError;
if (error.response?.status === 403) {
navigate(routes.START);
if (isMock(error)) {
onSuccess();
} else {
navigate(routes.SERVER_ERROR + errorToParams(error));
if (error.response?.status === 403) {
navigate(routes.START);
} else {
navigate(routes.SERVER_ERROR + errorToParams(error));
}
setDeletionStage(SUBMISSION_STATE.FAILED);
}
setDeletionStage(SUBMISSION_STATE.FAILED);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { routes } from '../../../types/generic/routes';
import { useNavigate, Link } from 'react-router-dom';
import { errorToParams } from '../../../helpers/utils/errorToParams';
import { AxiosError } from 'axios/index';
import { isMock } from '../../../helpers/utils/isLocal';

const FakeProgress = require('fake-progress');

Expand Down Expand Up @@ -86,6 +87,19 @@ function LloydGeorgeDownloadAllStage({
}, [linkAttributes]);

useEffect(() => {
const onFail = (error: AxiosError) => {
if (isMock(error)) {
if (typeof window !== 'undefined') {
const { protocol, host } = window.location;
setLinkAttributes({
url: protocol + '//' + host + '/dev/testFile.pdf',
filename: 'testFile.pdf',
});
}
} else {
navigate(routes.SERVER_ERROR + errorToParams(error));
}
};
const onPageLoad = async () => {
progressTimer.stop();
window.clearInterval(intervalTimer);
Expand All @@ -107,12 +121,14 @@ function LloydGeorgeDownloadAllStage({
baseHeaders,
});
} catch (e) {
navigate(routes.SERVER_ERROR + errorToParams(e as AxiosError));
const error = e as AxiosError;
onFail(error);
} // This is fail and forget at this point in time.
}
setLinkAttributes({ url: preSignedUrl, filename: filename });
} catch (e) {
navigate(routes.SERVER_ERROR + errorToParams(e as AxiosError));
const error = e as AxiosError;
onFail(error);
}
};

Expand Down
3 changes: 3 additions & 0 deletions app/src/helpers/requests/getLloydGeorgeRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ async function getLloydGeorgeRecord({
patientId: nhsNumber,
},
});
if (!data.presign_url.startsWith('https://')) {
return Promise.reject({ response: { status: 500 } });
}
return data;
}

Expand Down
45 changes: 32 additions & 13 deletions app/src/pages/lloydGeorgeRecordPage/LloydGeorgeRecordPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { REPOSITORY_ROLE } from '../../types/generic/authRole';
import { routes } from '../../types/generic/routes';
import { useNavigate } from 'react-router';
import { errorToParams } from '../../helpers/utils/errorToParams';
import { isMock } from '../../helpers/utils/isLocal';
import moment from 'moment';

function LloydGeorgeRecordPage() {
const patientDetails = usePatient();
Expand All @@ -36,6 +38,20 @@ function LloydGeorgeRecordPage() {
const deleteAfterDownload = role === REPOSITORY_ROLE.GP_ADMIN && isBSOL === false;

useEffect(() => {
const onSuccess = (
files_count: number,
updated_date: string,
presign_url: string,
file_size: number,
) => {
setNumberOfFiles(files_count);
setLastUpdated(getFormattedDatetime(new Date(updated_date)));
setLloydGeorgeUrl(presign_url);
setDownloadStage(DOWNLOAD_STAGE.SUCCEEDED);
setTotalFileSizeInByte(file_size);
setDownloadStage(DOWNLOAD_STAGE.SUCCEEDED);
};

const onPageLoad = async () => {
const nhsNumber: string = patientDetails?.nhsNumber || '';
try {
Expand All @@ -46,23 +62,26 @@ function LloydGeorgeRecordPage() {
baseHeaders,
});
if (presign_url?.startsWith('https://')) {
setNumberOfFiles(number_of_files);
setLastUpdated(getFormattedDatetime(new Date(last_updated)));
setLloydGeorgeUrl(presign_url);
setDownloadStage(DOWNLOAD_STAGE.SUCCEEDED);
setTotalFileSizeInByte(total_file_size_in_byte);
onSuccess(number_of_files, last_updated, presign_url, total_file_size_in_byte);
}
setDownloadStage(DOWNLOAD_STAGE.SUCCEEDED);
} catch (e) {
const error = e as AxiosError;
if (error.response?.status === 504) {
setDownloadStage(DOWNLOAD_STAGE.TIMEOUT);
} else if (error.response?.status === 404) {
setDownloadStage(DOWNLOAD_STAGE.NO_RECORDS);
} else if (error.response?.status && error.response?.status >= 500) {
navigate(routes.SERVER_ERROR + errorToParams(error));
if (isMock(error)) {
if (nhsNumber === '4857773456') {
setDownloadStage(DOWNLOAD_STAGE.NO_RECORDS);
} else {
onSuccess(1, moment().format(), '/dev/testFile.pdf', 59000);
}
} else {
setDownloadStage(DOWNLOAD_STAGE.FAILED);
if (error.response?.status === 504) {
setDownloadStage(DOWNLOAD_STAGE.TIMEOUT);
} else if (error.response?.status === 404) {
setDownloadStage(DOWNLOAD_STAGE.NO_RECORDS);
} else if (error.response?.status && error.response?.status >= 500) {
navigate(routes.SERVER_ERROR + errorToParams(error));
} else {
setDownloadStage(DOWNLOAD_STAGE.FAILED);
}
}
}
};
Expand Down
5 changes: 4 additions & 1 deletion app/src/pages/patientSearchPage/PatientSearchPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,10 @@ function PatientSearchPage() {
} catch (e) {
const error = e as AxiosError;
if (isMock(error)) {
handleSuccess(buildPatientDetails());
handleSuccess({
...buildPatientDetails(),
nhsNumber,
});
return;
}
if (error.response?.status === 400) {
Expand Down
6 changes: 3 additions & 3 deletions app/src/styles/App.scss
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ $govuk-compatibility-govukelements: true;
border-spacing: 0;
box-sizing: inherit;
text-align: left;
color: #005eb8;
color: $color_nhsuk-blue;
text-decoration: underline;
&:hover {
color: #7c2855;
Expand Down Expand Up @@ -287,7 +287,7 @@ $govuk-compatibility-govukelements: true;
&_details {
&-content {
text-align: center;
background-color: #555;
background-color: $color_nhsuk-blue;
color: #fff;
padding: 38px;
font-size: 20px;
Expand All @@ -312,7 +312,7 @@ $govuk-compatibility-govukelements: true;
text-align: center !important;
width: auto !important;
float: none !important;
background-color: #555;
background-color: $color_nhsuk-blue;
color: #fff;
}

Expand Down

0 comments on commit 17e1998

Please sign in to comment.