Files
speckle-server/packages/frontend-2/components/server-management/ChangeUserRoleDialog.vue
T
andrewwallacespeckle 671979e012 Feature - Frontend2 - Server Settings Pages (#1764)
* Add server management menu item

* Server Management Page & Settings Dialog

* escape from the precommits hooks

* Add Delete User Dialog

* Add invitations page

* Add Projects Page

* Pulling in GraphQL Data

* Settings Mutations

* Fix cardinfo type

* GraphQL in Active Users

* Add icons

* Infinite Load on Active Users

* Tidy Ups

* TS fixes

* Add Update button functionality

* Add Delete User

* Projects

* Home Done

* New query

* Delete User

* WIP User Roles

* Overflow fix

* Table Update

* Add Onclick to rows

* Fix bugs

* Fix console error

* Admin Middleware

* Role Update Dialog

* TS Fixes

* Latest updates

* Tidyups

* Tidy Up Nav Menu

* Tidy Up Card

* ChangeUserRoleDialog Tidyup

* Fix bubbling issue on Table

* Design fixes

* fix: speckle server version hydration mismatch

* Remove Dialog bg-white

* Rename Query, Fix Export

* fix: allowing FormSelectBase to reject updates

* feat: cache policies for new admin graph fields

* feat: cache updates so no refetch necessary

* PR Changes

* Fix Projects Page

* Updates to Roles

* Project Delete Mutation

* Add Resend & Delete Invite Mutation

* Fix console warnings

* Disable active user role select

* Linting fixes

* Reorder

* Linting fixes

* Changes from PR

* Fixes from PR

* Ui Fixes

* Update Settings Dialog Cache on Save

* Fix colours

* Delete Invitation Mutation Moved

* Delete Project Logic moved

* Delete Mutation moved to component

* Change User Role mutation moved to Dialog

* Reorder

* WIP - Checkbox Bug

* attempted checkbox fix

* Update Caching

* Rollback tsc

* Update to Resend Button

* Add new buttons

* Use defineModel

* Re-add emits

* Move mutation

* serverInfo cache update fix

* fixed delete invite cache update

* Updates to Project Delete Dialog Caching

* Remove unneeded props

* Fix caching in DeleteUserDialog

* Improved error handling in server info update

* Swap Invite modal to new style

* updated evictObjectFields details

* Update cache on successfull invite

* Add Invite dialog

* Add project Dialog Update

* defineModel

* Remove emits from Add Project and Invites

* Add missing Dialog

* Updates from PR

* Adjust query

* Remove need for items in admin data query

---------

Co-authored-by: Kristaps Fabians Geikins <fabis94@live.com>
2023-09-04 11:57:34 +01:00

134 lines
3.8 KiB
Vue

<template>
<LayoutDialog
v-model:open="isOpen"
max-width="sm"
title="Change Role"
:buttons="dialogButtons"
>
<div class="flex flex-col gap-6 text-sm text-foreground">
<p>
Are you sure you want to
<strong>change the role of</strong>
the selected user?
</p>
<div v-if="user && newRole && oldRole" class="flex flex-col gap-3">
<div class="flex items-center gap-2">
<UserAvatar :user="user" />
{{ user.name }}
</div>
<div class="flex gap-2 items-center">
<span class="capitalize">{{ getRoleLabel(oldRole) }}</span>
<ArrowLongRightIcon class="h-6 w-6" />
<strong class="capitalize">{{ getRoleLabel(newRole) }}</strong>
</div>
</div>
<div
v-if="user && newRole === Roles.Server.Admin"
class="flex gap-2 items-center bg-danger-lighter dark:bg-danger border-danger-darker dark:border-danger-lighter border rounded-lg p-2"
>
<ExclamationTriangleIcon
class="h-8 w-8 mt-0.5 text-danger-darker dark:text-danger-lighter"
/>
<div>
<p>Make sure you trust {{ user.name }}!</p>
<p>An admin on the server has access to every resource.</p>
</div>
</div>
</div>
</LayoutDialog>
</template>
<script setup lang="ts">
import { computed } from 'vue'
import { LayoutDialog } from '@speckle/ui-components'
import { UserItem } from '~~/lib/server-management/helpers/types'
import { Roles, ServerRoles } from '@speckle/shared'
import { ArrowLongRightIcon, ExclamationTriangleIcon } from '@heroicons/vue/20/solid'
import { getRoleLabel } from '~~/lib/server-management/helpers/utils'
import { changeRoleMutation } from '~~/lib/server-management/graphql/mutations'
import { useGlobalToast, ToastNotificationType } from '~~/lib/common/composables/toast'
import { useMutation } from '@vue/apollo-composable'
import {
convertThrowIntoFetchResult,
getCacheId,
getFirstErrorMessage
} from '~~/lib/common/helpers/graphql'
const emit = defineEmits<{
(e: 'update:open', val: boolean): void
}>()
const props = defineProps<{
open: boolean
user: UserItem | null
oldRole: ServerRoles | undefined
newRole: ServerRoles | undefined
}>()
const { triggerNotification } = useGlobalToast()
const { mutate: mutateChangeRole } = useMutation(changeRoleMutation)
const isOpen = computed({
get: () => props.open,
set: (newVal) => emit('update:open', newVal)
})
const changeUserRoleConfirmed = async () => {
if (!props.user || !props.newRole) {
return
}
const userId = props.user?.id
const newRoleVal = props.newRole
const result = await mutateChangeRole(
{
userRoleInput: { id: userId, role: newRoleVal }
},
{
update: (cache, { data }) => {
if (data?.userRoleChange) {
cache.modify({
id: getCacheId('AdminUserListItem', userId),
fields: {
role: () => newRoleVal
}
})
}
}
}
).catch(convertThrowIntoFetchResult)
if (result?.data?.userRoleChange) {
triggerNotification({
type: ToastNotificationType.Success,
title: 'User role updated',
description: 'The user role has been updated'
})
emit('update:open', false)
} else {
const errorMessage = getFirstErrorMessage(result?.errors)
triggerNotification({
type: ToastNotificationType.Danger,
title: 'Failed to update role',
description: errorMessage
})
}
emit('update:open', false)
}
const dialogButtons = [
{
text: 'Change Role',
props: { color: 'danger', fullWidth: true },
onClick: changeUserRoleConfirmed
},
{
text: 'Cancel',
props: { color: 'secondary', fullWidth: true, outline: true },
onClick: () => emit('update:open', false)
}
]
</script>