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

Revert "image profil a fix css" #118

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
65 changes: 19 additions & 46 deletions frontend/src/pages/Profil.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,20 @@ import axios from "axios";

import Recipe from "./Recipe";
import "./style/RecipeList.scss";

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

function Profil() {
const [id, setId] = useState();
const [editing, setEditing] = useState(false);
const [recipeBy, setRecipeBy] = useState([]);
const [userData, setUserData] = useState({
avatar: null,
username: null,
firstname: null,
lastname: null,
birthdate: null,
description: null,
});
const [selectedFile, setSelectedFile] = useState(null);
const [selectedFileUrl, setselectedFileUrl] = useState(null);
const [fav, setFav] = useState([]);

const handleEditClick = () => {
Expand Down Expand Up @@ -76,27 +73,23 @@ function Profil() {
}
}, [id]);

const handleSaveClick = async () => {
try {
const formData = new FormData();
formData.append("avatar", selectedFile);
formData.append("name", userData.recipeName);
formData.append("title", userData.recipeDesc);
formData.append("prep_time", userData.prepTime);
formData.append("nb_people", userData.nbPeople);
formData.append("difficulty", userData.difficulty);

await axios
.put(`${import.meta.env.VITE_BACKEND_URL}/api/users/${id}`, formData, {
withCredentials: true,
})
.then(() => {
setEditing(false);
});
setEditing(false);
} catch (err) {
console.error(err);
}
const handleSaveClick = () => {
axios
.put(
`${import.meta.env.VITE_BACKEND_URL}/api/users/${id}`,
{
username: userData.username,
description: userData.description,
firstname: userData.firstname,
lastname: userData.lastname,
birthdate: userData.birthdate,
},
{ withCredentials: true }
)
.then(() => {
setEditing(false);
});
setEditing(false);
};

const handleChange = (e) => {
Expand All @@ -106,33 +99,13 @@ function Profil() {
[name]: value,
}));
};
const handleFileInput = (e) => {
setSelectedFile(e.target.files[0]);
};
const handleImageUpload = (e) => {
if (e.target.files && e.target.files[0]) {
const imgFile = e.target.files[0];
setselectedFileUrl(URL.createObjectURL(imgFile));
}
};

const combineImagehandler = (e) => {
handleFileInput(e);
handleImageUpload(e);
};
const imageUrl = `${import.meta.env.VITE_BACKEND_URL}/${userData.avatar}`;

return (
<div className="body-content" style={{ flexDirection: "column" }}>
<div className="Profil_container">
<div className="first">
<div className="left-bloc">
<input type="file" onChange={combineImagehandler} />
{selectedFileUrl ? (
<img src={selectedFileUrl} alt="Preview" />
) : (
<img src={imageUrl} alt="vide" /> || "photo de profil"
)}
<img className="No-photo" src={addimage} alt="No Photos" />
</div>
<div className="right-bloc">
<label className="stats-label">
Expand Down
Loading