Browse Source

refactor/gui-v2-user-management-invite-cleanup

pull/2854/head
Muhammed Mustafa 3 years ago
parent
commit
48138df979
  1. 32
      packages/nc-gui-v2/components/dashboard/settings/UserManagement.vue
  2. 20
      packages/nc-gui-v2/components/dashboard/settings/userManagement/ShareBase.vue
  3. 11
      packages/nc-gui-v2/components/dashboard/settings/userManagement/UsersModal.vue

32
packages/nc-gui-v2/components/dashboard/settings/UserManagement.vue

@ -1,6 +1,7 @@
<script setup lang="ts"> <script setup lang="ts">
import { useDebounce } from '@vueuse/core' import { useDebounce } from '@vueuse/core'
import KebabIcon from '~icons/ic/baseline-more-vert' import KebabIcon from '~icons/ic/baseline-more-vert'
import { extractSdkResponseErrorMsg } from '~~/utils/errorUtils'
import UsersModal from './userManagement/UsersModal.vue' import UsersModal from './userManagement/UsersModal.vue'
import { projectRoleTagColors } from '~/utils/userUtils' import { projectRoleTagColors } from '~/utils/userUtils'
import MidAccountIcon from '~icons/mdi/account-outline' import MidAccountIcon from '~icons/mdi/account-outline'
@ -21,7 +22,7 @@ const toast = useToast()
const { $api, $e } = useNuxtApp() const { $api, $e } = useNuxtApp()
const { project } = useProject() const { project } = useProject()
let users = $ref<null | Array<User>>(null) let users = $ref<null | User[]>(null)
let selectedUser = $ref<null | User>(null) let selectedUser = $ref<null | User>(null)
let showUserModal = $ref(false) let showUserModal = $ref(false)
let showUserDeleteModal = $ref(false) let showUserDeleteModal = $ref(false)
@ -34,7 +35,6 @@ const debouncedSearchText = useDebounce(searchText, 300)
const loadUsers = async (page = currentPage, limit = currentLimit) => { const loadUsers = async (page = currentPage, limit = currentLimit) => {
try { try {
console.log('loadUsers', page, limit)
if (!project.value?.id) return if (!project.value?.id) return
const response = await $api.auth.projectUserList(project.value?.id, <any> { const response = await $api.auth.projectUserList(project.value?.id, <any> {
@ -44,25 +44,26 @@ const loadUsers = async (page = currentPage, limit = currentLimit) => {
query: searchText.value, query: searchText.value,
}, },
}) })
console.log('userData', response)
if (!response.users) return if (!response.users) return
totalRows = response.users.pageInfo.totalRows ?? 0 totalRows = response.users.pageInfo.totalRows ?? 0
users = response.users.list as Array<User> users = response.users.list as User[]
} catch (e) { } catch (e: any) {
console.log(e) console.error(e)
toast.error(await extractSdkResponseErrorMsg(e))
} }
} }
const inviteUser = async (user) => { const inviteUser = async (user: User) => {
try { try {
if (!project.value?.id) return if (!project.value?.id) return
await $api.auth.projectUserAdd(project.id, user); await $api.auth.projectUserAdd(project.value.id, user);
toast.success('Successfully added user to project'); toast.success('Successfully added user to project');
await loadUsers(); await loadUsers();
} catch (e) { } catch (e: any) {
toast.error(e.response.data.msg); console.error(e)
toast.error(await extractSdkResponseErrorMsg(e))
} }
$e('a:user:add'); $e('a:user:add');
@ -75,8 +76,9 @@ const deleteUser = async () => {
await $api.auth.projectUserRemove(project.value.id, selectedUser.id); await $api.auth.projectUserRemove(project.value.id, selectedUser.id);
toast.success('Successfully deleted user from project'); toast.success('Successfully deleted user from project');
await loadUsers(); await loadUsers();
} catch (e) { } catch (e: any) {
toast.error(e.response.data.msg); console.error(e)
toast.error(await extractSdkResponseErrorMsg(e))
} }
$e('a:user:delete'); $e('a:user:delete');
@ -104,8 +106,9 @@ const resendInvite = async (user: User) => {
await $api.auth.projectUserResendInvite(project.value.id, user.id); await $api.auth.projectUserResendInvite(project.value.id, user.id);
toast.success('Invite email sent successfully'); toast.success('Invite email sent successfully');
await loadUsers(); await loadUsers();
} catch (e) { } catch (e: any) {
toast.error(e.response.data.msg); console.error(e)
toast.error(await extractSdkResponseErrorMsg(e))
} }
$e('a:user:resend-invite'); $e('a:user:resend-invite');
@ -130,6 +133,7 @@ watch(
() => debouncedSearchText.value, () => debouncedSearchText.value,
() => loadUsers(), () => loadUsers(),
) )
</script> </script>
<template> <template>

20
packages/nc-gui-v2/components/dashboard/settings/userManagement/ShareBase.vue

