Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/RegistrationGameStyles #85

Open
wants to merge 38 commits into
base: homolog
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
966b1ff
feat: add checkbox component from shadcn
viniciusmontibeller May 1, 2024
6df2259
feat: add base text components and from
viniciusmontibeller May 1, 2024
2a9e2a0
feat: small changes to checkbox to fit our project
viniciusmontibeller May 2, 2024
d58937a
feat: added mock array to have data to make the page
viniciusmontibeller May 2, 2024
d0a8d89
feat: added form with checkbox to fit the task
viniciusmontibeller May 2, 2024
ba00ab3
feat: added generic checkbox validation
viniciusmontibeller May 2, 2024
85276aa
feat: add checkbox limit up to 3
viniciusmontibeller May 4, 2024
1370f4b
feat: add better checkbox limitation
viniciusmontibeller May 4, 2024
1fba402
refactor: small optimization on validationLimitationCheck
viniciusmontibeller May 4, 2024
96763b6
styles: changed error messages
viniciusmontibeller May 4, 2024
135412e
refactor: made a better location to error message
viniciusmontibeller May 4, 2024
f02774c
feat: added the form to home page to have a testing place
viniciusmontibeller May 4, 2024
1107d46
feat: add base api request to get rpg styles
viniciusmontibeller May 4, 2024
16622a2
chore: add husky
MathMendesReis May 15, 2024
4f3e419
chore: add husky
MathMendesReis May 15, 2024
738e5ff
teste:husky
MathMendesReis May 15, 2024
ab4d89d
teste:husky
MathMendesReis May 15, 2024
9b9b243
husky: corrigindo husky
MathMendesReis May 15, 2024
9c7e7b1
Merge pull request #83 from Quest-Finder/chore/husky
DevVitorPedra May 15, 2024
f1ccc47
Merge branch 'develop' into feat/integracaoFormulario
viniciusmontibeller May 22, 2024
b68b670
Merge branch 'feat/integracaoFormulario' into feat/playerRegistration…
viniciusmontibeller May 22, 2024
28d323e
fix: fixed checkbox array validation
viniciusmontibeller Jun 1, 2024
81e52b0
style: small change to fit figma's design
viniciusmontibeller Jun 1, 2024
e0204c5
refactor: removed duplicated componnet
viniciusmontibeller Jun 1, 2024
6d6042f
refactor: changed spacing to better fit figma's design
viniciusmontibeller Jun 1, 2024
7caa064
fix: returned to correct validation
viniciusmontibeller Jun 1, 2024
8075e69
style: small changed to better fit figma's design
viniciusmontibeller Jun 1, 2024
4a01f4c
refactor: small reorganization on types
viniciusmontibeller Jun 8, 2024
3860707
refactor: created custom hooks to have a better reading and separatio…
viniciusmontibeller Jun 8, 2024
a54ad0f
refactor: updated form with custom hooks created
viniciusmontibeller Jun 8, 2024
7804e03
refactor: removed uneeded home button and removed button from game st…
viniciusmontibeller Jun 8, 2024
4fc67f8
feat: created generic skeleton component
viniciusmontibeller Jun 9, 2024
ba6eaec
refactor: removed unused mock object, and added loading functionality.
viniciusmontibeller Jun 9, 2024
f1dcc66
fix: fixed typography and a typescript error
viniciusmontibeller Jun 17, 2024
97ac73b
feat: added storybook
viniciusmontibeller Jun 17, 2024
56b1846
style: fixed lint problems
viniciusmontibeller Jun 18, 2024
1b8b60f
styles: fixed aditional lint errors
viniciusmontibeller Jun 18, 2024
11956d6
fix: fixed word misspelling from First step form
viniciusmontibeller Jun 20, 2024
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
1 change: 1 addition & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm run lint
1 change: 1 addition & 0 deletions .husky/pre-push
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
npm run build
47 changes: 47 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
"start": "next start",
"lint": "next lint",
"storybook": "storybook dev -p 6006",
"build-storybook": "storybook build"
"build-storybook": "storybook build",
"format": "prettier --write \"**/*.{ts,tsx,js,jsx,md,mdx,css,yaml,yml}\"",
"check": "prettier --check \"**/*.{ts,tsx,js,jsx,md,mdx,css,yaml,yml}\"",
"prepare": "husky"
},
"dependencies": {
"@clerk/localizations": "^1.26.3",
"@clerk/nextjs": "^4.25.3",
"@hookform/resolvers": "^3.3.4",
"@radix-ui/react-alert-dialog": "^1.0.5",
"@radix-ui/react-avatar": "^1.0.4",
"@radix-ui/react-checkbox": "^1.0.4",
"@radix-ui/react-dialog": "^1.0.5",
"@radix-ui/react-label": "^2.0.2",
"@radix-ui/react-radio-group": "^1.1.3",
Expand Down Expand Up @@ -68,6 +72,7 @@
"eslint-config-prettier": "^8.8.0",
"eslint-plugin-prettier": "^5.0.0",
"eslint-plugin-storybook": "^0.6.15",
"husky": "^9.0.11",
"prettier": "3.0.0",
"prettier-plugin-tailwindcss": "^0.4.1",
"storybook": "^7.6.4"
Expand Down
4 changes: 3 additions & 1 deletion src/app/cadastro/estilos-de-jogo/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use client'

import { FormGameStyles } from '@/features/register-player/game-styles/FormGameStyles'

export default function PagesStylesPlay() {
return <div />
return <FormGameStyles />
}
30 changes: 30 additions & 0 deletions src/components/ui/checkbox.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"use client"

import * as React from "react"
import * as CheckboxPrimitive from "@radix-ui/react-checkbox"
import { Check } from "lucide-react"

import { cn } from "@/lib/utils"

const Checkbox = React.forwardRef<
React.ElementRef<typeof CheckboxPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof CheckboxPrimitive.Root>
>(({ className, ...props }, ref) => (
<CheckboxPrimitive.Root
ref={ref}
className={cn(
"peer h-4 w-4 shrink-0 rounded-sm border border-slate-900 ring-offset-white 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 data-[state=checked]:bg-slate-900 data-[state=checked]:text-slate-50 dark:border-slate-50 dark:ring-offset-slate-950 dark:focus-visible:ring-slate-300 dark:data-[state=checked]:bg-slate-50 dark:data-[state=checked]:text-slate-900",
className
)}
{...props}
>
<CheckboxPrimitive.Indicator
className={cn("flex items-center justify-center text-current")}
>
<Check className="h-3 w-3" />
</CheckboxPrimitive.Indicator>
</CheckboxPrimitive.Root>
))
Checkbox.displayName = CheckboxPrimitive.Root.displayName

export { Checkbox }
129 changes: 129 additions & 0 deletions src/features/register-player/game-styles/FormGameStyles.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
'use client'

import {
Form,
FormControl,
FormField,
FormItem,
FormLabel,
FormMessage,
} from '@/components/ui/form'
import { Checkbox } from '@/components/ui/checkbox'
import { Button } from '@/components/ui/button'
import { Arrow } from '@/components/icons/Arrow'

import { cn } from '@/lib/utils'
import { validationCheckBoxLimitation } from './helpers/validationCheckBoxLimitation'
import { FormAditionalText } from './components/FormAditionalText'
import { FormTitle } from '../utils/title-form'
import useSubmitGameStyles from './hooks/useSubmitGameStyles'
import { useFormGameStyles } from './hooks/useFormGameStyles'
import { Skeleton } from '../utils/Skeleton'

export function FormGameStyles() {
const { gameStyles, isLoading, form } = useFormGameStyles()

return (
<Form {...form}>
<div>
<FormAditionalText className='text-center'>
Olá! Para aprimorarmos sua experiência no TVM, por favor, responda
algumas perguntas.
</FormAditionalText>
<FormTitle className='mb-0'>
Escolha o estilo de jogo que mais se alinha com seus interesses.
</FormTitle>
</div>
<form
onSubmit={form.handleSubmit(useSubmitGameStyles())}
className='flex flex-col items-center space-y-8'
>
<FormField
control={form.control}
name='rpgStyles'
render={() => (
<FormItem>
<FormItem className='flex max-w-[44.063rem] flex-wrap justify-center gap-2 space-y-0'>
{isLoading && (
<Skeleton
height='[2.875rem]'
width={40}
quantity={10}
className='rounded-full'
/>
)}
{!isLoading &&
gameStyles &&
gameStyles.map(item => (
<FormField
key={item.id}
control={form.control}
name='rpgStyles'
render={({ field }) => {
return (
<FormItem
key={item.id}
aria-disabled={validationCheckBoxLimitation(
form.getValues('rpgStyles'),
item.id,
3,
)}
className='group/checkbox aria-disabled:cursor-not-allowed'
>
<FormLabel
className={cn(
'flex w-fit cursor-pointer items-center gap-2.5 space-y-0 rounded-full border-[1px] bg-primary-50 px-4 py-3 font-mono text-sm font-medium text-primary-900 group-aria-disabled/checkbox:pointer-events-none group-aria-disabled/checkbox:opacity-50',
field.value?.includes(item.id)
? 'border-primary-900'
: 'border-transparent',
)}
>
{item.name}
<FormControl>
<Checkbox
checked={field.value?.includes(item.id)}
className='border-primary-900 data-[state=checked]:rounded-full data-[state=checked]:bg-primary-900'
onCheckedChange={(checked: boolean) => {
return checked
? field.onChange([
...field.value,
item.id,
])
: field.onChange(
field.value?.filter(
value => value !== item.id,
),
)
}}
/>
</FormControl>
</FormLabel>
</FormItem>
)
}}
/>
))}
</FormItem>
{form.formState.errors.rpgStyles?.message && (
<div className='mx-auto w-fit [&>ul]:mt-5'>
<FormMessage />
</div>
)}
</FormItem>
)}
/>
<div className='text-center'>
<Button
disabled={!form.formState.isValid}
className='h-full max-h-14 w-full max-w-[214px] text-base disabled:opacity-50'
variant='default'
type='submit'
>
Salvar e Continuar
<Arrow />
</Button>
</div>
</form>
</Form>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { cn } from '@/lib/utils'

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

export function FormAditionalText({
className,
children,
...props
}: FormTitleProps) {
return (
<h1
className={cn('mb-6 text-base text-neutral-600', className)}
{...props}
>
{children}
</h1>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const defaultValues = {
rpgStyles: [],
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export function validationCheckBoxLimitation(
array: string[],
field: string,
maxNumber: number,
) {
return array.length >= maxNumber && !array.includes(field)
}
27 changes: 27 additions & 0 deletions src/features/register-player/game-styles/hooks/useFetchData.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { useEffect, useState } from 'react'

export function useFetchData<T>(url: string) {
const [data, setData] = useState<T | null>(null)
const [isLoading, setIsLoading] = useState(true)
const [error, setError] = useState<Error | null>(null)
useEffect(() => {
const fetchData = async () => {
try {
const response = await fetch(url)
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`)
}
const jsonData = await response.json()
setData(jsonData)
} catch (err) {
setError(err as Error)
} finally {
setIsLoading(false)
}
}

fetchData()
}, [url])

return { data, isLoading, error }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { zodResolver } from '@hookform/resolvers/zod'
import { useForm } from 'react-hook-form'
import useLocalStorageGetItem from '@/features/register-player/address registration/hooks/useLocalStorageGetItem'
import { FormGameStylesSchema } from '../validation'
import { GameStyle, FormGameStylesType } from '../types/gameStyles'
import { useFetchData } from './useFetchData'
import { defaultValues } from '../helpers/defaultValues'

export function useFormGameStyles() {
const {
data: gameStyles,
isLoading,
error,
} = useFetchData<GameStyle[]>(
'https://tem-vaga-mestre-api-nnf7bytugq-uc.a.run.app/rpg-style',
)
const savedData = useLocalStorageGetItem<FormGameStylesType>('game_styles')

const initalValue = savedData || defaultValues

const form = useForm<FormGameStylesType>({
resolver: zodResolver(FormGameStylesSchema),
defaultValues: initalValue,
})

return { form, gameStyles, isLoading, error }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import uselocalStorageSetItem from '@/features/register-player/address registration/hooks/uselocalStorageSetItem'
import { RegisterRoutes } from '@/services/routers'
import { useRouter } from 'next/navigation'
import { FormGameStylesType } from '../types/gameStyles'

export default function useSubmitGameStyles() {
const router = useRouter()
return (values: FormGameStylesType) => {
uselocalStorageSetItem('game_styles', values)
router.push(RegisterRoutes.PlayerProfile)
}
}
Loading