update
This commit is contained in:
@@ -1,11 +1,7 @@
|
||||
import type { Route } from './+types'
|
||||
|
||||
import { useToggle } from 'ahooks'
|
||||
import {
|
||||
EllipsisVerticalIcon,
|
||||
PencilIcon,
|
||||
UserRoundMinusIcon
|
||||
} from 'lucide-react'
|
||||
import { EllipsisIcon, PencilIcon, UserRoundMinusIcon } from 'lucide-react'
|
||||
import { Suspense } from 'react'
|
||||
import { Await, NavLink, useParams, useRevalidator } from 'react-router'
|
||||
import { toast } from 'sonner'
|
||||
@@ -123,7 +119,7 @@ function ActionMenu({ id }: { id: string }) {
|
||||
className="data-[state=open]:bg-muted text-muted-foreground cursor-pointer absolute z-1 right-4 top-4"
|
||||
size="icon-sm"
|
||||
>
|
||||
<EllipsisVerticalIcon />
|
||||
<EllipsisIcon />
|
||||
<span className="sr-only">Abrir menu</span>
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
@@ -185,12 +181,12 @@ function RevokeItem({ id }: { id: string }) {
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter className="*:cursor-pointer">
|
||||
<AlertDialogCancel>Cancelar</AlertDialogCancel>
|
||||
<AlertDialogAction asChild>
|
||||
<Button onClick={revoke} disabled={loading} variant="destructive">
|
||||
{loading ? <Spinner /> : null} Continuar
|
||||
</Button>
|
||||
</AlertDialogAction>
|
||||
<AlertDialogCancel>Cancelar</AlertDialogCancel>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { ComponentProps, MouseEvent } from 'react'
|
||||
import { useRequest, useToggle } from 'ahooks'
|
||||
import {
|
||||
CircleXIcon,
|
||||
EllipsisVerticalIcon,
|
||||
EllipsisIcon,
|
||||
FileBadgeIcon,
|
||||
LockOpenIcon
|
||||
} from 'lucide-react'
|
||||
@@ -99,7 +99,7 @@ function ActionMenu({ row }: { row: any }) {
|
||||
className="data-[state=open]:bg-muted text-muted-foreground cursor-pointer"
|
||||
size="icon-sm"
|
||||
>
|
||||
<EllipsisVerticalIcon />
|
||||
<EllipsisIcon />
|
||||
<span className="sr-only">Abrir menu</span>
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
@@ -238,12 +238,12 @@ function RemoveDedupItem({
|
||||
)}
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter className="*:cursor-pointer">
|
||||
<AlertDialogCancel>Cancelar</AlertDialogCancel>
|
||||
<AlertDialogAction asChild>
|
||||
<Button onClick={cancel} disabled={loading} variant="destructive">
|
||||
{loading ? <Spinner /> : null} Continuar
|
||||
</Button>
|
||||
</AlertDialogAction>
|
||||
<AlertDialogCancel>Cancelar</AlertDialogCancel>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
@@ -305,12 +305,12 @@ function CancelItem({
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter className="*:cursor-pointer">
|
||||
<AlertDialogCancel>Cancelar</AlertDialogCancel>
|
||||
<AlertDialogAction asChild>
|
||||
<Button onClick={cancel} disabled={loading} variant="destructive">
|
||||
{loading ? <Spinner /> : null} Continuar
|
||||
</Button>
|
||||
</AlertDialogAction>
|
||||
<AlertDialogCancel>Cancelar</AlertDialogCancel>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
|
||||
@@ -7,7 +7,6 @@ import {
|
||||
DataTableColumnSelect
|
||||
} from '@repo/ui/components/data-table'
|
||||
import { columns as columns_, type Order } from '@repo/ui/routes/orders/columns'
|
||||
import { Abbr } from '@repo/ui/components/abbr'
|
||||
|
||||
export type { Order }
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import type { Route } from './+types/route'
|
||||
import { zodResolver } from '@hookform/resolvers/zod'
|
||||
import { PatternFormat } from 'react-number-format'
|
||||
import { Link, useOutletContext } from 'react-router'
|
||||
import { useForm } from 'react-hook-form'
|
||||
|
||||
import { Button } from '@repo/ui/components/ui/button'
|
||||
import {
|
||||
@@ -22,15 +23,14 @@ import {
|
||||
} from '@repo/ui/components/ui/form'
|
||||
import { Input } from '@repo/ui/components/ui/input'
|
||||
import { Spinner } from '@repo/ui/components/ui/spinner'
|
||||
import { useForm } from 'react-hook-form'
|
||||
import { type User } from '@repo/ui/routes/users/data'
|
||||
|
||||
import type { User } from '../_.$orgid.users.$id/route'
|
||||
import { formSchema, type Schema } from '../_.$orgid.users.add/route'
|
||||
import { formSchema, type Schema } from '../_.$orgid.users.add/data'
|
||||
|
||||
export default function Route({}: Route.ComponentProps) {
|
||||
const { user } = useOutletContext() as { user: User }
|
||||
const form = useForm({
|
||||
defaultValues: user,
|
||||
defaultValues: { ...user, given_email: false },
|
||||
resolver: zodResolver(formSchema)
|
||||
})
|
||||
const { handleSubmit, control, formState } = form
|
||||
|
||||
@@ -40,8 +40,8 @@ export async function loader({ params, request, context }: Route.LoaderArgs) {
|
||||
throw new Response(null, { status: r.status })
|
||||
}
|
||||
|
||||
const user: User = await r.json()
|
||||
return { user }
|
||||
const data = await r.json()
|
||||
return { data } as { data: any }
|
||||
}
|
||||
|
||||
export function shouldRevalidate({
|
||||
@@ -51,18 +51,14 @@ export function shouldRevalidate({
|
||||
return currentParams.id !== nextParams.id
|
||||
}
|
||||
|
||||
export type User = {
|
||||
name: string
|
||||
email: string
|
||||
cpf: string
|
||||
}
|
||||
|
||||
const links = [
|
||||
{ to: '', title: 'Perfil', end: true },
|
||||
{ to: 'emails', title: 'Emails' }
|
||||
]
|
||||
|
||||
export default function Route({ loaderData: { user } }: Route.ComponentProps) {
|
||||
export default function Route({
|
||||
loaderData: { data: user }
|
||||
}: Route.ComponentProps) {
|
||||
return (
|
||||
<div className="space-y-2.5">
|
||||
<Breadcrumb>
|
||||
|
||||
@@ -2,11 +2,7 @@
|
||||
|
||||
import { type ColumnDef } from '@tanstack/react-table'
|
||||
import { useToggle } from 'ahooks'
|
||||
import {
|
||||
EllipsisVerticalIcon,
|
||||
PencilIcon,
|
||||
UserRoundMinusIcon
|
||||
} from 'lucide-react'
|
||||
import { EllipsisIcon, PencilIcon, UserRoundMinusIcon } from 'lucide-react'
|
||||
import { NavLink, useParams } from 'react-router'
|
||||
import { toast } from 'sonner'
|
||||
|
||||
@@ -63,7 +59,7 @@ function ActionMenu({ row }: { row: any }) {
|
||||
className="data-[state=open]:bg-muted text-muted-foreground cursor-pointer"
|
||||
size="icon-sm"
|
||||
>
|
||||
<EllipsisVerticalIcon />
|
||||
<EllipsisIcon />
|
||||
<span className="sr-only">Abrir menu</span>
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
@@ -127,12 +123,12 @@ function UnlinkItem({ id }: { id: string }) {
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter className="*:cursor-pointer">
|
||||
<AlertDialogCancel>Cancelar</AlertDialogCancel>
|
||||
<AlertDialogAction asChild>
|
||||
<Button onClick={unlink} disabled={loading} variant="destructive">
|
||||
{loading ? <Spinner /> : null} Continuar
|
||||
</Button>
|
||||
</AlertDialogAction>
|
||||
<AlertDialogCancel>Cancelar</AlertDialogCancel>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
|
||||
@@ -0,0 +1,55 @@
|
||||
import { isValidCPF } from '@brazilian-utils/brazilian-utils'
|
||||
import {
|
||||
adjectives,
|
||||
colors,
|
||||
NumberDictionary,
|
||||
uniqueNamesGenerator
|
||||
} from 'unique-names-generator'
|
||||
import { z } from 'zod'
|
||||
|
||||
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>
|
||||
@@ -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