|
|
@ -14,9 +14,10 @@ const isDivFocused = ref(false) |
|
|
|
const divRef = ref<HTMLDivElement>() |
|
|
|
const divRef = ref<HTMLDivElement>() |
|
|
|
|
|
|
|
|
|
|
|
const emailValidation = reactive({ |
|
|
|
const emailValidation = reactive({ |
|
|
|
isError: false, |
|
|
|
isError: true, |
|
|
|
message: '', |
|
|
|
message: '', |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
const singleEmailValue = ref('') |
|
|
|
|
|
|
|
|
|
|
|
const workspaceStore = useWorkspace() |
|
|
|
const workspaceStore = useWorkspace() |
|
|
|
|
|
|
|
|
|
|
@ -54,7 +55,28 @@ const emailInputValidation = (input: string): boolean => { |
|
|
|
return true |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const isInvitButtonDiabled = computed(() => { |
|
|
|
|
|
|
|
if (!emailBadges.value.length && !singleEmailValue.value.length) { |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (emailBadges.value.length && inviteData.email) { |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
watch(inviteData, (newVal) => { |
|
|
|
watch(inviteData, (newVal) => { |
|
|
|
|
|
|
|
// when user only want to enter a single email |
|
|
|
|
|
|
|
// we dont convert that as badge |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const isSingleEmailValid = validateEmail(newVal.email) |
|
|
|
|
|
|
|
if (isSingleEmailValid && !emailBadges.value.length) { |
|
|
|
|
|
|
|
singleEmailValue.value = newVal.email |
|
|
|
|
|
|
|
emailValidation.isError = false |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
singleEmailValue.value = '' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// when user enters multiple emails comma sepearted or space sepearted |
|
|
|
const isNewEmail = newVal.email.charAt(newVal.email.length - 1) === ',' || newVal.email.charAt(newVal.email.length - 1) === ' ' |
|
|
|
const isNewEmail = newVal.email.charAt(newVal.email.length - 1) === ',' || newVal.email.charAt(newVal.email.length - 1) === ' ' |
|
|
|
if (isNewEmail && newVal.email.trim().length) { |
|
|
|
if (isNewEmail && newVal.email.trim().length) { |
|
|
|
const emailToAdd = newVal.email.split(',')[0].trim() || newVal.email.split(' ')[0].trim() |
|
|
|
const emailToAdd = newVal.email.split(',')[0].trim() || newVal.email.split(' ')[0].trim() |
|
|
@ -74,6 +96,7 @@ watch(inviteData, (newVal) => { |
|
|
|
} |
|
|
|
} |
|
|
|
emailBadges.value.push(emailToAdd) |
|
|
|
emailBadges.value.push(emailToAdd) |
|
|
|
inviteData.email = '' |
|
|
|
inviteData.email = '' |
|
|
|
|
|
|
|
singleEmailValue.value = '' |
|
|
|
} |
|
|
|
} |
|
|
|
if (!newVal.email.length && emailValidation.isError) { |
|
|
|
if (!newVal.email.length && emailValidation.isError) { |
|
|
|
emailValidation.isError = false |
|
|
|
emailValidation.isError = false |
|
|
@ -91,7 +114,14 @@ const handleEnter = () => { |
|
|
|
|
|
|
|
|
|
|
|
const inviteCollaborator = async () => { |
|
|
|
const inviteCollaborator = async () => { |
|
|
|
try { |
|
|
|
try { |
|
|
|
const payloadData = emailBadges.value.join(',') |
|
|
|
const payloadData = singleEmailValue.value || emailBadges.value.join(',') |
|
|
|
|
|
|
|
if (!payloadData.includes(',')) { |
|
|
|
|
|
|
|
const validationStatus = validateEmail(payloadData) |
|
|
|
|
|
|
|
if (!validationStatus) { |
|
|
|
|
|
|
|
emailValidation.isError = true |
|
|
|
|
|
|
|
emailValidation.message = 'invalid email' |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
await _inviteCollaborator(payloadData, inviteData.roles) |
|
|
|
await _inviteCollaborator(payloadData, inviteData.roles) |
|
|
|
message.success('Invitation sent successfully') |
|
|
|
message.success('Invitation sent successfully') |
|
|
@ -99,6 +129,8 @@ const inviteCollaborator = async () => { |
|
|
|
emailBadges.value = [] |
|
|
|
emailBadges.value = [] |
|
|
|
} catch (e: any) { |
|
|
|
} catch (e: any) { |
|
|
|
message.error(await extractSdkResponseErrorMsg(e)) |
|
|
|
message.error(await extractSdkResponseErrorMsg(e)) |
|
|
|
|
|
|
|
} finally { |
|
|
|
|
|
|
|
singleEmailValue.value = '' |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
// allow only lower roles to be assigned |
|
|
|
// allow only lower roles to be assigned |
|
|
@ -194,7 +226,7 @@ const onPaste = (e: ClipboardEvent) => { |
|
|
|
ref="focusRef" |
|
|
|
ref="focusRef" |
|
|
|
v-model="inviteData.email" |
|
|
|
v-model="inviteData.email" |
|
|
|
:placeholder="emailBadges.length < 1 ? 'Enter emails to send invitation' : ''" |
|
|
|
:placeholder="emailBadges.length < 1 ? 'Enter emails to send invitation' : ''" |
|
|
|
class="min-w-50 outline-0 ml-2 mr-3" |
|
|
|
class="min-w-60 outline-0 ml-2 mr-3 flex-grow-1" |
|
|
|
data-testid="email-input" |
|
|
|
data-testid="email-input" |
|
|
|
@keyup.enter="handleEnter" |
|
|
|
@keyup.enter="handleEnter" |
|
|
|
@blur="isDivFocused = false" |
|
|
|
@blur="isDivFocused = false" |
|
|
@ -215,7 +247,7 @@ const onPaste = (e: ClipboardEvent) => { |
|
|
|
<NcButton |
|
|
|
<NcButton |
|
|
|
type="primary" |
|
|
|
type="primary" |
|
|
|
size="small" |
|
|
|
size="small" |
|
|
|
:disabled="!emailBadges.length || isInvitingCollaborators || emailValidation.isError" |
|
|
|
:disabled="isInvitButtonDiabled || isInvitingCollaborators || emailValidation.isError" |
|
|
|
:loading="isInvitingCollaborators" |
|
|
|
:loading="isInvitingCollaborators" |
|
|
|
@click="inviteCollaborator" |
|
|
|
@click="inviteCollaborator" |
|
|
|
> |
|
|
|
> |
|
|
|