Browse Source

En cours : update des users

Lou 3 years ago
parent
commit
5d475167eb

+ 1
- 1
src/components/forms/SignupForm/index.jsx View File

@@ -45,7 +45,7 @@ const SignupForm = () => {
45 45
 
46 46
 	useEffect(async () => {
47 47
 		if (passwordCheck === false) {
48
-			console.log("Passwords do not match");
48
+			console.log("Passwords do not match"); // À afficher autrement
49 49
 		} else if (passwordCheck === true && userData) {
50 50
 			const response = await handleSignup(userData);
51 51
 			if (response.status && response.status === 201) {

+ 27
- 0
src/components/forms/UserUpdateForm/index.jsx View File

@@ -0,0 +1,27 @@
1
+import React from "react";
2
+import { useSelector } from "react-redux";
3
+
4
+const UserUpdateForm = () => {
5
+	const currentUser = useSelector((state) => state.currentUser);
6
+
7
+	const handleSubmit = (event) => {
8
+		event.preventDefault();
9
+		const formdata = new FormData(event.currentTarget);
10
+	};
11
+
12
+	return (
13
+		<form action="" onSubmit={handleSubmit}>
14
+			<label htmlFor="username">Nom d'utilisateur</label>
15
+			<input type="text" id="username" name="username" />
16
+			<label htmlFor="email">Adresse email</label>
17
+			<input type="email" id="email" name="email" />
18
+			<label htmlFor="password">Mot de passe</label>
19
+			<input type="password" id="password" name="password" />
20
+			<label htmlFor="confirm_password">Confirmation du mot de passe</label>
21
+			<input type="password" id="confirm_password" name="confirm_password" />
22
+			<button type="submit">Valider</button>
23
+		</form>
24
+	);
25
+};
26
+
27
+export default UserUpdateForm;

+ 19
- 0
src/pages/Profile/index.jsx View File

@@ -5,9 +5,11 @@ import Cookies from "js-cookie";
5 5
 
6 6
 import del from "../../services/request/Delete";
7 7
 import { removeCurrentUser } from "../../redux/action/index";
8
+import UserUpdateForm from "../../components/forms/UserUpdateForm";
8 9
 
9 10
 const ProfilePage = () => {
10 11
 	const [deleteSuccess, setDeleteSuccess] = useState(null);
12
+	const [settings, setSettings] = useState(false);
11 13
 	const currentUser = useSelector((state) => state.currentUser);
12 14
 
13 15
 	const dispatch = useDispatch();
@@ -23,6 +25,14 @@ const ProfilePage = () => {
23 25
 		}
24 26
 	};
25 27
 
28
+	const toogleSettings = () => {
29
+		if (settings === false) {
30
+			setSettings(true);
31
+		} else {
32
+			setSettings(false);
33
+		}
34
+	};
35
+
26 36
 	useEffect(() => {
27 37
 		if (deleteSuccess && deleteSuccess === true) {
28 38
 			Cookies.remove("token");
@@ -39,6 +49,15 @@ const ProfilePage = () => {
39 49
 		<div>
40 50
 			<h1>Hello {currentUser.username}</h1>
41 51
 			<button onClick={handleDelete}>Supprimer le compte</button>
52
+			<button onClick={toogleSettings}>Mettre à jour les informations</button>
53
+			{settings === true ? (
54
+				<div className="truc">
55
+					<h2>Modifiez vos informations :</h2>
56
+					<UserUpdateForm />
57
+				</div>
58
+			) : (
59
+				<> </>
60
+			)}
42 61
 		</div>
43 62
 	);
44 63
 };

+ 23
- 0
src/services/request/Update.js View File

@@ -0,0 +1,23 @@
1
+import axios from 'axios';
2
+import { BASE_URL } from "./config.js";
3
+
4
+const update = async (
5
+  endpoint,
6
+  body = null,
7
+  jwt_token = null,
8
+  header = { "Content-Type": "application/json" }) => {
9
+
10
+  let opt = header;
11
+  if (jwt_token){
12
+      opt["Authorization"] = jwt_token
13
+  }
14
+
15
+  try {
16
+    const response = await axios.patch(BASE_URL + endpoint, body, { headers: opt })
17
+    return response
18
+  } catch (err) {
19
+    console.error(`An error occurred while trying to fetch ${endpoint}. ${err}`);
20
+  }
21
+}
22
+
23
+export default update;

Loading…
Cancel
Save