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

Profil updated #110

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Changes from all commits
Commits
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
30 changes: 22 additions & 8 deletions frontend/src/pages/Profil.jsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { useState, useEffect } from "react";
import { useEffect, useState } from "react";
import axios from "axios";

import addimage from "../assets/addimage.svg";
import "./style/Profil.scss";

function Profil() {
const [editing, setEditing] = useState(false);
const [recipeBy, setRecipeBy] = useState([]);
const [userData, setUserData] = useState({
username: null,
firstname: null,
Expand All @@ -19,8 +20,9 @@ function Profil() {
};

const handleKeepClick = () => {
const params = { id: "value" };
axios
.get(`${import.meta.env.VITE_BACKEND_URL}/api/users/8`, {
.get(`${import.meta.env.VITE_BACKEND_URL}/api/users/${params.id}`, {
withCredentials: true,
})
.then((res) => {
Expand All @@ -33,9 +35,10 @@ function Profil() {
};

const handleSaveClick = () => {
const params = { id: "value" };
axios
.put(
`${import.meta.env.VITE_BACKEND_URL}/api/users/8`,
`${import.meta.env.VITE_BACKEND_URL}/api/users/${params.id}`,
{
username: userData.username,
description: userData.description,
Expand Down Expand Up @@ -64,16 +67,19 @@ function Profil() {
};

useEffect(() => {
const endpoints = [`${import.meta.env.VITE_BACKEND_URL}/api/users`];
const params = { id: "value" };
const endpoints = [
`${import.meta.env.VITE_BACKEND_URL}/api/recipebyuser/${params.id}`,
];
Promise.all(
endpoints.map((endpoint) =>
axios.get(endpoint, {
withCredentials: true,
})
)
)
.then(([{ data: user }]) => {
setUserData(user);
.then(([{ data: recipebyuser }]) => {
setRecipeBy(recipebyuser);
})
.catch((erreur) => {
console.error(erreur);
Expand Down Expand Up @@ -161,8 +167,16 @@ function Profil() {
) : (
<label>{userData.description || "Ma description..."}</label>
)}
<p className="recipes">Mes recettes : {userData.recipes}</p>
<p className="comments">Commentaires: {userData.comments}</p>
<p className="recipes">
Mes recettes :{" "}
{recipeBy &&
recipeBy.map((recipeU) => (
<li key={recipeU.user_id}>
{recipeU.name} {recipeU.title}
</li>
))}
</p>
<p className="comments">Commentaires: </p>
</div>
<button
className="Edit"
Expand Down
Loading