1
0
Fork 0
mirror of synced 2024-07-04 05:50:57 +12:00

Fix initial role not being set when updating user role

This commit is contained in:
Andrew Kingston 2021-05-18 19:08:23 +01:00
parent ac3edb2f60
commit 9cdd519a8a

View file

@ -1,7 +1,6 @@
<script> <script>
import { createEventDispatcher } from "svelte" import { createEventDispatcher } from "svelte"
import { Body, Select, ModalContent, notifications } from "@budibase/bbui" import { Body, Select, ModalContent, notifications } from "@budibase/bbui"
import { fetchData } from "helpers"
import { users } from "stores/portal" import { users } from "stores/portal"
export let app export let app
@ -11,7 +10,7 @@
const roles = app.roles const roles = app.roles
let options = roles.map(role => role._id) let options = roles.map(role => role._id)
let selectedRole let selectedRole = user?.roles?.[app?._id]
async function updateUserRoles() { async function updateUserRoles() {
const res = await users.updateRoles({ const res = await users.updateRoles({
@ -24,7 +23,7 @@
if (res.status === 400) { if (res.status === 400) {
notifications.error("Failed to update role") notifications.error("Failed to update role")
} else { } else {
notifications.success("Roles updated") notifications.success("Role updated")
dispatch("update") dispatch("update")
} }
} }
@ -32,20 +31,20 @@
<ModalContent <ModalContent
onConfirm={updateUserRoles} onConfirm={updateUserRoles}
title="Update App Roles" title="Update App Role"
confirmText="Update roles" confirmText="Update role"
cancelText="Cancel" cancelText="Cancel"
size="M" size="M"
showCloseIcon={false} showCloseIcon={false}
> >
<Body noPadding <Body noPadding>
>Update {user.email}'s roles for <strong>{app.name}</strong>.</Body Update {user.email}'s role for <strong>{app.name}</strong>.
> </Body>
<Select <Select
placeholder={null} placeholder={null}
bind:value={selectedRole} bind:value={selectedRole}
on:change on:change
{options} {options}
label="Select roles:" label="Role"
/> />
</ModalContent> </ModalContent>