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.
276 lines
9.0 KiB
276 lines
9.0 KiB
3 years ago
|
<template>
|
||
3 years ago
|
<v-dialog
|
||
|
v-model="userEditDialog"
|
||
|
:width="invite_token ? 700 : 700"
|
||
3 years ago
|
transition="dialog-top-transition"
|
||
3 years ago
|
@close="invite_token = null"
|
||
|
>
|
||
3 years ago
|
<v-card v-if="selectedUser" style="min-height: 100%" class="elevation-0">
|
||
|
<v-card-title>
|
||
3 years ago
|
{{ $t('activity.share') }} :
|
||
|
{{ $store.getters['project/GtrProjectName'] }}
|
||
3 years ago
|
|
||
|
<div class="nc-header-border" />
|
||
|
</v-card-title>
|
||
|
|
||
|
<v-card-text>
|
||
|
<div>
|
||
3 years ago
|
<v-icon small> mdi-account-outline </v-icon>
|
||
|
<template v-if="invite_token"> Copy Invite Token </template>
|
||
|
<template v-else-if="selectedUser.id"> Edit User </template>
|
||
3 years ago
|
<template v-else>
|
||
|
<!-- Invite Team -->
|
||
3 years ago
|
{{ $t('activity.inviteTeam') }}
|
||
3 years ago
|
</template>
|
||
|
</div>
|
||
|
<div class="pa-4 nc-invite-container">
|
||
3 years ago
|
<div v-if="invite_token" class="mt-6 align-center">
|
||
3 years ago
|
<v-alert
|
||
|
v-ripple
|
||
|
type="success"
|
||
|
outlined
|
||
|
class="pointer"
|
||
3 years ago
|
@click="
|
||
|
clipboard(inviteUrl);
|
||
|
$toast.success('Copied invite url to clipboard').goAway(3000);
|
||
|
"
|
||
3 years ago
|
>
|
||
|
<template #append>
|
||
3 years ago
|
<v-icon color="green" class="ml-2"> mdi-content-copy </v-icon>
|
||
3 years ago
|
</template>
|
||
|
<div class="ellipsis d-100">
|
||
|
{{ inviteUrl }}
|
||
|
</div>
|
||
|
</v-alert>
|
||
|
|
||
|
<p class="caption grey--text mt-3">
|
||
3 years ago
|
<!-- Looks like you have not configured mailer yet! <br> Please copy above invite link and send it to -->
|
||
3 years ago
|
{{ $t('msg.info.userInviteNoSMTP') }}
|
||
|
{{ invite_token && (invite_token.email || (invite_token.emails && invite_token.emails.join(', '))) }}.
|
||
3 years ago
|
</p>
|
||
|
|
||
|
<div class="text-right">
|
||
|
<!--tooltip="Invite more users"-->
|
||
3 years ago
|
<x-btn :tooltip="$t('tooltip.inviteMore')" small outlined btn.class="grey--text" @click="clickInviteMore">
|
||
|
<v-icon small color="grey" class="mr-1"> mdi-account-multiple-plus-outline </v-icon>
|
||
3 years ago
|
<!--Invite more-->
|
||
3 years ago
|
{{ $t('activity.inviteMore') }}
|
||
3 years ago
|
</x-btn>
|
||
|
</div>
|
||
|
|
||
|
<!-- todo: show error message if failed-->
|
||
|
</div>
|
||
|
<template v-else>
|
||
|
<v-form ref="form" v-model="valid" @submit.prevent="saveUser">
|
||
|
<v-row class="my-0">
|
||
|
<v-col cols="8" class="py-0">
|
||
|
<!--hint="You can add multiple comma(,) separated emails"-->
|
||
|
<v-text-field
|
||
|
ref="email"
|
||
|
v-model="selectedUser.email"
|
||
|
:disabled="!!selectedUser.id"
|
||
|
dense
|
||
|
validate-on-blur
|
||
|
outlined
|
||
|
:rules="emailRules"
|
||
|
class="caption"
|
||
|
:hint="$t('msg.info.addMultipleUsers')"
|
||
|
label="Email"
|
||
3 years ago
|
@input="edited = true"
|
||
3 years ago
|
>
|
||
|
<template #label>
|
||
|
<span class="caption">
|
||
|
<!-- Email -->
|
||
3 years ago
|
{{ $t('labels.email') }}
|
||
3 years ago
|
</span>
|
||
|
</template>
|
||
|
</v-text-field>
|
||
|
</v-col>
|
||
|
<v-col cols="4" class="py-0">
|
||
|
<!--label="Select User Role"-->
|
||
|
<v-combobox
|
||
|
v-model="selectedRoles"
|
||
|
outlined
|
||
|
:rules="roleRules"
|
||
|
class="role-select caption"
|
||
|
hide-details="auto"
|
||
|
:items="roles"
|
||
|
:label="$t('labels.selectUserRole')"
|
||
|
dense
|
||
|
deletable-chips
|
||
|
@change="edited = true"
|
||
|
>
|
||
3 years ago
|
<template #selection="{ item }">
|
||
3 years ago
|
<v-chip small :color="rolesColors[item]">
|
||
|
{{ item }}
|
||
|
</v-chip>
|
||
|
</template>
|
||
3 years ago
|
<template #item="{ item }">
|
||
3 years ago
|
<div>
|
||
|
<div>{{ item }}</div>
|
||
|
<div class="mb-2 caption grey--text">
|
||
|
{{ roleDescriptions[item] }}
|
||
|
</div>
|
||
|
</div>
|
||
|
</template>
|
||
|
</v-combobox>
|
||
|
</v-col>
|
||
|
</v-row>
|
||
|
</v-form>
|
||
|
<div class="text-center mt-0">
|
||
|
<x-btn
|
||
3 years ago
|
v-ge="['rows', 'save']"
|
||
3 years ago
|
:tooltip="$t('tooltip.saveChanges')"
|
||
|
color="primary"
|
||
|
btn.class="nc-invite-or-save-btn"
|
||
|
@click="saveUser"
|
||
|
>
|
||
|
<v-icon small left>
|
||
3 years ago
|
{{ selectedUser.id ? 'save' : 'mdi-send' }}
|
||
3 years ago
|
</v-icon>
|
||
3 years ago
|
{{ selectedUser.id ? $t('general.save') : $t('activity.invite') }}
|
||
3 years ago
|
</x-btn>
|
||
|
</div>
|
||
|
</template>
|
||
|
<!-- </v-card-actions>-->
|
||
|
</div>
|
||
|
</v-card-text>
|
||
|
<v-card-text>
|
||
|
<share-base />
|
||
|
</v-card-text>
|
||
|
</v-card>
|
||
|
</v-dialog>
|
||
|
</template>
|
||
|
|
||
|
<script>
|
||
3 years ago
|
import { isEmail } from '~/helpers';
|
||
|
import { enumColor } from '~/components/project/spreadsheet/helpers/colors';
|
||
|
import ShareBase from '~/components/base/ShareBase';
|
||
3 years ago
|
|
||
|
export default {
|
||
3 years ago
|
name: 'ShareOrInviteModal',
|
||
3 years ago
|
components: { ShareBase },
|
||
|
props: {
|
||
3 years ago
|
value: Boolean,
|
||
3 years ago
|
},
|
||
|
data: () => ({
|
||
3 years ago
|
roles: ['creator', 'editor', 'commenter', 'viewer'],
|
||
3 years ago
|
selectedUser: {},
|
||
|
invite_token: null,
|
||
|
valid: null,
|
||
|
emailRules: [
|
||
3 years ago
|
v => !!v || 'E-mail is required',
|
||
3 years ago
|
v => {
|
||
|
const invalidEmails = (v || '').split(/\s*,\s*/).filter(e => !isEmail(e));
|
||
|
return !invalidEmails.length || `"${invalidEmails.join(', ')}" - invalid email`;
|
||
|
},
|
||
3 years ago
|
],
|
||
|
roleRules: [
|
||
3 years ago
|
v => !!v || 'User Role is required',
|
||
3 years ago
|
v => ['creator', 'editor', 'commenter', 'viewer'].includes(v) || 'invalid user role',
|
||
3 years ago
|
],
|
||
|
userList: [],
|
||
|
roleDescriptions: {},
|
||
3 years ago
|
deleteUserType: '',
|
||
3 years ago
|
}),
|
||
|
computed: {
|
||
|
userEditDialog: {
|
||
|
get() {
|
||
3 years ago
|
return this.value;
|
||
3 years ago
|
},
|
||
|
set(v) {
|
||
3 years ago
|
this.$emit('input', v);
|
||
|
},
|
||
3 years ago
|
},
|
||
|
inviteUrl() {
|
||
3 years ago
|
return this.invite_token
|
||
|
? `${location.origin}${location.pathname}#/user/authentication/signup/${this.invite_token.invite_token}`
|
||
3 years ago
|
: null;
|
||
3 years ago
|
},
|
||
|
rolesColors() {
|
||
3 years ago
|
const colors = this.$store.state.settings.darkTheme ? enumColor.dark : enumColor.light;
|
||
3 years ago
|
return ['owner'].concat(this.roles).reduce((o, r, i) => {
|
||
3 years ago
|
o[r] = colors[i % colors.length];
|
||
|
return o;
|
||
|
}, {});
|
||
3 years ago
|
},
|
||
|
|
||
|
selectedRoles: {
|
||
|
get() {
|
||
3 years ago
|
return (this.selectedUser && this.selectedUser.roles ? this.selectedUser.roles.split(',') : []).sort(
|
||
3 years ago
|
(a, b) => this.roleNames.indexOf(a) - this.roleNames.indexOf(a)
|
||
3 years ago
|
)[0];
|
||
3 years ago
|
},
|
||
|
set(roles) {
|
||
|
if (this.selectedUser) {
|
||
3 years ago
|
this.selectedUser.roles = roles; // .filter(Boolean).join(',')
|
||
3 years ago
|
}
|
||
3 years ago
|
},
|
||
|
},
|
||
3 years ago
|
},
|
||
|
methods: {
|
||
|
async saveUser() {
|
||
3 years ago
|
this.validate = true;
|
||
|
await this.$nextTick();
|
||
3 years ago
|
if (this.loading || !this.$refs.form.validate() || !this.selectedUser) {
|
||
3 years ago
|
return;
|
||
3 years ago
|
}
|
||
3 years ago
|
this.$e('a:user:invite', { role: this.selectedUser.roles });
|
||
3 years ago
|
|
||
|
if (!this.edited) {
|
||
3 years ago
|
this.userEditDialog = false;
|
||
3 years ago
|
}
|
||
|
|
||
|
try {
|
||
3 years ago
|
let data;
|
||
3 years ago
|
if (this.selectedUser.id) {
|
||
3 years ago
|
await this.$api.auth.projectUserUpdate(this.$route.params.project_id, this.selectedUser.id, {
|
||
|
roles: this.selectedUser.roles,
|
||
|
email: this.selectedUser.email,
|
||
|
project_id: this.$route.params.project_id,
|
||
|
projectName: this.$store.getters['project/GtrProjectName'],
|
||
|
});
|
||
3 years ago
|
} else {
|
||
3 years ago
|
data = await this.$api.auth.projectUserAdd(this.$route.params.project_id, {
|
||
|
...this.selectedUser,
|
||
|
project_id: this.$route.params.project_id,
|
||
|
projectName: this.$store.getters['project/GtrProjectName'],
|
||
|
});
|
||
3 years ago
|
}
|
||
3 years ago
|
this.$toast.success('Successfully updated the user details').goAway(3000);
|
||
|
this.$emit('saved');
|
||
3 years ago
|
if (data && data.invite_token) {
|
||
3 years ago
|
this.invite_token = data;
|
||
3 years ago
|
// todo: bring anim
|
||
|
// this.simpleAnim()
|
||
3 years ago
|
return;
|
||
3 years ago
|
}
|
||
|
} catch (e) {
|
||
3 years ago
|
this.$toast.error(await this._extractSdkResponseErrorMsg(e)).goAway(3000);
|
||
3 years ago
|
}
|
||
|
|
||
3 years ago
|
this.userEditDialog = false;
|
||
3 years ago
|
},
|
||
|
|
||
|
clickInviteMore() {
|
||
3 years ago
|
this.$e('c:user:invite-more');
|
||
|
this.invite_token = null;
|
||
|
this.selectedUser = { roles: 'editor' };
|
||
3 years ago
|
},
|
||
|
clipboard(str) {
|
||
3 years ago
|
const el = document.createElement('textarea');
|
||
|
el.addEventListener('focusin', e => e.stopPropagation());
|
||
|
el.value = str;
|
||
|
document.body.appendChild(el);
|
||
|
el.select();
|
||
|
document.execCommand('copy');
|
||
|
document.body.removeChild(el);
|
||
3 years ago
|
|
||
3 years ago
|
this.$e('c:user:copy-url');
|
||
|
},
|
||
|
},
|
||
|
};
|
||
3 years ago
|
</script>
|
||
|
|
||
3 years ago
|
<style scoped></style>
|