Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 12 additions & 8 deletions src/features/home/pages/home-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
import { ArrowDown, ArrowRight, Check } from 'lucide-react'
import { BackgroundBlobs } from '@/shared/components/background-blobs'
import { Footer } from '@/features/home/components/footer'
import { Link } from 'react-router-dom'

const plans = [
{
Expand Down Expand Up @@ -130,7 +131,8 @@ const owners = [
{
name: 'Júlia Galhardi Cerqueira',
image: 'https://d1b8zs4rmj3xdl.cloudfront.net/julia.jpeg',
role: 'Estagiária'
role: 'Estagiária',
linkedin: 'https://www.linkedin.com/in/j%C3%BAliacerqueira/'
},
{
name: 'Vinícius Berti',
Expand Down Expand Up @@ -255,14 +257,16 @@ export function HomePage() {
transition={transition}
variants={variants}
>
<Button>Começar</Button>
<a
href="https://github.com/knowlyai/knowly"
<Link to="/docs">
<Button>Começar</Button>
</Link>
<Link
to="https://github.com/knowlyai/knowly"
target="_blank"
rel="noreferrer"
>
<Button variant="outline">GitHub</Button>
</a>
</Link>
</motion.div>
<LogoCarousel />
</motion.section>
Expand Down Expand Up @@ -444,9 +448,9 @@ export function HomePage() {
variants={variants}
>
{owners.map((owner, index) => (
<a
<Link
key={index}
href={owner.linkedin}
to={owner.linkedin}
target="_blank"
rel="noreferrer"
className="flex h-full w-full items-center justify-center"
Expand All @@ -464,7 +468,7 @@ export function HomePage() {
{owner.role}
</span>
</Card>
</a>
</Link>
))}
</motion.div>
</motion.section>
Expand Down
62 changes: 23 additions & 39 deletions src/features/sign-up/pages/sign-up-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ import { zodResolver } from '@hookform/resolvers/zod'
import { useForm } from 'react-hook-form'
import { Checkbox } from '@/shared/components/checkbox'
import { Label } from '@/shared/components/label'
import {
formatCNPJ,
formatCPF,
formatPhone
} from '@/shared/utils/format-documents'
import toast from 'react-hot-toast'
import { BackgroundBlobs } from '@/shared/components/background-blobs'
import { motion } from 'framer-motion'
Expand All @@ -41,6 +36,12 @@ import { containerVariants, cardVariants } from '@/shared/utils/animations'
import { useCreateUserMutation } from '@/shared/hooks/use-user'
import { AxiosError } from 'axios'
import { useNavigate } from 'react-router-dom'
import { DOCUMENT_TYPE } from '@/shared/enums/document-type'
import {
handleCNPJChange,
handleCPFChange,
handlePhoneChange
} from '@/shared/utils/string-extensions'

export function SignUpPage() {
const [showPassword, setShowPassword] = useState(false)
Expand All @@ -55,33 +56,9 @@ export function SignUpPage() {
mode: 'onBlur'
})

const handleCPFChange = (
value: string,
onChange: (value: string) => void
) => {
const formattedValue = formatCPF(value)
onChange(formattedValue)
}

const handleCNPJChange = (
value: string,
onChange: (value: string) => void
) => {
const formattedValue = formatCNPJ(value)
onChange(formattedValue)
}

const handlePhoneChange = (
value: string,
onChange: (value: string) => void
) => {
const formattedValue = formatPhone(value)
onChange(formattedValue)
}

async function onSubmit(values: SignUpFormData) {
try {
const isIndividual = values.documentType === 'individual'
const isIndividual = values.documentType === DOCUMENT_TYPE.INDIVIDUAL

// Convert birthDate to seconds since epoch if provided
const birthDateSeconds = values.birthDate
Expand Down Expand Up @@ -196,9 +173,11 @@ export function SignUpPage() {
>
<Checkbox
id="type-individual"
checked={field.value === 'individual'}
checked={
field.value === DOCUMENT_TYPE.INDIVIDUAL
}
onCheckedChange={() => {
field.onChange('individual')
field.onChange(DOCUMENT_TYPE.INDIVIDUAL)
form.setValue('document', '')
}}
/>
Expand All @@ -210,9 +189,9 @@ export function SignUpPage() {
>
<Checkbox
id="type-business"
checked={field.value === 'business'}
checked={field.value === DOCUMENT_TYPE.BUSINESS}
onCheckedChange={() => {
field.onChange('business')
field.onChange(DOCUMENT_TYPE.BUSINESS)
form.setValue('document', '')
form.setValue('birthDate', undefined)
}}
Expand All @@ -231,7 +210,8 @@ export function SignUpPage() {
render={({ field }) => (
<FormItem className="w-full">
<FormLabel>
{form.getValues('documentType') === 'individual'
{form.getValues('documentType') ===
DOCUMENT_TYPE.INDIVIDUAL
? 'CPF'
: 'CNPJ'}
</FormLabel>
Expand All @@ -240,20 +220,23 @@ export function SignUpPage() {
{...field}
onChange={(e) => {
if (
form.getValues('documentType') === 'individual'
form.getValues('documentType') ===
DOCUMENT_TYPE.INDIVIDUAL
) {
handleCPFChange(e.target.value, field.onChange)
} else {
handleCNPJChange(e.target.value, field.onChange)
}
}}
placeholder={
form.getValues('documentType') === 'individual'
form.getValues('documentType') ===
DOCUMENT_TYPE.INDIVIDUAL
? '000.000.000-00'
: '00.000.000/0000-00'
}
maxLength={
form.getValues('documentType') === 'individual'
form.getValues('documentType') ===
DOCUMENT_TYPE.INDIVIDUAL
? 14
: 18
}
Expand All @@ -263,7 +246,8 @@ export function SignUpPage() {
</FormItem>
)}
/>
{form.getValues('documentType') === 'individual' && (
{form.getValues('documentType') ===
DOCUMENT_TYPE.INDIVIDUAL && (
<FormField
control={form.control}
name="birthDate"
Expand Down
6 changes: 3 additions & 3 deletions src/features/sign-up/types/sign-up-schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,15 @@ export const signUpFormSchema = z
})
}

if (data.documentType === 'individual' && !data.birthDate) {
if (data.documentType === DOCUMENT_TYPE.INDIVIDUAL && !data.birthDate) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: 'A data de nascimento é obrigatória para pessoa física.',
path: ['birthDate']
})
}

if (data.documentType === 'individual') {
if (data.documentType === DOCUMENT_TYPE.INDIVIDUAL) {
// Validação CPF
const cpfRegex = /^\d{3}\.?\d{3}\.?\d{3}-?\d{2}$/
if (!cpfRegex.test(data.document)) {
Expand Down Expand Up @@ -104,7 +104,7 @@ export const signUpFormInitialValues: SignUpFormData = {
name: '',
email: '',
phone: '',
documentType: 'individual',
documentType: DOCUMENT_TYPE.INDIVIDUAL,
document: '',
birthDate: undefined,
password: '',
Expand Down
Loading