Skip to content

Commit

Permalink
refactor: Update error message while adding library team member
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisChV committed Dec 16, 2024
1 parent b110b6b commit 3c42def
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
6 changes: 3 additions & 3 deletions src/library-authoring/library-team/LibraryTeam.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,10 @@ describe('<LibraryTeam />', () => {
expect(await screen.findByText('Team Member added')).toBeInTheDocument();
});

it('shows error when user do not exist', async () => {
it('shows error when specific error', async () => {
const url = getLibraryTeamApiUrl(libraryId);
const axiosMock = new MockAdapter(getAuthenticatedHttpClient());
axiosMock.onPost(url).reply(400, { email: 'Error' });
axiosMock.onPost(url).reply(400, { email: 'This is an specific error.' });

await renderLibraryTeam();

Expand All @@ -204,7 +204,7 @@ describe('<LibraryTeam />', () => {
});

expect(await screen.findByText(
'Error adding Team Member. Please verify that the email is correct and belongs to a registered user.',
'Error adding Team Member. This is an specific error.',
)).toBeInTheDocument();
});

Expand Down
11 changes: 10 additions & 1 deletion src/library-authoring/library-team/LibraryTeam.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,16 @@ const LibraryTeam: React.FC<Record<never, never>> = () => {
}).catch((addMemberError) => {
const errorData = typeof addMemberError === 'object' ? addMemberError.response?.data : undefined;
if (errorData && 'email' in errorData) {
showToast(intl.formatMessage(messages.addMemberEmailError));
const errorEmail = errorData.email;
if (typeof errorEmail === 'string') {
showToast(intl.formatMessage(messages.addMemberSpecificError, {
message: errorEmail,
}));
} else {
showToast(intl.formatMessage(messages.addMemberSpecificError, {

Check warning on line 77 in src/library-authoring/library-team/LibraryTeam.tsx

View check run for this annotation

Codecov / codecov/patch

src/library-authoring/library-team/LibraryTeam.tsx#L76-L77

Added lines #L76 - L77 were not covered by tests
message: errorEmail[0],
}));
}
} else {
showToast(intl.formatMessage(messages.addMemberError));
}
Expand Down
8 changes: 4 additions & 4 deletions src/library-authoring/library-team/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,10 @@ const messages = defineMessages({
defaultMessage: 'Error adding Team Member',
description: 'Message shown when an error occurs while adding a Library Team member',
},
addMemberEmailError: {
id: 'course-authoring.library-authoring.library-team.add-member-email-error',
defaultMessage: 'Error adding Team Member. Please verify that the email is correct and belongs to a registered user.',
description: 'Message shown when an error occurs with email while adding a Library Team member.',
addMemberSpecificError: {
id: 'course-authoring.library-authoring.library-team.add-member-specific-error',
defaultMessage: 'Error adding Team Member. {message}',
description: 'Message shown when an error occurs with an specific error while adding a Library Team member.',
},
deleteMemberSuccess: {
id: 'course-authoring.library-authoring.library-team.delete-member-success',
Expand Down

0 comments on commit 3c42def

Please sign in to comment.