AxL95 commited on
Commit
ef66196
·
verified ·
1 Parent(s): c9d0942

Update frontend/src/components/Signin.jsx

Browse files
Files changed (1) hide show
  1. frontend/src/components/Signin.jsx +76 -76
frontend/src/components/Signin.jsx CHANGED
@@ -1,76 +1,76 @@
1
- import React, { useState } from 'react'
2
- import '../login.css';
3
-
4
- function Signin({toLogin}) {
5
- const [formData, setFormData] = useState({
6
- prenom: '',
7
- nom: '',
8
- email: '',
9
- password: '', // Changé de password_hash à password pour correspondre à l'API
10
- });
11
-
12
- const handleChange = (e) => {
13
- setFormData({...formData, [e.target.name]: e.target.value});
14
- };
15
-
16
- const handleSubmit = async (e) => {
17
- e.preventDefault();
18
- try {
19
- const res = await fetch("/.netlify/functions/register", {
20
- method: "POST",
21
- headers: {
22
- "Content-Type": "application/json"
23
- },
24
- body: JSON.stringify(formData)
25
- });
26
-
27
- if (res.ok) {
28
- const data = await res.json();
29
- console.log(data);
30
- toLogin();
31
- } else {
32
- const errorData = await res.json().catch(() => ({}));
33
- alert(errorData.detail || "Erreur d'inscription");
34
- }
35
- } catch (error) {
36
- console.error("Erreur lors de l'inscription", error);
37
- }
38
- };
39
-
40
- return (
41
- <div className='login'>
42
- <h1 className='title-1'>Bienvenue sur Medic.ial !</h1>
43
- <div className="container">
44
- <div className='container-form'>
45
- <form action="" className='form' onSubmit={handleSubmit}>
46
- <h3>INSCRIPTION</h3>
47
- <div className='form-container-name'>
48
- <div>
49
- <p className='form-title'>Prénom</p>
50
- <input type='text' name="prenom" onChange={handleChange} value={formData.prenom} className='form-input'/>
51
- </div>
52
- <div>
53
- <p className='form-title'>Nom</p>
54
- <input type='text' name="nom" onChange={handleChange} value={formData.nom} className='form-input'/>
55
- </div>
56
- </div>
57
- <div className='form-container-input'>
58
- <p className='form-title'>Adresse email</p>
59
- <input type='email' name="email" onChange={handleChange} value={formData.email} className='form-input'/>
60
- </div>
61
- <div className='form-container-input'>
62
- <p className='form-title'>Mot de passe</p>
63
- <input type='password' name="password" onChange={handleChange} value={formData.password} className='form-input'/>
64
- </div>
65
- <div className='form-container-submit'>
66
- <button type="submit">Inscription</button>
67
- </div>
68
- </form>
69
- </div>
70
- </div>
71
- <p className='title-2'>Déjà un compte ? <span onClick={toLogin}>Se connecter</span></p>
72
- </div>
73
- )
74
- }
75
-
76
- export default Signin
 
1
+ import React, { useState } from 'react'
2
+ import '../login.css';
3
+
4
+ function Signin({toLogin}) {
5
+ const [formData, setFormData] = useState({
6
+ prenom: '',
7
+ nom: '',
8
+ email: '',
9
+ password: '', // Changé de password_hash à password pour correspondre à l'API
10
+ });
11
+
12
+ const handleChange = (e) => {
13
+ setFormData({...formData, [e.target.name]: e.target.value});
14
+ };
15
+
16
+ const handleSubmit = async (e) => {
17
+ e.preventDefault();
18
+ try {
19
+ const res = await fetch("/api/register", {
20
+ method: "POST",
21
+ headers: {
22
+ "Content-Type": "application/json"
23
+ },
24
+ body: JSON.stringify(formData)
25
+ });
26
+
27
+ if (res.ok) {
28
+ const data = await res.json();
29
+ console.log(data);
30
+ toLogin();
31
+ } else {
32
+ const errorData = await res.json().catch(() => ({}));
33
+ alert(errorData.detail || "Erreur d'inscription");
34
+ }
35
+ } catch (error) {
36
+ console.error("Erreur lors de l'inscription", error);
37
+ }
38
+ };
39
+
40
+ return (
41
+ <div className='login'>
42
+ <h1 className='title-1'>Bienvenue sur Medic.ial !</h1>
43
+ <div className="container">
44
+ <div className='container-form'>
45
+ <form action="" className='form' onSubmit={handleSubmit}>
46
+ <h3>INSCRIPTION</h3>
47
+ <div className='form-container-name'>
48
+ <div>
49
+ <p className='form-title'>Prénom</p>
50
+ <input type='text' name="prenom" onChange={handleChange} value={formData.prenom} className='form-input'/>
51
+ </div>
52
+ <div>
53
+ <p className='form-title'>Nom</p>
54
+ <input type='text' name="nom" onChange={handleChange} value={formData.nom} className='form-input'/>
55
+ </div>
56
+ </div>
57
+ <div className='form-container-input'>
58
+ <p className='form-title'>Adresse email</p>
59
+ <input type='email' name="email" onChange={handleChange} value={formData.email} className='form-input'/>
60
+ </div>
61
+ <div className='form-container-input'>
62
+ <p className='form-title'>Mot de passe</p>
63
+ <input type='password' name="password" onChange={handleChange} value={formData.password} className='form-input'/>
64
+ </div>
65
+ <div className='form-container-submit'>
66
+ <button type="submit">Inscription</button>
67
+ </div>
68
+ </form>
69
+ </div>
70
+ </div>
71
+ <p className='title-2'>Déjà un compte ? <span onClick={toLogin}>Se connecter</span></p>
72
+ </div>
73
+ )
74
+ }
75
+
76
+ export default Signin