diff --git a/packages/builder/src/pages/builder/portal/manage/users/_components/ImportUsersModal.svelte b/packages/builder/src/pages/builder/portal/manage/users/_components/ImportUsersModal.svelte index 5c78dedd66..7ff60530c6 100644 --- a/packages/builder/src/pages/builder/portal/manage/users/_components/ImportUsersModal.svelte +++ b/packages/builder/src/pages/builder/portal/manage/users/_components/ImportUsersModal.svelte @@ -7,20 +7,38 @@ notifications, } from "@budibase/bbui" import { groups } from "stores/portal" + import { emailValidator } from "../../../../../../helpers/validation" import { Constants } from "@budibase/frontend-core" const BYTES_IN_MB = 1000000 const FILE_SIZE_LIMIT = BYTES_IN_MB * 5 - export let showOnboardingTypeModal + export let createUsersFromCsv + let files = [] - let csvString = undefined + let userEmails = [] + let userGroups = [] + let usersRole = null + $: invalidEmails = [] + + const validEmails = userEmails => { + for (const email of userEmails) { + if (emailValidator(email) !== true) invalidEmails.push(email) + } + + if (!invalidEmails.length) return true + + notifications.error( + `Error, please check the following email${ + invalidEmails.length > 1 ? "s" : "" + }: ${invalidEmails.join(", ")}` + ) + + return false + } - /* - function parseCsv() {} -*/ async function handleFile(evt) { const fileArray = Array.from(evt.target.files) if (fileArray.some(file => file.size >= FILE_SIZE_LIMIT)) { @@ -37,6 +55,8 @@ reader.addEventListener("load", function (e) { csvString = e.target.result files = fileArray + + userEmails = csvString.split("\n") }) reader.readAsText(fileArray[0]) } @@ -49,8 +69,8 @@ showCancelButton={false} cancelText="Cancel" showCloseIcon={false} - onConfirm={showOnboardingTypeModal} - disabled={!files.length} + onConfirm={() => createUsersFromCsv({ userEmails, usersRole, userGroups })} + disabled={!userEmails.length || !validEmails(userEmails) || !usersRole} >
Import your users email addrresses from a CSV @@ -61,14 +81,18 @@ -