1
0
Fork 0
mirror of synced 2024-07-16 03:35:56 +12:00

adds create user flow

This commit is contained in:
Keviin Åberg Kultalahti 2021-05-12 11:00:18 +02:00
parent 395825dc8b
commit f196f480be
3 changed files with 31 additions and 3 deletions

View file

@ -8,7 +8,7 @@ export function createValidationStore(initialValue, ...validators) {
const touchedStore = derived(value, () => { const touchedStore = derived(value, () => {
if (!touched) { if (!touched) {
touched = true touched = true
return return false
} }
return touched return touched
}) })

View file

@ -1,8 +1,10 @@
<script> <script>
import { ModalContent, Body, Input } from "@budibase/bbui" import { ModalContent, Body, Input, notifications } from "@budibase/bbui"
import { createValidationStore, emailValidator } from "helpers/validation" import { createValidationStore, emailValidator } from "helpers/validation"
import { users } from "stores/portal"
const [email, error, touched] = createValidationStore("", emailValidator) const [email, error, touched] = createValidationStore("", emailValidator)
const password = generatePassword()
function generatePassword() { function generatePassword() {
return Array(30) return Array(30)
@ -21,9 +23,19 @@
) )
.join("") .join("")
} }
async function createUser() {
const res = await users.create({ email: $email, password })
if (res.status) {
notifications.error(res.message)
} else {
notifications.success("Succesfully created user")
}
}
</script> </script>
<ModalContent <ModalContent
onConfirm={createUser}
size="M" size="M"
title="Basic user onboarding" title="Basic user onboarding"
confirmText="Continue" confirmText="Continue"
@ -42,5 +54,5 @@
bind:value={$email} bind:value={$email}
error={$touched && $error} error={$touched && $error}
/> />
<Input disabled label="Password" value={generatePassword()} /> <Input disabled label="Password" value={password} />
</ModalContent> </ModalContent>

View file

@ -14,6 +14,20 @@ export function createUsersStore() {
} }
} }
async function invite(email) {
try {
const response = await api.post(`/api/admin/users/invite`, { email })
return await response.json()
} catch (error) {
return error
}
}
async function create({ email, password }) {
const response = await api.post("/api/admin/users", { email, password, roles: {} })
return await response.json()
}
return { return {
subscribe, subscribe,
// save: async config => { // save: async config => {
@ -26,6 +40,8 @@ export function createUsersStore() {
// } // }
// }, // },
init, init,
invite,
create,
} }
} }