update
This commit is contained in:
@@ -1,18 +1,11 @@
|
||||
import type { Route } from './+types/route'
|
||||
|
||||
import { isValidCPF } from '@brazilian-utils/brazilian-utils'
|
||||
import { useEffect } from 'react'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { PatternFormat } from 'react-number-format'
|
||||
import { Link, useFetcher } from 'react-router'
|
||||
import { toast } from 'sonner'
|
||||
import {
|
||||
adjectives,
|
||||
colors,
|
||||
NumberDictionary,
|
||||
uniqueNamesGenerator
|
||||
} from 'unique-names-generator'
|
||||
import { z } from 'zod'
|
||||
|
||||
import {
|
||||
Breadcrumb,
|
||||
@@ -44,54 +37,7 @@ import { Spinner } from '@repo/ui/components/ui/spinner'
|
||||
|
||||
import { useWorksapce } from '@/components/workspace-switcher'
|
||||
import { HttpMethod, request as req } from '@repo/util/request'
|
||||
import { useEffect } from 'react'
|
||||
|
||||
const isName = (name: string) => name && name.includes(' ')
|
||||
|
||||
function randomEmail() {
|
||||
const numberDict = NumberDictionary.generate({ min: 100, max: 999 })
|
||||
const randomName: string = uniqueNamesGenerator({
|
||||
dictionaries: [adjectives, colors, numberDict],
|
||||
length: 3,
|
||||
separator: '-'
|
||||
})
|
||||
|
||||
return `${randomName}@users.noreply.saladeaula.digital`
|
||||
}
|
||||
|
||||
export const formSchema = z
|
||||
.object({
|
||||
name: z
|
||||
.string()
|
||||
.trim()
|
||||
.nonempty('Digite um nome')
|
||||
.refine(isName, { message: 'Nome inválido' }),
|
||||
email: z.string().trim().toLowerCase().optional(),
|
||||
cpf: z
|
||||
.string('CPF obrigatório')
|
||||
.refine(isValidCPF, { message: 'CPF inválido' }),
|
||||
given_email: z.coerce.boolean()
|
||||
})
|
||||
.refine(
|
||||
({ given_email, email }) => {
|
||||
if (given_email) {
|
||||
return true
|
||||
}
|
||||
return email && z.email().safeParse(email).success
|
||||
},
|
||||
{
|
||||
message: 'Email inválido',
|
||||
path: ['email']
|
||||
}
|
||||
)
|
||||
.transform((data) => {
|
||||
if (data.given_email) {
|
||||
return { ...data, email: randomEmail() }
|
||||
}
|
||||
return data
|
||||
})
|
||||
|
||||
export type Schema = z.infer<typeof formSchema>
|
||||
import { formSchema, type Schema } from './data'
|
||||
|
||||
export function meta({}: Route.MetaArgs) {
|
||||
return [{ title: 'Adicionar colaborador' }]
|
||||
|
||||
Reference in New Issue
Block a user