Skip to content

UI: Enhance Error Message Specificity in User Invite Modal #1053

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -40,6 +40,8 @@ const FormControlSelect = styled(FormControl)(() => ({
const EMAIL_REGEXP =
/^[\w!#$%&'*+\-\\/=?^_`{|}~]+(\.[\w!#$%&'*+\-\\/=?^_`{|}~]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,})$/;

const INVITE_EXISTING_USER_ERROR_CODE = 'meshery_cloud-1098';

interface Organization {
id: string;
name: string;
@@ -205,9 +207,34 @@ export default function UserInviteModal({
}).unwrap();

handleSuccess(`Invite send to ${inviteeName.trim() === '' ? inviteeEmail : inviteeName}.`);
} catch (e) {
console.debug('cannot send user invite', e);
handleError(`Invitation to ${inviteeFirstName} ${inviteeLastName} failed.`);
} catch (error: any) {
console.debug('cannot send user invite, API error:', error);
let displayErrorMessage = `Invitation to ${inviteeName.trim() === '' ? inviteeEmail : inviteeName} failed.`;
if (
error &&
error.data &&
typeof error.data === 'object' &&
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create new error codes in the respective handlers.

error.data.code === INVITE_EXISTING_USER_ERROR_CODE
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it necessary to hardcode, we can directly display the error message 🤔

) {
displayErrorMessage =
error.data.suggestedRemediation || error.data.message || displayErrorMessage;
} else if (
error &&
error.data &&
typeof error.data.message === 'string' &&
error.data.message.trim() !== ''
) {
displayErrorMessage = error.data.message;
} else if (
error &&
error.data &&
typeof error.data === 'string' &&
error.data.trim() !== ''
) {
displayErrorMessage = error.data;
}

handleError(displayErrorMessage);
}
setInviteModal(false);
setLoading(false);