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 {
Form,
computed,
emailValidator,
extractSdkResponseErrorMsg,
message,
ref,
@ -11,7 +12,6 @@ import {
useDashboard,
useI18n,
useNuxtApp,
validateEmail,
} from '#imports'
import type { User } from '~/lib'
import { Role } from '~/lib'
@ -44,24 +44,10 @@ const usersData = $ref<Users>({ emails: '', role: Role.OrgLevelViewer, invitatio
const formRef = ref()
const useForm = Form.useForm
const validators = computed(() => {
return {
emails: [
{
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()
}
},
},
],
emails: [emailValidator],
}
})

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

@ -9,6 +9,7 @@ import {
ReloadViewDataHookInj,
computed,
createEventHook,
emailValidator,
extractSdkResponseErrorMsg,
inject,
message,
@ -23,7 +24,6 @@ import {
useUIPermission,
useViewColumns,
useViewData,
validateEmail,
watch,
} from '#imports'
import type { Permission } from '~/lib'
@ -103,22 +103,7 @@ const { t } = useI18n()
const { betaFeatureToggleState } = useBetaFeatureToggle()
const formRules = {
email: [
{
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()
}
},
},
],
email: [emailValidator],
}
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 {
Form,
computed,
emailValidator,
extractSdkResponseErrorMsg,
message,
onMounted,
@ -17,7 +18,6 @@ import {
useI18n,
useNuxtApp,
useProject,
validateEmail,
} from '#imports'
import type { User } from '~/lib'
import { ProjectRole } from '~/lib'
@ -54,24 +54,10 @@ let usersData = $ref<Users>({ emails: undefined, role: ProjectRole.Viewer, invit
const formRef = ref()
const useForm = Form.useForm
const validators = computed(() => {
return {
emails: [
{
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()
}
},
},
],
emails: [emailValidator],
}
})

Loading…
Cancel
Save