Skip to content

Commit 1c30beb

Browse files
authored
feat: informative errors on failure to download or create shared record (#472)
* feat: informative errors on failure to download or create shared record Adds user-facing errors if errors appear on download or creation of shared program record. FIXES: APER-3170
1 parent 5db9cfc commit 1c30beb

File tree

2 files changed

+41
-4
lines changed

2 files changed

+41
-4
lines changed

src/components/ProgramRecord/ProgramRecordActions.jsx

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ function ProgramRecordActions({
2020
}) {
2121
const [programRecordUrl, setProgramRecordUrl] = useState(sharedRecordUUID && `${getConfig().CREDENTIALS_BASE_URL}/records/programs/shared/${sharedRecordUUID}`);
2222
const [showCopyTooltip, setShowCopyTooltip] = useState(false);
23+
const [showCreateLinkAlert, setShowCreateLinkAlert] = useState(false);
2324
const [showDownloadToast, setShowDownloadToast] = useState(false);
2425
const [downloadRecord, setDownloadRecord] = useState('default');
2526

@@ -46,6 +47,13 @@ function ProgramRecordActions({
4647
description="Completed state for the download program record button"
4748
/>
4849
),
50+
error: (
51+
<FormattedMessage
52+
id="download.button.error"
53+
defaultMessage="Download program record failed"
54+
description="Error state for the download program record button"
55+
/>
56+
),
4957
},
5058
icons: {
5159
default: <Icon src={Download} />,
@@ -97,7 +105,7 @@ function ProgramRecordActions({
97105
})
98106
.catch((error) => {
99107
logError(error);
100-
throw new Error(error);
108+
setShowCreateLinkAlert(true);
101109
});
102110
handleCopyEvent();
103111
};
@@ -112,8 +120,8 @@ function ProgramRecordActions({
112120
}
113121
})
114122
.catch((error) => {
123+
setDownloadRecord('error');
115124
logError(error);
116-
throw new Error(error);
117125
});
118126
};
119127

@@ -177,6 +185,16 @@ function ProgramRecordActions({
177185
defaultMessage="Create program record link"
178186
description="Button text for creating a link to the program record"
179187
/>
188+
<Toast
189+
onClose={() => setShowCreateLinkAlert(false)}
190+
show={showCreateLinkAlert}
191+
>
192+
<FormattedMessage
193+
id="create.link.error"
194+
defaultMessage="Program record link creation failed. Please log out, log back in, and try again."
195+
description="A message to briefly display when the creation of a shared program record link fails"
196+
/>
197+
</Toast>
180198
</Button>
181199
)}
182200
</OverlayTrigger>
@@ -251,7 +269,7 @@ function ProgramRecordActions({
251269
>
252270
<FormattedMessage
253271
id="successful.record.download.toast.message"
254-
defaultMessage="Program record sucessfullly downloaded"
272+
defaultMessage="Program record sucessfully downloaded"
255273
description="A message to briefly display when the user successfully downloads a program record"
256274
/>
257275
</Toast>
@@ -268,7 +286,11 @@ ProgramRecordActions.propTypes = {
268286
renderBackButton: PropTypes.func.isRequired,
269287
username: PropTypes.string.isRequired,
270288
programUUID: PropTypes.string.isRequired,
271-
sharedRecordUUID: PropTypes.string.isRequired,
289+
sharedRecordUUID: PropTypes.string,
290+
};
291+
292+
ProgramRecordActions.defaultProps = {
293+
sharedRecordUUID: '',
272294
};
273295

274296
export default ProgramRecordActions;

src/components/ProgramRecord/test/DownloadCsv.test.jsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,19 @@ describe('program-record', () => {
5858
expect(await screen.findByText(`Last Updated ${new Date(responseMock.record.program.last_updated).toLocaleDateString()}`)).toBeTruthy();
5959
expect(screen.getByRole('link', { name: 'read more in our records help area.' })).toBeTruthy();
6060
});
61+
it('renders an alert when CSV download is unsuccessful', async () => {
62+
const responseMock = programRecordFactory.build();
63+
await act(async () => {
64+
const axiosMock = new MockAdapter(getAuthenticatedHttpClient());
65+
axiosMock
66+
.onGet(`${getConfig().CREDENTIALS_BASE_URL}/records/api/v1/program_records/test-id/?is_public=true`)
67+
.reply(200, responseMock);
68+
axiosMock
69+
.onGet(`${getConfig().CREDENTIALS_BASE_URL}/records/programs/shared/test-id/csv`)
70+
.reply(404, {});
71+
render(<ProgramRecord isPublic />);
72+
});
73+
fireEvent.click(await screen.findByRole('button', { name: 'Download program record' }));
74+
waitFor(() => expect(screen.getByRole('button', { name: 'Download program record failed' })).toBeTruthy());
75+
});
6176
});

0 commit comments

Comments
 (0)