adds create user flow
This commit is contained in:
parent
431a3e5929
commit
a3b44caa37
|
@ -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
|
||||||
})
|
})
|
||||||
|
|
|
@ -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>
|
||||||
|
|
|
@ -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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue