1
0
Fork 0
mirror of synced 2024-07-07 23:35:49 +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, () => {
if (!touched) {
touched = true
return
return false
}
return touched
})

View file

@ -1,8 +1,10 @@
<script>
import { ModalContent, Body, Input } from "@budibase/bbui"
import { ModalContent, Body, Input, notifications } from "@budibase/bbui"
import { createValidationStore, emailValidator } from "helpers/validation"
import { users } from "stores/portal"
const [email, error, touched] = createValidationStore("", emailValidator)
const password = generatePassword()
function generatePassword() {
return Array(30)
@ -21,9 +23,19 @@
)
.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>
<ModalContent
onConfirm={createUser}
size="M"
title="Basic user onboarding"
confirmText="Continue"
@ -42,5 +54,5 @@
bind:value={$email}
error={$touched && $error}
/>
<Input disabled label="Password" value={generatePassword()} />
<Input disabled label="Password" value={password} />
</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 {
subscribe,
// save: async config => {
@ -26,6 +40,8 @@ export function createUsersStore() {
// }
// },
init,
invite,
create,
}
}