From b331f47aa43918be6bdd19e75338743f728e68c8 Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Thu, 25 Aug 2022 22:56:58 +0100 Subject: [PATCH] Update user creation UI --- .../users/_components/PasswordModal.svelte | 120 ++++++++++++++---- .../builder/portal/manage/users/index.svelte | 10 +- packages/builder/src/stores/portal/users.js | 6 +- packages/types/src/documents/pouch.ts | 8 +- packages/worker/src/api/index.ts | 16 +-- .../src/api/routes/global/tests/users.spec.ts | 12 +- packages/worker/src/sdk/users/users.ts | 34 ++--- .../worker/src/tests/TestConfiguration.ts | 18 ++- 8 files changed, 150 insertions(+), 74 deletions(-) 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}