Skip to content

Commit ab8ec58

Browse files
committed
fix: apply prettier formatting
1 parent 3786336 commit ab8ec58

File tree

2 files changed

+154
-169
lines changed

2 files changed

+154
-169
lines changed

src/app/login/page.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,8 @@ export default function LoginPage() {
2323
})
2424

2525
const data = await res.json()
26-
console.log('🛠️ Resposta do backend:', data)
2726

2827
if (res.ok && data.access_token) {
29-
3028
localStorage.setItem('token', data.access_token)
3129

3230
setMensagem('Login bem-sucedido!')

src/app/register/page.tsx

Lines changed: 154 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -7,185 +7,172 @@ import styles from './register.module.css'
77
import Image from 'next/image'
88

99
export default function RegisterPage() {
10-
const [email, setEmail] = useState('')
11-
const [password, setPassword] = useState('')
12-
const [confirmPassword, setConfirmPassword] = useState('')
13-
const [username, setUsername] = useState('')
10+
const [email, setEmail] = useState('')
11+
const [password, setPassword] = useState('')
12+
const [confirmPassword, setConfirmPassword] = useState('')
13+
const [username, setUsername] = useState('')
1414

15-
// Os valores corretos do enum para backend
16-
const [role, setRole] = useState<'DUNGEON_MASTER' | 'PLAYER'>('DUNGEON_MASTER')
17-
const [error, setError] = useState('')
18-
const [loading, setLoading] = useState(false)
15+
const [role, setRole] = useState<'DUNGEON_MASTER' | 'PLAYER'>('DUNGEON_MASTER')
16+
const [error, setError] = useState('')
17+
const [loading, setLoading] = useState(false)
1918

20-
const router = useRouter()
19+
const router = useRouter()
2120

22-
const handleSubmit = async (event: React.FormEvent) => {
23-
event.preventDefault()
24-
setError('')
25-
setLoading(true)
21+
const handleSubmit = async (event: React.FormEvent) => {
22+
event.preventDefault()
23+
setError('')
24+
setLoading(true)
2625

27-
if (password !== confirmPassword) {
28-
setError('As senhas não coincidem.')
29-
setLoading(false)
30-
return
31-
}
26+
if (password !== confirmPassword) {
27+
setError('As senhas não coincidem.')
28+
setLoading(false)
29+
return
30+
}
3231

33-
// Mapeia o valor do role para o que backend espera
34-
const roleToSend = role === 'DUNGEON_MASTER' ? 'dungeon master' : 'player'
32+
const roleToSend = role === 'DUNGEON_MASTER' ? 'dungeon master' : 'player'
3533

36-
try {
37-
const response = await fetch('http://localhost:8080/users/', {
38-
method: 'POST',
39-
headers: { 'Content-Type': 'application/json' },
40-
body: JSON.stringify({
41-
email,
42-
password,
43-
username,
44-
role: roleToSend,
45-
}),
46-
})
34+
try {
35+
const response = await fetch('http://localhost:8080/users/', {
36+
method: 'POST',
37+
headers: { 'Content-Type': 'application/json' },
38+
body: JSON.stringify({
39+
email,
40+
password,
41+
username,
42+
role: roleToSend,
43+
}),
44+
})
4745

48-
if (!response.ok) {
49-
const errorData = await response.json()
50-
if (Array.isArray(errorData.detail)) {
51-
const messages = errorData.detail.map((e: any) => e.msg).join('; ')
52-
setError(messages)
53-
} else {
54-
setError(errorData.detail || 'Erro ao cadastrar usuário.')
55-
}
56-
} else {
57-
localStorage.setItem('role', role)
58-
router.push('/login')
46+
if (!response.ok) {
47+
const errorData = await response.json()
48+
if (Array.isArray(errorData.detail)) {
49+
const messages = errorData.detail.map((e: any) => e.msg).join('; ')
50+
setError(messages)
51+
} else {
52+
setError(errorData.detail || 'Erro ao cadastrar usuário.')
53+
}
54+
} else {
55+
localStorage.setItem('role', role)
56+
router.push('/login')
57+
}
58+
} catch (err) {
59+
let errorMessage = 'Ocorreu um erro desconhecido ao tentar conectar com o servidor.'
60+
if (err instanceof Error) errorMessage = `Erro: ${err.message}`
61+
else if (typeof err === 'string') errorMessage = `Erro: ${err}`
62+
setError(errorMessage)
63+
} finally {
64+
setLoading(false)
5965
}
60-
} catch (err) {
61-
let errorMessage = 'Ocorreu um erro desconhecido ao tentar conectar com o servidor.'
62-
if (err instanceof Error) errorMessage = `Erro: ${err.message}`
63-
else if (typeof err === 'string') errorMessage = `Erro: ${err}`
64-
setError(errorMessage)
65-
} finally {
66-
setLoading(false)
6766
}
68-
}
69-
7067

71-
return (
72-
<div className={styles.pageContainer}>
73-
<header className={styles.header}>
74-
<h1 className={styles.headerTitle}>EASYCRIT</h1>
75-
</header>
76-
<div className={styles.mainContainer}>
77-
<div className={styles.blackContainer}>
78-
<div className={styles.formWrapper}>
79-
<h2 className={styles.greeting}>Crie sua conta</h2>
80-
<form onSubmit={handleSubmit}>
81-
<div className={styles.inputGroup}>
82-
<label htmlFor="username">Nome de Usuário</label>
83-
<input
84-
type="text"
85-
id="username"
86-
className={styles.inputField}
87-
placeholder="Seu nome de usuário"
88-
value={username}
89-
onChange={(e) => setUsername(e.target.value)}
90-
required
91-
/>
92-
</div>
93-
<div className={styles.inputGroup}>
94-
<label htmlFor="email">Email</label>
95-
<input
96-
type="email"
97-
id="email"
98-
className={styles.inputField}
99-
placeholder="Seu email"
100-
value={email}
101-
onChange={(e) => setEmail(e.target.value)}
102-
required
103-
/>
104-
</div>
105-
<div className={styles.inputGroup}>
106-
<label htmlFor="password">Senha</label>
107-
<input
108-
type="password"
109-
id="password"
110-
className={styles.inputField}
111-
placeholder="••••••••"
112-
value={password}
113-
onChange={(e) => setPassword(e.target.value)}
114-
required
115-
/>
116-
</div>
117-
<div className={styles.inputGroup}>
118-
<label htmlFor="confirm-password">Confirmar Senha</label>
119-
<input
120-
type="password"
121-
id="confirm-password"
122-
className={styles.inputField}
123-
placeholder="••••••••"
124-
value={confirmPassword}
125-
onChange={(e) => setConfirmPassword(e.target.value)}
126-
required
127-
/>
128-
</div>
68+
return (
69+
<div className={styles.pageContainer}>
70+
<header className={styles.header}>
71+
<h1 className={styles.headerTitle}>EASYCRIT</h1>
72+
</header>
73+
<div className={styles.mainContainer}>
74+
<div className={styles.blackContainer}>
75+
<div className={styles.formWrapper}>
76+
<h2 className={styles.greeting}>Crie sua conta</h2>
77+
<form onSubmit={handleSubmit}>
78+
<div className={styles.inputGroup}>
79+
<label htmlFor='username'>Nome de Usuário</label>
80+
<input
81+
type='text'
82+
id='username'
83+
className={styles.inputField}
84+
placeholder='Seu nome de usuário'
85+
value={username}
86+
onChange={(e) => setUsername(e.target.value)}
87+
required
88+
/>
89+
</div>
90+
<div className={styles.inputGroup}>
91+
<label htmlFor='email'>Email</label>
92+
<input
93+
type='email'
94+
id='email'
95+
className={styles.inputField}
96+
placeholder='Seu email'
97+
value={email}
98+
onChange={(e) => setEmail(e.target.value)}
99+
required
100+
/>
101+
</div>
102+
<div className={styles.inputGroup}>
103+
<label htmlFor='password'>Senha</label>
104+
<input
105+
type='password'
106+
id='password'
107+
className={styles.inputField}
108+
placeholder='••••••••'
109+
value={password}
110+
onChange={(e) => setPassword(e.target.value)}
111+
required
112+
/>
113+
</div>
114+
<div className={styles.inputGroup}>
115+
<label htmlFor='confirm-password'>Confirmar Senha</label>
116+
<input
117+
type='password'
118+
id='confirm-password'
119+
className={styles.inputField}
120+
placeholder='••••••••'
121+
value={confirmPassword}
122+
onChange={(e) => setConfirmPassword(e.target.value)}
123+
required
124+
/>
125+
</div>
129126

130-
<div className={styles.adventureChoice}>
131-
<div className={styles.chooseAdventure}>Escolha sua aventura</div>
132-
<div className={styles.roles}>
133-
<label className={styles.roleOption}>
134-
<input
135-
type="radio"
136-
name="role"
137-
value="DUNGEON_MASTER"
138-
className={styles.radioInput}
139-
checked={role === 'DUNGEON_MASTER'}
140-
onChange={() => setRole('DUNGEON_MASTER')}
141-
/>
142-
<Image
143-
src="/mestre-icon.svg"
144-
alt="Dungeon Master"
145-
width={40}
146-
height={40}
147-
className={styles.roleImage}
148-
/>
149-
<span className={styles.roleLabel}>Mestre</span>
150-
</label>
151-
<label className={styles.roleOption}>
152-
<input
153-
type="radio"
154-
name="role"
155-
value="PLAYER"
156-
className={styles.radioInput}
157-
checked={role === 'PLAYER'}
158-
onChange={() => setRole('PLAYER')}
159-
/>
160-
<Image
161-
src="/jogador-icon.svg"
162-
alt="Player"
163-
width={40}
164-
height={40}
165-
className={styles.roleImage}
166-
/>
167-
<span className={styles.roleLabel}>Jogador</span>
168-
</label>
169-
</div>
170-
</div>
127+
<div className={styles.adventureChoice}>
128+
<div className={styles.chooseAdventure}>Escolha sua aventura</div>
129+
<div className={styles.roles}>
130+
<label className={styles.roleOption}>
131+
<input
132+
type='radio'
133+
name='role'
134+
value='DUNGEON_MASTER'
135+
className={styles.radioInput}
136+
checked={role === 'DUNGEON_MASTER'}
137+
onChange={() => setRole('DUNGEON_MASTER')}
138+
/>
139+
<Image
140+
src='/mestre-icon.svg'
141+
alt='Dungeon Master'
142+
width={40}
143+
height={40}
144+
className={styles.roleImage}
145+
/>
146+
<span className={styles.roleLabel}>Mestre</span>
147+
</label>
148+
<label className={styles.roleOption}>
149+
<input
150+
type='radio'
151+
name='role'
152+
value='PLAYER'
153+
className={styles.radioInput}
154+
checked={role === 'PLAYER'}
155+
onChange={() => setRole('PLAYER')}
156+
/>
157+
<Image src='/jogador-icon.svg' alt='Player' width={40} height={40} className={styles.roleImage} />
158+
<span className={styles.roleLabel}>Jogador</span>
159+
</label>
160+
</div>
161+
</div>
171162

172-
{error && (
173-
<p style={{ color: 'red', textAlign: 'center', marginTop: '1rem' }}>
174-
{error}
175-
</p>
176-
)}
163+
{error && <p style={{ color: 'red', textAlign: 'center', marginTop: '1rem' }}>{error}</p>}
177164

178-
<button type="submit" className={styles.submitButton} disabled={loading}>
179-
{loading ? 'CADASTRANDO...' : 'CADASTRAR-SE'}
180-
</button>
165+
<button type='submit' className={styles.submitButton} disabled={loading}>
166+
{loading ? 'CADASTRANDO...' : 'CADASTRAR-SE'}
167+
</button>
181168

182-
<p className={styles.AccountNew}>
183-
<Link href="/login">Já tem uma conta?</Link>
184-
</p>
185-
</form>
186-
</div>
187-
</div>
188-
</div>
189-
</div>
190-
)
169+
<p className={styles.AccountNew}>
170+
<Link href='/login'>Já tem uma conta?</Link>
171+
</p>
172+
</form>
173+
</div>
174+
</div>
175+
</div>
176+
</div>
177+
)
191178
}

0 commit comments

Comments
 (0)