Skip to content

Commit

Permalink
Merge pull request #82 from Quest-Finder/lint/correcoes
Browse files Browse the repository at this point in the history
Lint/correcoes
  • Loading branch information
DevVitorPedra committed May 15, 2024
2 parents 8616a9f + 8d563c3 commit 363614a
Show file tree
Hide file tree
Showing 12 changed files with 99 additions and 65 deletions.
2 changes: 1 addition & 1 deletion src/app/cadastro/perfil-do-jogador/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ export default function PagesPlayerProfile() {
/>
</>
)
}
}
3 changes: 2 additions & 1 deletion src/components/ui/input.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ const Input = React.forwardRef<HTMLInputElement, InputProps>(
type={type}
className={cn(
'flex h-10 w-full rounded-md border border-slate-200 bg-white px-3 py-2 text-sm ring-offset-white file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-slate-500 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-slate-950 focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 dark:border-slate-800 dark:bg-slate-950 dark:ring-offset-slate-950 dark:placeholder:text-slate-400 dark:focus-visible:ring-slate-300',
isError && 'border-red-700 bg-red-100 text-red-700 placeholder:text-red-700',
isError &&
'border-red-700 bg-red-100 text-red-700 placeholder:text-red-700',
className,
)}
ref={ref}
Expand Down
69 changes: 39 additions & 30 deletions src/features/register-player/player-profile/FormPlayerProfile.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
'use client'

import {
Form,
FormControl,
FormField,
FormItem,
} from "@/components/ui/form"
import { Card, CardTitle, CardDescription } from '@/components/ui/card'
import { Button } from "@/components/ui/button"
import { Arrow } from '@/components/icons/Arrow'
import { useForm } from "react-hook-form"
import { FormPlayerProfileType, FormPlayerProfileSchema } from './validation'
import { zodResolver } from "@hookform/resolvers/zod"
import { Button } from '@/components/ui/button'
import { Card, CardDescription, CardTitle } from '@/components/ui/card'
import { Form, FormControl, FormField, FormItem } from '@/components/ui/form'
import { zodResolver } from '@hookform/resolvers/zod'
import Image from 'next/image'
import { useForm } from 'react-hook-form'
import { FormPlayerProfileSchema, FormPlayerProfileType } from './validation'

import { mockFormPlayerProfile } from './mock'

import { getRpgImage, getRpgStyling, getRpgImageColor } from './helpers/getRpgStyle'
import { FormTitle } from "./components/FormTitle"
import { FormAditionalText } from "./components/FormAditionalText"
import { FormAditionalText } from './components/FormAditionalText'
import { FormTitle } from './components/FormTitle'
import {
getRpgImage,
getRpgImageColor,
getRpgStyling,
} from './helpers/getRpgStyle'

export function FormPlayerProfile() {
const form = useForm<FormPlayerProfileType>({
Expand All @@ -28,27 +27,27 @@ export function FormPlayerProfile() {
},
})

function onSubmit(data: FormPlayerProfileType) {
console.log(data)
}

console.log(form.getValues('playerProfileId'))
function onSubmit() {}

return (
<Form {...form}>
<FormAditionalText>
Olá! Para aprimorarmos sua experiência no TVM, por favor, responda algumas perguntas.
Olá! Para aprimorarmos sua experiência no TVM, por favor, responda
algumas perguntas.
</FormAditionalText>
<FormTitle>
Escolha o perfil de jogador que mais se alinha com seus interesses.
</FormTitle>
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8 flex flex-col items-center">
<form
onSubmit={form.handleSubmit(onSubmit)}
className='flex flex-col items-center space-y-8'
>
<FormField
control={form.control}
name='playerProfileId'
render={() => (
<FormItem className="flex gap-[1.625rem] space-y-0 max-w-[1125px]">
{mockFormPlayerProfile.map((item) => (
<FormItem className='flex max-w-[1125px] gap-[1.625rem] space-y-0'>
{mockFormPlayerProfile.map(item => (
<FormField
key={item.id}
control={form.control}
Expand All @@ -57,25 +56,35 @@ export function FormPlayerProfile() {
return (
<FormItem
key={item.id}
className="basis-1/3"
className='basis-1/3'
>
<FormControl>
<Card
aria-disabled={form.getValues("playerProfileId").length !== 0 && (form.getValues('playerProfileId') !== item.id)}
className={`${getRpgStyling(item.title)} py-4 px-6 aria-disabled:opacity-50 cursor-pointer`}
aria-disabled={
form.getValues('playerProfileId').length !== 0 &&
form.getValues('playerProfileId') !== item.id
}
className={`${getRpgStyling(
item.title,
)} cursor-pointer px-6 py-4 aria-disabled:opacity-50`}
onClick={() => {
console.log(form.getValues('playerProfileId'))
return field.onChange(item.id)
}}
>
<div className={`${getRpgImageColor(item.title)} rounded-full p-4 h-24 w-24 flex justify-center items-center`}>
<div
className={`${getRpgImageColor(
item.title,
)} flex h-24 w-24 items-center justify-center rounded-full p-4`}
>
<Image
src={getRpgImage(item.title)}
alt={item.title}
/>
</div>
<CardTitle>{item.title}</CardTitle>
<CardDescription>{item.description}</CardDescription>
<CardDescription>
{item.description}
</CardDescription>
</Card>
</FormControl>
</FormItem>
Expand All @@ -101,4 +110,4 @@ export function FormPlayerProfile() {
</form>
</Form>
)
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
import { cn } from '@/lib/utils'

interface FormAditionalTextProps extends React.HTMLAttributes<HTMLHeadingElement> {
interface FormAditionalTextProps
extends React.HTMLAttributes<HTMLHeadingElement> {
children: string
}

export function FormAditionalText({ className, children, ...props }: FormAditionalTextProps) {
export function FormAditionalText({
className,
children,
...props
}: FormAditionalTextProps) {
return (
<h1
className={cn('mb-4 text-base text-neutral-600 text-center', className)}
className={cn('mb-4 text-center text-base text-neutral-600', className)}
{...props}
>
{children}
</h1>
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ interface FormTitleProps extends React.HTMLAttributes<HTMLHeadingElement> {
export function FormTitle({ className, children, ...props }: FormTitleProps) {
return (
<h1
className={cn('mb-4 text-[32px] text-neutral-950 text-center', className)}
className={cn('mb-4 text-center text-[32px] text-neutral-950', className)}
{...props}
>
{children}
</h1>
)
}
}
16 changes: 11 additions & 5 deletions src/features/register-player/player-profile/helpers/getRpgStyle.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,42 @@
import Exploracao from '../assets/Exploracao.svg'
import MatarEPilhar from '../assets/MatarEPilhar.svg'
import Interpretacao from '../assets/Interpretacao.svg'
import MatarEPilhar from '../assets/MatarEPilhar.svg'

export function getRpgImage(rpgStyle: string) {
switch (rpgStyle) {
case 'Exploração':
return Exploracao
case 'Matar e pilhar':
case 'Matar e pilhar':
return MatarEPilhar
case 'Interpretação':
return Interpretacao
default:
return ''
}
}

export function getRpgImageColor(rpgStyle: string) {
switch (rpgStyle) {
case 'Exploração':
return 'bg-primary-100'
case 'Matar e pilhar':
case 'Matar e pilhar':
return 'bg-secondary-100'
case 'Interpretação':
return 'bg-accent-100'
default:
return ''
}
}

export function getRpgStyling(rpgStyle: string) {
switch (rpgStyle) {
case 'Exploração':
return 'border-primary-500 bg-primary-50'
case 'Matar e pilhar':
case 'Matar e pilhar':
return 'border-secondary-500 bg-secondary-50'
case 'Interpretação':
return 'border-accent-500 bg-accent-50'
default:
return ''
}
}
}
15 changes: 9 additions & 6 deletions src/features/register-player/player-profile/mock.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
interface profileType {
id: string,
title: string,
id: string
title: string
description: string
}

export const mockFormPlayerProfile: profileType[] = [
{
id: '9228a9a0-c7e0-4d62-80bb-458dd772c4f9',
title: 'Exploração',
description: 'Você gosta de conhecer o mundo em que está se aventurando, adora encontrar e explorar dungeons.',
description:
'Você gosta de conhecer o mundo em que está se aventurando, adora encontrar e explorar dungeons.',
},
{
id: '9228b7a0-c7e0-3d62-86bb-458dd332c4f9',
title: 'Matar e pilhar',
description: 'Para você, a parte mais importante e divertida de uma partida é a hora de rolar dados e distribuir o dano entre seus inimigos.',
description:
'Para você, a parte mais importante e divertida de uma partida é a hora de rolar dados e distribuir o dano entre seus inimigos.',
},
{
id: '9988b7c3-c2t0-3d09-43cb-451gd332c0l9',
title: 'Interpretação',
description: 'Para você, a ficha e as regras são apenas uma parte do RPG, você gosta de sentir-se na pele de seu personagem.',
description:
'Para você, a ficha e as regras são apenas uma parte do RPG, você gosta de sentir-se na pele de seu personagem.',
},
]
]
9 changes: 5 additions & 4 deletions src/features/register-player/player-profile/validation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { z } from "zod"
import { z } from 'zod'

export const FormPlayerProfileSchema = z.object({
playerProfileId: z.string()
.min(1, { message: 'Necessário escolher pelo menos uma opção' })
playerProfileId: z
.string()
.min(1, { message: 'Necessário escolher pelo menos uma opção' }),
})

export type FormPlayerProfileType = z.infer<typeof FormPlayerProfileSchema>
export type FormPlayerProfileType = z.infer<typeof FormPlayerProfileSchema>
10 changes: 7 additions & 3 deletions src/features/register-player/player-registration/FormStepOne.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ export function FormStepOne() {
return (
<FormFirstStep.Root>
<Form {...form}>
<FormFirstStep.Title>Deixe-nos sabes mais sobre você</FormFirstStep.Title>
<FormFirstStep.Title>
Deixe-nos sabes mais sobre você
</FormFirstStep.Title>
<form
onSubmit={form.handleSubmit(useSubmitStepOne())}
className='w-full max-w-[340px] space-y-4'
Expand Down Expand Up @@ -108,7 +110,9 @@ export function FormStepOne() {
<SelectItem value='he/his'>Ele / Dele</SelectItem>
<SelectItem value='she/her'>Ela / Dela</SelectItem>
<SelectItem value='they/theirs'>Elu / Delu</SelectItem>
<SelectItem value="I don't want to share any pronouns">Prefiro não responder</SelectItem>
<SelectItem value="I don't want to share any pronouns">
Prefiro não responder
</SelectItem>
</SelectContent>
</Select>
</FormItem>
Expand All @@ -129,7 +133,7 @@ export function FormStepOne() {
<Button
disabled={!form.formState.isValid}
aria-disabled={form.formState.isValidating}
className='mt-4 h-full max-h-14 w-full max-w-[214px] text-base disabled:opacity-50 aria-disabled:animate-pulse aria-disabled:pointer-events-none aria-disabled:cursor-wait'
className='mt-4 h-full max-h-14 w-full max-w-[214px] text-base disabled:opacity-50 aria-disabled:pointer-events-none aria-disabled:animate-pulse aria-disabled:cursor-wait'
variant='default'
type='submit'
>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
export async function checkUniqueUsername(username: string) {
try {
const response = await fetch(`https://tem-vaga-mestre-api-nnf7bytugq-uc.a.run.app/user/check-username/${username}`)
return response.status === 200 ? true : false
const response = await fetch(
`https://tem-vaga-mestre-api-nnf7bytugq-uc.a.run.app/user/check-username/${username}`,
)
return response.status === 200
} catch (error) {
console.log(error)
return false
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ import { FormStepOneType } from '../validation'
export default function useSubmitStepOne() {
const router = useRouter()
return (values: FormStepOneType) => {
const notEmptyPronounValues = { ...values, pronoun: values.pronoun || "I don't want to share any pronouns" }
const notEmptyPronounValues = {
...values,
pronoun: values.pronoun || "I don't want to share any pronouns",
}
uselocalStorageSetItem('form_step_one', notEmptyPronounValues)
router.push(RegisterRoutes.SocialNetworks)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as z from 'zod'
import moment from 'moment'
import { filter } from '@/helpers/badWordsFilter/badWordsFilter'
import moment from 'moment'
import * as z from 'zod'
import { checkUniqueUsername } from './helper/checkUniqueUsername'

export const FormStepOneSchema = z.object({
Expand All @@ -19,8 +19,8 @@ export const FormStepOneSchema = z.object({
.min(1, 'Campo obrigatório')
.max(15, 'O username deve conter no máximo 15 caracteres')
.regex(/^[a-zA-Z0-9'-]*$/, 'Caracteres especiais não são disponiveis')
.refine((username) => checkUniqueUsername(username), {
message: "Username ja existente"
.refine(username => checkUniqueUsername(username), {
message: 'Username ja existente',
})
.refine(username => !filter.isProfane(username), {
message: 'Palavras de baixo calão não são permitidas',
Expand Down

0 comments on commit 363614a

Please sign in to comment.