enables functionality to delete users from frontend

This commit is contained in:
Keviin Åberg Kultalahti 2021-05-12 11:08:21 +02:00
parent f196f480be
commit 7137cc6f60
2 changed files with 21 additions and 0 deletions

View File

@ -11,13 +11,25 @@
Input, Input,
Modal, Modal,
ModalContent, ModalContent,
notifications,
} from "@budibase/bbui" } from "@budibase/bbui"
import { fetchData } from "helpers" import { fetchData } from "helpers"
import { users } from "stores/portal"
export let userId export let userId
let deleteUserModal let deleteUserModal
const request = fetchData(`/api/admin/users/${userId}`) const request = fetchData(`/api/admin/users/${userId}`)
async function deleteUser() {
const res = await users.del(userId)
if (res.message) {
notifications.success(res.message)
$goto("./")
} else {
notifications.error("Failed to delete user.")
}
}
</script> </script>
<Layout noPadding gap="XS"> <Layout noPadding gap="XS">
@ -66,6 +78,7 @@
<Modal bind:this={deleteUserModal}> <Modal bind:this={deleteUserModal}>
<ModalContent <ModalContent
warning warning
onConfirm={deleteUser}
title="Delete User" title="Delete User"
confirmText="Delete user" confirmText="Delete user"
cancelText="Cancel" cancelText="Cancel"

View File

@ -25,6 +25,13 @@ export function createUsersStore() {
async function create({ email, password }) { async function create({ email, password }) {
const response = await api.post("/api/admin/users", { email, password, roles: {} }) const response = await api.post("/api/admin/users", { email, password, roles: {} })
init()
return await response.json()
}
async function del(id) {
const response = await api.delete(`/api/admin/users/${id}`)
init()
return await response.json() return await response.json()
} }
@ -42,6 +49,7 @@ export function createUsersStore() {
init, init,
invite, invite,
create, create,
del
} }
} }