mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
250 lines
8.5 KiB
250 lines
8.5 KiB
2 years ago
|
<script setup lang="ts">
|
||
2 years ago
|
import { Form, message } from 'ant-design-vue'
|
||
2 years ago
|
import { useI18n } from 'vue-i18n'
|
||
2 years ago
|
import ShareBase from './ShareBase.vue'
|
||
2 years ago
|
import {
|
||
|
computed,
|
||
|
extractSdkResponseErrorMsg,
|
||
|
isEmail,
|
||
|
onMounted,
|
||
|
projectRoles,
|
||
|
ref,
|
||
|
useClipboard,
|
||
|
useDashboard,
|
||
|
useNuxtApp,
|
||
|
useProject,
|
||
|
} from '#imports'
|
||
|
import type { User } from '~/lib'
|
||
|
import { ProjectRole } from '~/lib'
|
||
2 years ago
|
|
||
2 years ago
|
const { show, selectedUser } = defineProps<Props>()
|
||
|
|
||
|
const emit = defineEmits(['closed', 'reload'])
|
||
|
|
||
|
const { t } = useI18n()
|
||
|
|
||
2 years ago
|
interface Props {
|
||
|
show: boolean
|
||
|
selectedUser?: User
|
||
|
}
|
||
2 years ago
|
|
||
2 years ago
|
interface Users {
|
||
2 years ago
|
emails?: string
|
||
2 years ago
|
role: ProjectRole
|
||
|
invitationToken?: string
|
||
|
}
|
||
|
|
||
|
const { project } = useProject()
|
||
|
const { $api, $e } = useNuxtApp()
|
||
2 years ago
|
const { copy } = useClipboard()
|
||
2 years ago
|
const { dashboardUrl } = $(useDashboard())
|
||
2 years ago
|
|
||
2 years ago
|
const usersData = $ref<Users>({ emails: undefined, role: ProjectRole.Viewer, invitationToken: undefined })
|
||
2 years ago
|
const formRef = ref()
|
||
|
|
||
|
const useForm = Form.useForm
|
||
|
const validators = computed(() => {
|
||
|
return {
|
||
|
emails: [
|
||
|
{
|
||
|
validator: (rule: any, value: string, callback: (errMsg?: string) => void) => {
|
||
2 years ago
|
if (!value || value.length === 0) {
|
||
2 years ago
|
callback('Email is required')
|
||
|
return
|
||
|
}
|
||
|
const invalidEmails = (value || '').split(/\s*,\s*/).filter((e: string) => !isEmail(e))
|
||
|
if (invalidEmails.length > 0) {
|
||
|
callback(`${invalidEmails.length > 1 ? ' Invalid emails:' : 'Invalid email:'} ${invalidEmails.join(', ')} `)
|
||
|
} else {
|
||
|
callback()
|
||
|
}
|
||
|
},
|
||
|
},
|
||
|
],
|
||
|
}
|
||
|
})
|
||
|
|
||
|
const { validateInfos } = useForm(usersData, validators)
|
||
|
|
||
|
onMounted(() => {
|
||
2 years ago
|
if (!usersData.emails && selectedUser?.email) {
|
||
2 years ago
|
usersData.emails = selectedUser.email
|
||
|
usersData.role = selectedUser.roles
|
||
|
}
|
||
|
})
|
||
|
|
||
|
const saveUser = async () => {
|
||
|
$e('a:user:invite', { role: usersData.role })
|
||
|
|
||
|
if (!project.value.id) return
|
||
|
|
||
|
await formRef.value?.validateFields()
|
||
|
|
||
|
try {
|
||
|
if (selectedUser?.id) {
|
||
|
await $api.auth.projectUserUpdate(project.value.id, selectedUser.id, {
|
||
2 years ago
|
roles: usersData.role,
|
||
2 years ago
|
email: selectedUser.email,
|
||
|
project_id: project.value.id,
|
||
|
projectName: project.value.title,
|
||
|
})
|
||
2 years ago
|
emit('closed')
|
||
2 years ago
|
} else {
|
||
|
const res = await $api.auth.projectUserAdd(project.value.id, {
|
||
|
roles: usersData.role,
|
||
|
email: usersData.emails,
|
||
|
project_id: project.value.id,
|
||
|
projectName: project.value.title,
|
||
|
})
|
||
|
usersData.invitationToken = res.invite_token
|
||
|
}
|
||
2 years ago
|
emit('reload')
|
||
2 years ago
|
|
||
|
// Successfully updated the user details
|
||
|
message.success(t('msg.success.userDetailsUpdated'))
|
||
2 years ago
|
} catch (e: any) {
|
||
|
console.error(e)
|
||
2 years ago
|
message.error(await extractSdkResponseErrorMsg(e))
|
||
2 years ago
|
}
|
||
|
}
|
||
|
|
||
2 years ago
|
const inviteUrl = $computed(() => (usersData.invitationToken ? `${dashboardUrl}#/signup/${usersData.invitationToken}` : null))
|
||
2 years ago
|
|
||
|
const copyUrl = async () => {
|
||
|
if (!inviteUrl) return
|
||
|
|
||
2 years ago
|
await copy(inviteUrl)
|
||
|
|
||
2 years ago
|
// Copied shareable base url to clipboard!
|
||
|
message.success(t('msg.success.shareableURLCopied'))
|
||
2 years ago
|
|
||
|
$e('c:shared-base:copy-url')
|
||
|
}
|
||
|
|
||
|
const clickInviteMore = () => {
|
||
|
$e('c:user:invite-more')
|
||
|
usersData.invitationToken = undefined
|
||
2 years ago
|
usersData.role = ProjectRole.Viewer
|
||
2 years ago
|
usersData.emails = undefined
|
||
2 years ago
|
}
|
||
|
</script>
|
||
|
|
||
|
<template>
|
||
2 years ago
|
<a-modal :footer="null" centered :visible="show" :closable="false" width="max(50vw, 44rem)" @cancel="emit('closed')">
|
||
2 years ago
|
<div class="flex flex-col">
|
||
|
<div class="flex flex-row justify-between items-center pb-1.5 mb-2 border-b-1 w-full">
|
||
2 years ago
|
<a-typography-title class="select-none" :level="4"> {{ $t('activity.share') }}: {{ project.title }} </a-typography-title>
|
||
2 years ago
|
<a-button type="text" class="!rounded-md mr-1 -mt-1.5" @click="emit('closed')">
|
||
2 years ago
|
<template #icon>
|
||
2 years ago
|
<MaterialSymbolsCloseRounded class="flex mx-auto" />
|
||
2 years ago
|
</template>
|
||
|
</a-button>
|
||
|
</div>
|
||
|
|
||
2 years ago
|
<div class="px-2 mt-1.5">
|
||
2 years ago
|
<template v-if="usersData.invitationToken">
|
||
|
<div class="flex flex-col mt-1 border-b-1 pb-5">
|
||
2 years ago
|
<div class="flex flex-row items-center pl-1.5 pb-1 h-[1.1rem]">
|
||
2 years ago
|
<MdiAccountOutline />
|
||
2 years ago
|
<div class="text-xs ml-0.5 mt-0.5">Copy Invite Token</div>
|
||
2 years ago
|
</div>
|
||
|
|
||
|
<a-alert class="mt-1" type="success" show-icon>
|
||
|
<template #message>
|
||
2 years ago
|
<div class="flex flex-row justify-between items-center py-1">
|
||
|
<div class="flex pl-2 text-green-700 text-xs">
|
||
2 years ago
|
{{ inviteUrl }}
|
||
2 years ago
|
</div>
|
||
2 years ago
|
<a-button type="text" class="!rounded-md -mt-0.5" @click="copyUrl">
|
||
2 years ago
|
<template #icon>
|
||
2 years ago
|
<MdiContentCopy class="flex mx-auto text-green-700 h-[1rem]" />
|
||
2 years ago
|
</template>
|
||
|
</a-button>
|
||
|
</div>
|
||
|
</template>
|
||
|
</a-alert>
|
||
2 years ago
|
|
||
2 years ago
|
<div class="flex text-xs text-gray-500 mt-2 justify-start ml-2">
|
||
2 years ago
|
{{ $t('msg.info.userInviteNoSMTP') }}
|
||
2 years ago
|
{{ usersData.invitationToken && usersData.emails }}
|
||
2 years ago
|
</div>
|
||
2 years ago
|
<div class="flex flex-row justify-start mt-4 ml-2">
|
||
2 years ago
|
<a-button size="small" outlined @click="clickInviteMore">
|
||
|
<div class="flex flex-row justify-center items-center space-x-0.5">
|
||
2 years ago
|
<MaterialSymbolsSendOutline class="flex mx-auto text-gray-600 h-[0.8rem]" />
|
||
2 years ago
|
<div class="text-xs text-gray-600">{{ $t('activity.inviteMore') }}</div>
|
||
2 years ago
|
</div>
|
||
|
</a-button>
|
||
|
</div>
|
||
|
</div>
|
||
|
</template>
|
||
|
<div v-else class="flex flex-col pb-4">
|
||
2 years ago
|
<div class="flex flex-row items-center pl-2 pb-1 h-[1rem]">
|
||
2 years ago
|
<MdiAccountOutline />
|
||
2 years ago
|
<div class="text-xs ml-0.5 mt-0.5">{{ selectedUser ? $t('activity.editUser') : $t('activity.inviteTeam') }}</div>
|
||
2 years ago
|
</div>
|
||
|
<div class="border-1 py-3 px-4 rounded-md mt-1">
|
||
2 years ago
|
<a-form
|
||
|
ref="formRef"
|
||
|
:validate-on-rule-change="false"
|
||
|
:model="usersData"
|
||
|
validate-trigger="onBlur"
|
||
|
@finish="saveUser"
|
||
|
>
|
||
2 years ago
|
<div class="flex flex-row space-x-4">
|
||
|
<div class="flex flex-col w-3/4">
|
||
|
<a-form-item
|
||
|
v-bind="validateInfos.emails"
|
||
2 years ago
|
validate-trigger="onBlur"
|
||
2 years ago
|
name="emails"
|
||
|
:rules="[{ required: true, message: 'Please input email' }]"
|
||
|
>
|
||
2 years ago
|
<div class="ml-1 mb-1 text-xs text-gray-500">{{ $t('datatype.Email') }}:</div>
|
||
2 years ago
|
<a-input
|
||
|
v-model:value="usersData.emails"
|
||
|
validate-trigger="onBlur"
|
||
2 years ago
|
:placeholder="$t('labels.email')"
|
||
2 years ago
|
:disabled="!!selectedUser"
|
||
|
/>
|
||
2 years ago
|
</a-form-item>
|
||
|
</div>
|
||
|
<div class="flex flex-col w-1/4">
|
||
|
<a-form-item name="role" :rules="[{ required: true, message: 'Role required' }]">
|
||
2 years ago
|
<div class="ml-1 mb-1 text-xs text-gray-500">{{ $t('labels.selectUserRole') }}</div>
|
||
2 years ago
|
<a-select v-model:value="usersData.role" class="nc-user-roles">
|
||
|
<a-select-option v-for="(role, index) in projectRoles" :key="index" :value="role" class="nc-role-option">
|
||
2 years ago
|
<div class="flex flex-row h-full justify-start items-center">
|
||
2 years ago
|
<div
|
||
|
class="px-2 py-1 flex rounded-full text-xs"
|
||
|
:style="{ backgroundColor: projectRoleTagColors[role] }"
|
||
|
>
|
||
2 years ago
|
{{ role }}
|
||
|
</div>
|
||
|
</div>
|
||
|
</a-select-option>
|
||
|
</a-select>
|
||
|
</a-form-item>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="flex flex-row justify-center">
|
||
2 years ago
|
<a-button type="primary" html-type="submit">
|
||
2 years ago
|
<div v-if="selectedUser">{{ $t('general.save') }}</div>
|
||
2 years ago
|
<div v-else class="flex flex-row justify-center items-center space-x-1.5">
|
||
2 years ago
|
<MaterialSymbolsSendOutline class="flex h-[0.8rem]" />
|
||
2 years ago
|
<div>{{ $t('activity.invite') }}</div>
|
||
2 years ago
|
</div>
|
||
|
</a-button>
|
||
2 years ago
|
</div>
|
||
|
</a-form>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="flex mt-4">
|
||
|
<ShareBase />
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
</a-modal>
|
||
|
</template>
|
||
|
|
||
|
<style scoped></style>
|