1- import { useState } from 'react' ;
2- import { Button , Checkbox , Input , Layout } from 'antd' ;
3- import axios from 'axios' ;
4- import router from 'next/router' ;
5- import { API_URL } from "@/config/config" ;
6-
7- const { Content } = Layout ;
8-
9- const Cadastro = ( ) => {
10- const [ email , setEmail ] = useState ( '' ) ;
11- const [ password , setPassword ] = useState ( '' ) ;
12- const [ nomeUsuario , setNomeUsuario ] = useState ( '' ) ;
13- const [ isProfessor , setIsProfessor ] = useState ( false ) ;
14- const [ isAluno , setIsAluno ] = useState ( false ) ;
15- const [ tipoUsuario , setTipoUsuario ] = useState ( '' ) ;
16-
17-
18- const handleCheckboxChange = ( type : string ) => {
19- console . log ( 'type' , type )
20- if ( type === 'professor' ) {
21- setIsProfessor ( ! isProfessor ) ;
22- setIsAluno ( false ) ;
23- setTipoUsuario ( type ) ;
24- } else if ( type === 'aluno' ) {
25- setIsAluno ( ! isAluno ) ;
26- setIsProfessor ( false ) ;
27- setTipoUsuario ( type ) ;
28- }
29- } ;
30-
31- const handleCadastro = async ( ) => {
32- try {
33- await axios . post ( `${ API_URL } /userRegister` , {
34- email,
35- password,
36- nomeUsuario,
37- tipoUsuario
38- } ) ;
39- console . log ( 'Usuário cadastrado com sucesso!' ) ;
40- setEmail ( '' ) ;
41- setPassword ( '' ) ;
42- setTipoUsuario ( '' ) ;
43- setNomeUsuario ( '' ) ;
44- router . push ( '/quintana /login' ) ;
45- } catch ( error ) {
46- console . error ( 'Erro ao cadastrar usuário:' , error ) ;
47- }
48- }
49-
50- const isDisabled = ! isProfessor && ! isAluno ;
51-
52- return (
53- < Layout style = { { minHeight : '50vh' , display : 'flex' , justifyContent : 'center' , alignItems : 'center' } } >
54- < Content style = { { padding : '20px' , borderRadius : '8px' , boxShadow : '0 4px 8px rgba(0,0,0,0.1)' , width : '300px' } } >
55- < div style = { { marginBottom : '20px' , textAlign : 'center' } } >
56- < h2 > Cadastro</ h2 >
57- </ div >
58- < div style = { { marginBottom : '20px' } } >
59- < Checkbox
60- style = { { marginLeft : '50px' } }
61- checked = { isProfessor }
62- onChange = { ( ) => handleCheckboxChange ( 'professor' ) }
63- >
64- Professor
65- </ Checkbox >
66- < Checkbox
67- checked = { isAluno }
68- onChange = { ( ) => handleCheckboxChange ( 'aluno' ) }
69- >
70- Aluno
71- </ Checkbox >
72- </ div >
73- < div style = { { marginBottom : '20px' } } >
74- < Input
75- placeholder = "Email"
76- value = { email }
77- onChange = { e => setEmail ( e . target . value ) }
78- disabled = { isDisabled }
79- />
80- </ div >
81- < div style = { { marginBottom : '20px' } } >
82- < Input
83- placeholder = "Nome de usuário"
84- value = { nomeUsuario }
85- onChange = { e => setNomeUsuario ( e . target . value ) }
86- disabled = { isDisabled }
87- />
88- </ div >
89- < div style = { { marginBottom : '20px' } } >
90- < Input . Password
91- placeholder = "Senha"
92- value = { password }
93- onChange = { e => setPassword ( e . target . value ) }
94- disabled = { isDisabled }
95- />
96- </ div >
97- < div style = { { textAlign : 'center' } } >
98- < Button onClick = { handleCadastro } type = "primary" > Entrar</ Button >
99- </ div >
100- </ Content >
101- </ Layout >
102- ) ;
103- } ;
104-
1+ import { useState } from 'react' ;
2+ import { Button , Checkbox , Input , Layout } from 'antd' ;
3+ import axios from 'axios' ;
4+ import router from 'next/router' ;
5+ import { API_URL } from "@/config/config" ;
6+
7+ const { Content } = Layout ;
8+
9+ const Cadastro = ( ) => {
10+ const [ email , setEmail ] = useState ( '' ) ;
11+ const [ password , setPassword ] = useState ( '' ) ;
12+ const [ nomeUsuario , setNomeUsuario ] = useState ( '' ) ;
13+ const [ isProfessor , setIsProfessor ] = useState ( false ) ;
14+ const [ isAluno , setIsAluno ] = useState ( false ) ;
15+ const [ tipoUsuario , setTipoUsuario ] = useState ( '' ) ;
16+
17+
18+ const handleCheckboxChange = ( type : string ) => {
19+ console . log ( 'type' , type )
20+ if ( type === 'professor' ) {
21+ setIsProfessor ( ! isProfessor ) ;
22+ setIsAluno ( false ) ;
23+ setTipoUsuario ( type ) ;
24+ } else if ( type === 'aluno' ) {
25+ setIsAluno ( ! isAluno ) ;
26+ setIsProfessor ( false ) ;
27+ setTipoUsuario ( type ) ;
28+ }
29+ } ;
30+
31+ const handleCadastro = async ( ) => {
32+ try {
33+ await axios . post ( `${ API_URL } /userRegister` , {
34+ email,
35+ password,
36+ nomeUsuario,
37+ tipoUsuario
38+ } ) ;
39+ console . log ( 'Usuário cadastrado com sucesso!' ) ;
40+ setEmail ( '' ) ;
41+ setPassword ( '' ) ;
42+ setTipoUsuario ( '' ) ;
43+ setNomeUsuario ( '' ) ;
44+ router . push ( '/lumen /login' ) ;
45+ } catch ( error ) {
46+ console . error ( 'Erro ao cadastrar usuário:' , error ) ;
47+ }
48+ }
49+
50+ const isDisabled = ! isProfessor && ! isAluno ;
51+
52+ return (
53+ < Layout style = { { minHeight : '50vh' , display : 'flex' , justifyContent : 'center' , alignItems : 'center' } } >
54+ < Content style = { { padding : '20px' , borderRadius : '8px' , boxShadow : '0 4px 8px rgba(0,0,0,0.1)' , width : '300px' } } >
55+ < div style = { { marginBottom : '20px' , textAlign : 'center' } } >
56+ < h2 > Cadastro</ h2 >
57+ </ div >
58+ < div style = { { marginBottom : '20px' } } >
59+ < Checkbox
60+ style = { { marginLeft : '50px' } }
61+ checked = { isProfessor }
62+ onChange = { ( ) => handleCheckboxChange ( 'professor' ) }
63+ >
64+ Professor
65+ </ Checkbox >
66+ < Checkbox
67+ checked = { isAluno }
68+ onChange = { ( ) => handleCheckboxChange ( 'aluno' ) }
69+ >
70+ Aluno
71+ </ Checkbox >
72+ </ div >
73+ < div style = { { marginBottom : '20px' } } >
74+ < Input
75+ placeholder = "Email"
76+ value = { email }
77+ onChange = { e => setEmail ( e . target . value ) }
78+ disabled = { isDisabled }
79+ />
80+ </ div >
81+ < div style = { { marginBottom : '20px' } } >
82+ < Input
83+ placeholder = "Nome de usuário"
84+ value = { nomeUsuario }
85+ onChange = { e => setNomeUsuario ( e . target . value ) }
86+ disabled = { isDisabled }
87+ />
88+ </ div >
89+ < div style = { { marginBottom : '20px' } } >
90+ < Input . Password
91+ placeholder = "Senha"
92+ value = { password }
93+ onChange = { e => setPassword ( e . target . value ) }
94+ disabled = { isDisabled }
95+ />
96+ </ div >
97+ < div style = { { textAlign : 'center' } } >
98+ < Button onClick = { handleCadastro } type = "primary" > Entrar</ Button >
99+ </ div >
100+ </ Content >
101+ </ Layout >
102+ ) ;
103+ } ;
104+
105105export default Cadastro ;
0 commit comments