diff --git a/src/components/ProgramRecord/ProgramRecordActions.jsx b/src/components/ProgramRecord/ProgramRecordActions.jsx
index 9d9b90b8..b3c5443a 100644
--- a/src/components/ProgramRecord/ProgramRecordActions.jsx
+++ b/src/components/ProgramRecord/ProgramRecordActions.jsx
@@ -20,6 +20,7 @@ function ProgramRecordActions({
}) {
const [programRecordUrl, setProgramRecordUrl] = useState(sharedRecordUUID && `${getConfig().CREDENTIALS_BASE_URL}/records/programs/shared/${sharedRecordUUID}`);
const [showCopyTooltip, setShowCopyTooltip] = useState(false);
+ const [showCreateLinkAlert, setShowCreateLinkAlert] = useState(false);
const [showDownloadToast, setShowDownloadToast] = useState(false);
const [downloadRecord, setDownloadRecord] = useState('default');
@@ -46,6 +47,13 @@ function ProgramRecordActions({
description="Completed state for the download program record button"
/>
),
+ error: (
+
+ ),
},
icons: {
default: ,
@@ -97,7 +105,7 @@ function ProgramRecordActions({
})
.catch((error) => {
logError(error);
- throw new Error(error);
+ setShowCreateLinkAlert(true);
});
handleCopyEvent();
};
@@ -112,8 +120,8 @@ function ProgramRecordActions({
}
})
.catch((error) => {
+ setDownloadRecord('error');
logError(error);
- throw new Error(error);
});
};
@@ -177,6 +185,16 @@ function ProgramRecordActions({
defaultMessage="Create program record link"
description="Button text for creating a link to the program record"
/>
+ setShowCreateLinkAlert(false)}
+ show={showCreateLinkAlert}
+ >
+
+
)}
@@ -251,7 +269,7 @@ function ProgramRecordActions({
>
@@ -268,7 +286,11 @@ ProgramRecordActions.propTypes = {
renderBackButton: PropTypes.func.isRequired,
username: PropTypes.string.isRequired,
programUUID: PropTypes.string.isRequired,
- sharedRecordUUID: PropTypes.string.isRequired,
+ sharedRecordUUID: PropTypes.string,
+};
+
+ProgramRecordActions.defaultProps = {
+ sharedRecordUUID: '',
};
export default ProgramRecordActions;
diff --git a/src/components/ProgramRecord/test/DownloadCsv.test.jsx b/src/components/ProgramRecord/test/DownloadCsv.test.jsx
index 5e7a5d31..b92f612e 100644
--- a/src/components/ProgramRecord/test/DownloadCsv.test.jsx
+++ b/src/components/ProgramRecord/test/DownloadCsv.test.jsx
@@ -58,4 +58,19 @@ describe('program-record', () => {
expect(await screen.findByText(`Last Updated ${new Date(responseMock.record.program.last_updated).toLocaleDateString()}`)).toBeTruthy();
expect(screen.getByRole('link', { name: 'read more in our records help area.' })).toBeTruthy();
});
+ it('renders an alert when CSV download is unsuccessful', async () => {
+ const responseMock = programRecordFactory.build();
+ await act(async () => {
+ const axiosMock = new MockAdapter(getAuthenticatedHttpClient());
+ axiosMock
+ .onGet(`${getConfig().CREDENTIALS_BASE_URL}/records/api/v1/program_records/test-id/?is_public=true`)
+ .reply(200, responseMock);
+ axiosMock
+ .onGet(`${getConfig().CREDENTIALS_BASE_URL}/records/programs/shared/test-id/csv`)
+ .reply(404, {});
+ render();
+ });
+ fireEvent.click(await screen.findByRole('button', { name: 'Download program record' }));
+ waitFor(() => expect(screen.getByRole('button', { name: 'Download program record failed' })).toBeTruthy());
+ });
});