Browse Source

feat: added support for space in email invite

pull/6441/head
sreehari jayaraj 1 year ago
parent
commit
e33cc96a15
  1. 11
      packages/nc-gui/components/project/InviteProjectCollabSection.vue
  2. 18
      packages/nc-gui/components/workspace/InviteSection.vue

11
packages/nc-gui/components/project/InviteProjectCollabSection.vue

@ -26,7 +26,8 @@ const validateEmail = (email: string): boolean => {
// all user input emails are stored here // all user input emails are stored here
const emailBadges = ref<Array<string>>([]) const emailBadges = ref<Array<string>>([])
watch(inviteData, (newVal) => { watch(inviteData, (newVal) => {
if (newVal.email.includes(' ')) { const isNewEmail = newVal.email.includes(' ') || newVal.email.includes(',')
if (isNewEmail) {
if (inviteData.email.length < 1) { if (inviteData.email.length < 1) {
emailValidation.isError = true emailValidation.isError = true
emailValidation.message = 'email should not be empty' emailValidation.message = 'email should not be empty'
@ -39,11 +40,11 @@ watch(inviteData, (newVal) => {
} }
// if email is already enterd we just ignore the input // if email is already enterd we just ignore the input
// no error is thrown // no error is thrown
if (emailBadges.value.includes(newVal.email.split(' ')[0])) { const emailToAdd = newVal.email.split(',')[0].trim() || newVal.email.split(' ')[0].trim()
if (emailBadges.value.includes(emailToAdd)) {
inviteData.email = '' inviteData.email = ''
return return
} }
const emailToAdd = newVal.email.split(' ')[0].trim()
emailBadges.value.push(emailToAdd) emailBadges.value.push(emailToAdd)
inviteData.email = '' inviteData.email = ''
} }
@ -167,7 +168,7 @@ onKeyStroke('Backspace', () => {
// when bulk email is pasted // when bulk email is pasted
const onPaste = (e: ClipboardEvent) => { const onPaste = (e: ClipboardEvent) => {
const pastedText = e.clipboardData?.getData('text') const pastedText = e.clipboardData?.getData('text')
const inputArray = pastedText?.split(' ') const inputArray = pastedText?.split(',') || pastedText?.split(' ')
inputArray?.forEach((el) => { inputArray?.forEach((el) => {
if (el.length < 1) { if (el.length < 1) {
emailValidation.isError = true emailValidation.isError = true
@ -287,7 +288,7 @@ const onPaste = (e: ClipboardEvent) => {
<a-button <a-button
type="primary" type="primary"
class="!rounded-md" class="!rounded-md"
:disabled="!inviteData.email?.length || isInvitingCollaborators" :disabled="!emailBadges.length || isInvitingCollaborators || emailValidation.isErro"
@click="inviteCollaborator" @click="inviteCollaborator"
> >
<div class="flex flex-row items-center gap-x-2 pr-1"> <div class="flex flex-row items-center gap-x-2 pr-1">

18
packages/nc-gui/components/workspace/InviteSection.vue

@ -32,7 +32,8 @@ const { workspaceRoles } = useRoles()
const emailBadges = ref<Array<string>>([]) const emailBadges = ref<Array<string>>([])
watch(inviteData, (newVal) => { watch(inviteData, (newVal) => {
if (newVal.email.includes(' ')) { const isNewEmail = newVal.email.includes(' ') || newVal.email.includes(',')
if (isNewEmail) {
if (newVal.email.length < 1) { if (newVal.email.length < 1) {
emailValidation.isError = true emailValidation.isError = true
emailValidation.message = 'EMAIL SHOULD NOT BE EMPTY' emailValidation.message = 'EMAIL SHOULD NOT BE EMPTY'
@ -45,17 +46,14 @@ watch(inviteData, (newVal) => {
} }
// if email is already enterd we just ignore the input // if email is already enterd we just ignore the input
// no error is thrown // no error is thrown
if (emailBadges.value.includes(inviteData.email.split(' ')[0])) { const emailToAdd = newVal.email.split(',')[0].trim() || newVal.email.split(' ')[0].trim()
inviteData.email = ''
return
}
if (newVal.email.includes(' ')) { if (emailBadges.value.includes(emailToAdd)) {
const emailToAdd = newVal.email.split(' ')[0].trim()
console.log(emailToAdd)
emailBadges.value.push(emailToAdd)
inviteData.email = '' inviteData.email = ''
return
} }
emailBadges.value.push(emailToAdd)
inviteData.email = ''
} }
if (newVal.email.length < 1 && emailValidation.isError) { if (newVal.email.length < 1 && emailValidation.isError) {
emailValidation.isError = false emailValidation.isError = false
@ -129,7 +127,7 @@ onKeyStroke('Backspace', () => {
// when bulk email is pasted // when bulk email is pasted
const onPaste = (e: ClipboardEvent) => { const onPaste = (e: ClipboardEvent) => {
const pastedText = e.clipboardData?.getData('text') const pastedText = e.clipboardData?.getData('text')
const inputArray = pastedText?.split(' ') const inputArray = pastedText?.split(',') || pastedText?.split(' ')
inputArray?.forEach((el) => { inputArray?.forEach((el) => {
if (el.length < 1) { if (el.length < 1) {
emailValidation.isError = true emailValidation.isError = true

Loading…
Cancel
Save