Browse Source

refactor(nc-gui): use emailValidator

pull/5328/head
Wing-Kam Wong 2 years ago
parent
commit
72ac86e7d8
  1. 20
      packages/nc-gui/components/account/UsersModal.vue
  2. 19
      packages/nc-gui/components/smartsheet/Form.vue
  3. 20
      packages/nc-gui/components/tabs/auth/user-management/UsersModal.vue

20
packages/nc-gui/components/account/UsersModal.vue

@ -4,6 +4,7 @@ import type { OrgUserReqType } from 'nocodb-sdk'
import { import {
Form, Form,
computed, computed,
emailValidator,
extractSdkResponseErrorMsg, extractSdkResponseErrorMsg,
message, message,
ref, ref,
@ -11,7 +12,6 @@ import {
useDashboard, useDashboard,
useI18n, useI18n,
useNuxtApp, useNuxtApp,
validateEmail,
} from '#imports' } from '#imports'
import type { User } from '~/lib' import type { User } from '~/lib'
import { Role } from '~/lib' import { Role } from '~/lib'
@ -44,24 +44,10 @@ const usersData = $ref<Users>({ emails: '', role: Role.OrgLevelViewer, invitatio
const formRef = ref() const formRef = ref()
const useForm = Form.useForm const useForm = Form.useForm
const validators = computed(() => { const validators = computed(() => {
return { return {
emails: [ emails: [emailValidator],
{
validator: (rule: any, value: string, callback: (errMsg?: string) => void) => {
if (!value || value.length === 0) {
callback('Email is required')
return
}
const invalidEmails = (value || '').split(/\s*,\s*/).filter((e: string) => !validateEmail(e))
if (invalidEmails.length > 0) {
callback(`${invalidEmails.length > 1 ? ' Invalid emails:' : 'Invalid email:'} ${invalidEmails.join(', ')} `)
} else {
callback()
}
},
},
],
} }
}) })

19
packages/nc-gui/components/smartsheet/Form.vue

@ -9,6 +9,7 @@ import {
ReloadViewDataHookInj, ReloadViewDataHookInj,
computed, computed,
createEventHook, createEventHook,
emailValidator,
extractSdkResponseErrorMsg, extractSdkResponseErrorMsg,
inject, inject,
message, message,
@ -23,7 +24,6 @@ import {
useUIPermission, useUIPermission,
useViewColumns, useViewColumns,
useViewData, useViewData,
validateEmail,
watch, watch,
} from '#imports' } from '#imports'
import type { Permission } from '~/lib' import type { Permission } from '~/lib'
@ -103,22 +103,7 @@ const { t } = useI18n()
const { betaFeatureToggleState } = useBetaFeatureToggle() const { betaFeatureToggleState } = useBetaFeatureToggle()
const formRules = { const formRules = {
email: [ email: [emailValidator],
{
validator: (rule: any, value: string, callback: (errMsg?: string) => void) => {
if (!value || value.length === 0) {
callback('Email is required')
return
}
const invalidEmails = (value || '').split(/\s*,\s*/).filter((e: string) => !validateEmail(e))
if (invalidEmails.length > 0) {
callback(`${invalidEmails.length > 1 ? ' Invalid emails:' : 'Invalid email:'} ${invalidEmails.join(', ')} `)
} else {
callback()
}
},
},
],
} }
const updateView = useDebounceFn( const updateView = useDebounceFn(

20
packages/nc-gui/components/tabs/auth/user-management/UsersModal.vue

@ -4,6 +4,7 @@ import type { ProjectUserReqType } from 'nocodb-sdk'
import { import {
Form, Form,
computed, computed,
emailValidator,
extractSdkResponseErrorMsg, extractSdkResponseErrorMsg,
message, message,
onMounted, onMounted,
@ -17,7 +18,6 @@ import {
useI18n, useI18n,
useNuxtApp, useNuxtApp,
useProject, useProject,
validateEmail,
} from '#imports' } from '#imports'
import type { User } from '~/lib' import type { User } from '~/lib'
import { ProjectRole } from '~/lib' import { ProjectRole } from '~/lib'
@ -54,24 +54,10 @@ let usersData = $ref<Users>({ emails: undefined, role: ProjectRole.Viewer, invit
const formRef = ref() const formRef = ref()
const useForm = Form.useForm const useForm = Form.useForm
const validators = computed(() => { const validators = computed(() => {
return { return {
emails: [ emails: [emailValidator],
{
validator: (rule: any, value: string, callback: (errMsg?: string) => void) => {
if (!value || value.length === 0) {
callback('Email is required')
return
}
const invalidEmails = (value || '').split(/\s*,\s*/).filter((e: string) => !validateEmail(e))
if (invalidEmails.length > 0) {
callback(`${invalidEmails.length > 1 ? ' Invalid emails:' : 'Invalid email:'} ${invalidEmails.join(', ')} `)
} else {
callback()
}
},
},
],
} }
}) })

Loading…
Cancel
Save