adds create user flow
This commit is contained in:
parent
395825dc8b
commit
f196f480be
|
@ -8,7 +8,7 @@ export function createValidationStore(initialValue, ...validators) {
|
|||
const touchedStore = derived(value, () => {
|
||||
if (!touched) {
|
||||
touched = true
|
||||
return
|
||||
return false
|
||||
}
|
||||
return touched
|
||||
})
|
||||
|
|
|
@ -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>
|
||||
|
|
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue