diff --git a/packages/builder/src/pages/builder/portal/manage/users/_components/AddUserModal.svelte b/packages/builder/src/pages/builder/portal/manage/users/_components/AddUserModal.svelte index fc9c4b8cf2..44ec8085a6 100644 --- a/packages/builder/src/pages/builder/portal/manage/users/_components/AddUserModal.svelte +++ b/packages/builder/src/pages/builder/portal/manage/users/_components/AddUserModal.svelte @@ -13,14 +13,14 @@ import { emailValidator } from "helpers/validation" export let showOnboardingTypeModal + const password = Math.random().toString(36).substring(2, 22) let disabled let userGroups = [] - $: errors = [] + $: hasGroupsLicense = $auth.user?.license.features.includes( Constants.Features.USER_GROUPS ) - $: userData = [ { email: "", @@ -29,6 +29,7 @@ forceResetPassword: true, }, ] + $: hasError = userData.find(x => x.error != null) function removeInput(idx) { userData = userData.filter((e, i) => i !== idx) @@ -41,38 +42,45 @@ role: "appUser", password: Math.random().toString(36).substring(2, 22), forceResetPassword: true, + error: null, }, ] } function validateInput(email, index) { if (email) { - if (emailValidator(email) === true) { - errors[index] = true - return null - } else { - errors[index] = false - return emailValidator(email) - } + const res = emailValidator(email) + userData[index].error = res === true ? null : res + } else { + userData[index].error = "Please enter an email address" } + return userData[index].error == null + } + + const onConfirm = () => { + let valid = true + userData.forEach((input, index) => { + valid = validateInput(input.email, index) && valid + }) + if (!valid) { + return false + } + showOnboardingTypeModal({ users: userData, groups: userGroups }) } - showOnboardingTypeModal({ users: userData, groups: userGroups })} + {onConfirm} size="M" title="Add new user" confirmText="Add user" confirmDisabled={disabled} cancelText="Cancel" showCloseIcon={false} - disabled={errors.some(x => x === false) || - userData.some(x => x.email === "" || x.email === null)} + disabled={hasError || !userData.length} > - - + {#each userData as input, index}
+
option.name} getOptionValue={option => option._id} @@ -120,10 +125,9 @@