@ -2,7 +2,7 @@
import { useToast } from 'vue-toastification' import { useToast } from 'vue-toastification'
import OpenInNewIcon from '~icons/mdi/open-in-new' import OpenInNewIcon from '~icons/mdi/open-in-new'
import { dashboardUrl } from '~/utils/urlUtils' import { dashboardUrl } from '~/utils/urlUtils'
import { extractSdkResponseErrorMsg } from '~~/utils/errorUtils'
import MdiReload from '~icons/mdi/reload' import MdiReload from '~icons/mdi/reload'
import DownIcon from '~icons/ic/round-keyboard-arrow-down' import DownIcon from '~icons/ic/round-keyboard-arrow-down'
import ContentCopyIcon from '~icons/mdi/content-copy' import ContentCopyIcon from '~icons/mdi/content-copy'
@ -38,9 +38,9 @@ const loadBase = async () => {
url: res.url, url: res.url,
role: res.roles, role: res.roles,
} }
} catch (e) { } catch (e: any) {
console.error(e) console.error(e)
toast.error('Something went wrong') toast.error(await extractSdkResponseErrorMsg(e))
} }
} }
@ -54,9 +54,9 @@ const createShareBase = async (role = ShareBaseRole.Viewer) => {
base = res || {} base = res || {}
base.role = role base.role = role
} catch (e) { } catch (e: any) {
console.error(e) console.error(e)
toast.error('Something went wrong') toast.error(await extractSdkResponseErrorMsg(e))
} }
$e('a:shared-base:enable', { role }) $e('a:shared-base:enable', { role })
} }
@ -67,8 +67,9 @@ const disableSharedBase = async () => {
await $api.project.sharedBaseDisable(project.value.id) await $api.project.sharedBaseDisable(project.value.id)
base = {} base = {}
} catch (e) { } catch (e: any) {
toast.error(e.message) console.error(e)
toast.error(await extractSdkResponseErrorMsg(e))
} }
$e('a:shared-base:disable') $e('a:shared-base:disable')
@ -83,8 +84,9 @@ const recreate = async () => {
}) })
const newBase = sharedBase || {} const newBase = sharedBase || {}
base = { ...newBase, role: base?.role } base = { ...newBase, role: base?.role }
} catch (e) { } catch (e: any) {
toast.error(e.message) console.error(e)
toast.error(await extractSdkResponseErrorMsg(e))
} }
$e('a:shared-base:recreate') $e('a:shared-base:recreate')

11
packages/nc-gui-v2/components/dashboard/settings/userManagement/UsersModal.vue

@ -20,6 +20,7 @@ interface Props {
show: boolean show: boolean
selectedUser?: User selectedUser?: User
} }
interface Users { interface Users {
emails?: string emails?: string
role: ProjectRole role: ProjectRole
@ -30,7 +31,6 @@ const { project } = useProject()
const { $api, $e } = useNuxtApp() const { $api, $e } = useNuxtApp()
const usersData = $ref<Users>({ emails: undefined, role: ProjectRole.Guest, invitationToken: undefined }) const usersData = $ref<Users>({ emails: undefined, role: ProjectRole.Guest, invitationToken: undefined })
const inviteToken = $ref(null)
const formRef = ref() const formRef = ref()
const useForm = Form.useForm const useForm = Form.useForm
@ -89,13 +89,16 @@ const saveUser = async () => {
usersData.invitationToken = res.invite_token usersData.invitationToken = res.invite_token
} }
toast.success('Successfully updated the user details') toast.success('Successfully updated the user details')
} catch (e) { } catch (e: any) {
console.error(e)
toast.error(await extractSdkResponseErrorMsg(e)) toast.error(await extractSdkResponseErrorMsg(e))
} }
} }
const inviteUrl = $computed(() => const inviteUrl = $computed(() =>
inviteToken ? `${location.origin}${location.pathname}#/user/authentication/signup/${inviteToken}` : null, usersData.invitationToken
? `${location.origin}${location.pathname}#/user/authentication/signup/${usersData.invitationToken}`
: null,
) )
const copyUrl = async () => { const copyUrl = async () => {
@ -139,7 +142,7 @@ const clickInviteMore = () => {
<template #message> <template #message>
<div class="flex flex-row w-full justify-between items-center"> <div class="flex flex-row w-full justify-between items-center">
<div class="flex pl-2 text-green-700"> <div class="flex pl-2 text-green-700">
{{ inviteUrl }} http://localhost:3001/nc/p_60c3wrrzv563zq#/nc/base/2d6f72d7-b16a-40f2-951c-00b1b90f3920 {{ inviteUrl }}
</div> </div>
<a-button type="text" class="!rounded-md mr-1" @click="copyUrl"> <a-button type="text" class="!rounded-md mr-1" @click="copyUrl">
<template #icon> <template #icon>

Loading…
Cancel
Save