Skip to content

Commit

Permalink
fix: Added error message when user can't approve membership
Browse files Browse the repository at this point in the history
  • Loading branch information
josebui committed Oct 2, 2023
1 parent 7b10b77 commit 6c67b19
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 38 deletions.
3 changes: 2 additions & 1 deletion src/localization/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -1014,7 +1014,8 @@
"addMemberships.unique": "One or more users are already collaborators of this story map.",
"approved_membership": "You have been added to “{{storyMapTitle}}”",
"approve_invite_success": "You have been added to “{{storyMapTitle}}”",
"approve_invite_error": "Failed to accept Story Map invite",
"approveMembership.update_not_allowed": "Failed to accept Story Map invite",
"approveMembership.update_not_allowed_permissions_validation": "You do not have permission to accept this Story Map invite",
"invite_document_title": "Story Map Invite"
},
"site": {
Expand Down
3 changes: 2 additions & 1 deletion src/localization/locales/es-ES.json
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,8 @@
"addMemberships.unique": "Uno o más usuarios ya son colaboradores de este story map.",
"approved_membership": "Te han agregado a “{{storyMapTitle}}”",
"approve_invite_success": "Te han agregado a “{{storyMapTitle}}”",
"approve_invite_error": "No se pudo aceptar la invitación al Story Map",
"approveMembership.update_not_allowed": "No se pudo aceptar la invitación al Story Map",
"approveMembership.update_not_allowed_permissions_validation": "No tienes permiso para aceptar esta invitación de Story Map",
"invite_document_title": "Invitación a Story Map"
},
"site": {
Expand Down
6 changes: 1 addition & 5 deletions src/navigation/components/Routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,11 +193,7 @@ const paths = [
isEmbedded: true,
},
}),
path('/tools/story-maps/accept', StoryMapInvite, {
optionalAuth: {
enabled: true,
},
}),
path('/tools/story-maps/accept', StoryMapInvite),
path('*', NotFound),
];

Expand Down
46 changes: 16 additions & 30 deletions src/storyMap/components/StoryMapInvite.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,44 +52,26 @@ const StoryMapInvite = () => {
}, [token, decodedToken, membershipId])
);

useEffect(() => {
if (!success && !error) {
return;
}

if (success) {
dispatch(
addMessage({
severity: 'success',
content: 'storyMap.approve_invite_success',
params: {
storyMapTitle: storyMap.title,
},
})
);
}

if (error) {
dispatch(
addMessage({
severity: 'error',
content: 'storyMap.approve_invite_error',
})
);
}
}, [success, error, storyMap, dispatch, navigate]);

useEffect(() => {
if (!success) {
return;
}
navigate(`/tools/story-maps/${storyMap.storyMapId}/${storyMap.slug}/edit`);
trackEvent('storymap.share.accept');
}, [success, navigate, trackEvent, storyMap]);
dispatch(
addMessage({
severity: 'success',
content: 'storyMap.approve_invite_success',
params: {
storyMapTitle: storyMap.title,
},
})
);
}, [success, navigate, trackEvent, dispatch, storyMap]);

useDocumentTitle(t('storyMap.invite_document_title'));

if (processing || !storyMap) {
if (processing) {
return <PageLoader />;
}

Expand All @@ -99,7 +81,11 @@ const StoryMapInvite = () => {

return (
<PageContainer>
<Alert severity="error">{t('storyMap.approve_invite_error')}</Alert>
{error?.parsedErrors.map((error, index) => (
<Alert key={index} severity={error.severity}>
{t(error.content, error.params)}
</Alert>
))}
</PageContainer>
);
};
Expand Down
30 changes: 30 additions & 0 deletions src/storyMap/components/StoryMapInvite.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,33 @@ test('StoryMapInvite: Invalid token', async () => {
).toBeInTheDocument()
);
});

test('StoryMapInvite: Different user token', async () => {
const navigate = jest.fn();
useNavigate.mockReturnValue(navigate);

const searchParams = new URLSearchParams();
searchParams.set('token', TOKEN);
useSearchParams.mockReturnValue([searchParams]);

mockTerrasoAPIrequestGraphQL({
'mutation approveMembershipToken': Promise.reject({
content: 'update_not_allowed_permissions_validation',
}),
});

await setup({
user: {
id: 'user-id-2',
email: '',
},
});

expect(
within(screen.getByRole('alert')).getByText(
/You do not have permission to accept this Story Map invite/i
)
).toBeInTheDocument();

expect(navigate).not.toHaveBeenCalled();
});
2 changes: 1 addition & 1 deletion src/storyMap/storyMapSlice.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ const storyMapSlice = createSlice({
...state.memberships.approve,
[action.meta.arg.membership.membershipId]: {
processing: false,
error: true,
error: action.payload,
},
},
},
Expand Down

0 comments on commit 6c67b19

Please sign in to comment.