Skip to content
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);