diff --git a/packages/builder/src/pages/builder/portal/manage/users/_components/PasswordModal.svelte b/packages/builder/src/pages/builder/portal/manage/users/_components/PasswordModal.svelte index 02501f2de0..8f22371372 100644 --- a/packages/builder/src/pages/builder/portal/manage/users/_components/PasswordModal.svelte +++ b/packages/builder/src/pages/builder/portal/manage/users/_components/PasswordModal.svelte @@ -2,24 +2,78 @@ import { Body, ModalContent, Table, Icon } from "@budibase/bbui" import PasswordCopyRenderer from "./PasswordCopyRenderer.svelte" import { parseToCsv } from "helpers/data/utils" + import { onMount } from "svelte" export let userData + export let createUsersResponse - $: mappedData = userData.map(user => { - return { - email: user.email, - password: user.password, + let hasSuccess + let hasFailure + let title + let failureMessage + + let userDataIndex + let successfulUsers + let unsuccessfulUsers + + const setTitle = () => { + if (hasSuccess) { + title = "Users created!" + } else if (hasFailure) { + title = "Oops!" } + } + + const setFailureMessage = () => { + if (hasSuccess) { + failureMessage = "However there was a problem creating some users." + } else { + failureMessage = "There was a problem creating some users." + } + } + + const setUsers = () => { + userDataIndex = userData.reduce((prev, current) => { + prev[current.email] = current + return prev + }, {}) + + successfulUsers = createUsersResponse.successful.map(user => { + return { + email: user.email, + password: userDataIndex[user.email].password, + } + }) + + unsuccessfulUsers = createUsersResponse.unsuccessful.map(user => { + return { + email: user.email, + reason: user.reason, + } + }) + } + + onMount(() => { + hasSuccess = createUsersResponse.successful.length + hasFailure = createUsersResponse.unsuccessful.length + setTitle() + setFailureMessage() + setUsers() }) - const schema = { + const successSchema = { email: {}, password: {}, } + const failedSchema = { + email: {}, + reason: {}, + } + const downloadCsvFile = () => { const fileName = "passwords.csv" - const content = parseToCsv(["email", "password"], mappedData) + const content = parseToCsv(["email", "password"], successfulUsers) download(fileName, content) } @@ -43,35 +97,51 @@ - - All your new users can be accessed through the autogenerated passwords. Take - note of these passwords or download the CSV file. - + {#if hasFailure} + + {failureMessage} + + + {/if} + {#if hasSuccess} + + All your new users can be accessed through the autogenerated passwords. + Take note of these passwords or download the CSV file. + -
-
- +
+
+ -
- Passwords CSV +
+ Passwords CSV +
-
-
+
+ {/if}