$
This commit is contained in:
parent
66d5b3d533
commit
bc0c68282a
src
api
assets/styles
components/AddBtn
pages
@ -18,3 +18,23 @@ export const createItem = async (settings) => {
|
|||||||
|
|
||||||
return response.data;
|
return response.data;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const updateItem = async (settings) => {
|
||||||
|
console.log(settings);
|
||||||
|
|
||||||
|
const formData = new FormData();
|
||||||
|
formData.append("brand", settings.brand);
|
||||||
|
formData.append("model", settings.model);
|
||||||
|
formData.append("price", settings.price);
|
||||||
|
formData.append("purchaseDate", settings.purchaseDate);
|
||||||
|
formData.append("link", settings.link);
|
||||||
|
|
||||||
|
const response = await axios.put(`/item/${settings._id}`, formData);
|
||||||
|
return response.data;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const deleteItem = async (id) => {
|
||||||
|
console.log(id);
|
||||||
|
const response = await axios.delete(`/item/${id}`);
|
||||||
|
return response.data;
|
||||||
|
};
|
||||||
|
@ -1,14 +1,17 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
export const createUser = async (username, password, confirmation) => {
|
export const createUser = async (username, password, confirmation) => {
|
||||||
try {
|
try {
|
||||||
const response = await axios.post("/user", {
|
const response = await axios.post("/user", {
|
||||||
username,
|
username,
|
||||||
password,
|
password,
|
||||||
confirmation,
|
confirmation,
|
||||||
});
|
});
|
||||||
return response.data;
|
return response.data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
return error.response.data;
|
return error.response.data;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// TODO: REgarde postman
|
||||||
|
export const updateUser = 0;
|
||||||
|
@ -4,6 +4,10 @@ body {
|
|||||||
}
|
}
|
||||||
|
|
||||||
* {
|
* {
|
||||||
|
a {
|
||||||
|
color: rgb(123, 106, 156);
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 0;
|
padding: 0;
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
.add-btn-container {
|
.add-btn-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
position: absolute;
|
position: fixed;
|
||||||
bottom: 20px;
|
bottom: 20px;
|
||||||
right: 20px;
|
right: 20px;
|
||||||
width: 45px;
|
width: 45px;
|
||||||
@ -15,5 +15,11 @@
|
|||||||
color: white;
|
color: white;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
font-size: 15px;
|
font-size: 15px;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
transform: scale(1.05);
|
||||||
|
transition: 0.2s;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,50 +1,93 @@
|
|||||||
import { useAuth } from "../../hooks";
|
import { useAuth } from "../../hooks";
|
||||||
|
import { useState } from "react";
|
||||||
import "./Profile.scss";
|
import "./Profile.scss";
|
||||||
//Bilouuuuuuu94!@@
|
//Bilouuuuuuu94!@@
|
||||||
|
|
||||||
export default function Profile() {
|
export default function Profile() {
|
||||||
const { user } = useAuth();
|
const { user } = useAuth();
|
||||||
|
const [username, setUsername] = useState("");
|
||||||
|
const [oldPUsername, setOldPUsername] = useState("");
|
||||||
|
|
||||||
return (
|
const [oldPPassword, setOldPPassword] = useState("");
|
||||||
<div id="profile-container">
|
const [password, setPassword] = useState("");
|
||||||
<div id="title-container">
|
const [confirmPassword, setConfirmPassword] = useState("");
|
||||||
<h3 id="title">
|
|
||||||
Heureux de vous voir <b>{user.user.username}</b> !
|
|
||||||
</h3>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="profile-modifier-container">
|
const handleUsername = (e) => {
|
||||||
<span className="profile-modifier-title">
|
setUsername(e.target.value);
|
||||||
Change ton pseudo
|
};
|
||||||
</span>
|
const handlePassword = (e) => {
|
||||||
|
setPassword(e.target.value);
|
||||||
|
};
|
||||||
|
const handleConfirmPassword = (e) => {
|
||||||
|
setConfirmPassword(e.target.value);
|
||||||
|
};
|
||||||
|
const handleOldPUsername = (e) => {
|
||||||
|
setOldPUsername(e.target.value);
|
||||||
|
};
|
||||||
|
const handleOldPPassword = (e) => {
|
||||||
|
setOldPPassword(e.target.value);
|
||||||
|
};
|
||||||
|
|
||||||
<input
|
// TODO: Faire la paire de fonction
|
||||||
className="profile-modifier-ipt"
|
const handleSubmitPassword = () => {};
|
||||||
type="text"
|
const handleSubmitUsername = () => {};
|
||||||
placeholder="Nouveau nom"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<button>OK</button>
|
return (
|
||||||
</div>
|
<div id="profile-container">
|
||||||
|
<div id="title-container">
|
||||||
|
<h3 id="title">
|
||||||
|
Heureux de vous voir <b>{user.user.username}</b> !
|
||||||
|
</h3>
|
||||||
|
|
||||||
<div className="profile-modifier-container">
|
<button onClick={null}>Supprimer mon compte</button>
|
||||||
<span className="profile-modifier-title">
|
</div>
|
||||||
Change ton mot de passe
|
|
||||||
</span>
|
|
||||||
|
|
||||||
<input
|
<div className="profile-modifier-container">
|
||||||
className="profile-modifier-ipt"
|
<span className="profile-modifier-title">Change ton pseudo</span>
|
||||||
type="password"
|
|
||||||
placeholder="Nouveau mot de passe"
|
|
||||||
/>
|
|
||||||
<input
|
|
||||||
className="profile-modifier-ipt"
|
|
||||||
type="password"
|
|
||||||
placeholder="Confirmation"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<button>OK</button>
|
<input
|
||||||
</div>
|
className="profile-modifier-ipt"
|
||||||
</div>
|
type="password"
|
||||||
);
|
placeholder="Ancien mot de passe"
|
||||||
|
onChange={handleOldPUsername}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<input
|
||||||
|
className="profile-modifier-ipt"
|
||||||
|
type="text"
|
||||||
|
placeholder="Nouveau nom"
|
||||||
|
onChange={handleUsername}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<button>OK</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="profile-modifier-container">
|
||||||
|
<span className="profile-modifier-title">Change ton mot de passe</span>
|
||||||
|
|
||||||
|
<input
|
||||||
|
className="profile-modifier-ipt"
|
||||||
|
type="password"
|
||||||
|
placeholder="Ancien mot de passe"
|
||||||
|
onChange={handleOldPPassword}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<input
|
||||||
|
className="profile-modifier-ipt"
|
||||||
|
type="password"
|
||||||
|
placeholder="Nouveau mot de passe"
|
||||||
|
onChange={handlePassword}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<input
|
||||||
|
className="profile-modifier-ipt"
|
||||||
|
type="password"
|
||||||
|
placeholder="Confirmation"
|
||||||
|
onChange={handleConfirmPassword}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<button>OK</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
@ -12,8 +12,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.profile-modifier-container {
|
.profile-modifier-container {
|
||||||
border: 1px dashed black;
|
border: 1px dashed rgb(61, 61, 61);
|
||||||
width: 500px;
|
width: 450px;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
@ -21,8 +21,12 @@
|
|||||||
align-items: center;
|
align-items: center;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
|
|
||||||
|
@media (max-width: 770px) {
|
||||||
|
width: 80%;
|
||||||
|
}
|
||||||
|
|
||||||
.profile-modifier-title {
|
.profile-modifier-title {
|
||||||
color: rgb(70, 70, 70);
|
color: rgb(49, 49, 49);
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,24 +3,73 @@ import { useState, useEffect } from "react";
|
|||||||
import { getRoom } from "../../api";
|
import { getRoom } from "../../api";
|
||||||
import "./Room.scss";
|
import "./Room.scss";
|
||||||
import AddBtn from "../../components/AddBtn/AddBtn";
|
import AddBtn from "../../components/AddBtn/AddBtn";
|
||||||
import { createItem } from "../../api/";
|
import { createItem, deleteItem, updateItem } from "../../api/";
|
||||||
|
|
||||||
export default function Room() {
|
export default function Room() {
|
||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
const [data, setData] = useState({});
|
const [data, setData] = useState({});
|
||||||
const [isInForm, setInForm] = useState(false);
|
const [isInForm, setInForm] = useState(false);
|
||||||
|
const [isInFormUpdate, setIsInFormUpdate] = useState(false);
|
||||||
|
const [formUpdateData, setFormUpdateData] = useState(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getRoom(id).then((res) => {
|
getRoom(id).then((res) => {
|
||||||
console.log(res);
|
|
||||||
setData(res);
|
setData(res);
|
||||||
});
|
});
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const handleFormUpdateDataChange = (e, name) => {
|
||||||
|
const cpy = { ...formUpdateData };
|
||||||
|
cpy[name] =
|
||||||
|
name === "purchaseDate"
|
||||||
|
? new Date(e.target.value).toISOString()
|
||||||
|
: e.target.value;
|
||||||
|
setFormUpdateData(cpy);
|
||||||
|
};
|
||||||
|
|
||||||
const handleForm = () => {
|
const handleForm = () => {
|
||||||
setInForm(!isInForm);
|
setInForm(!isInForm);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const handleFormUpdate = (item = null) => {
|
||||||
|
if (item) {
|
||||||
|
const cpy = { ...item };
|
||||||
|
delete cpy.createdAt;
|
||||||
|
delete cpy.image;
|
||||||
|
delete cpy.invoice;
|
||||||
|
delete cpy.user;
|
||||||
|
delete cpy.updatedAt;
|
||||||
|
delete cpy.__v;
|
||||||
|
delete cpy.description;
|
||||||
|
setFormUpdateData(cpy);
|
||||||
|
}
|
||||||
|
|
||||||
|
setIsInFormUpdate(!isInFormUpdate);
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleDelete = (id) => {
|
||||||
|
deleteItem(id).then((_) => {
|
||||||
|
const cpy = [...data.items];
|
||||||
|
const filtered = cpy.filter((e) => e._id !== id);
|
||||||
|
setData({ ...data, items: filtered });
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
const handleSubmitUpdate = () => {
|
||||||
|
try {
|
||||||
|
updateItem(formUpdateData).then((_) => {
|
||||||
|
// TODO: Je ferai une modification unitaire plus tard
|
||||||
|
getRoom(id).then((res) => {
|
||||||
|
handleFormUpdate();
|
||||||
|
setData(res);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
handleFormUpdate();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleSubmit = (e) => {
|
const handleSubmit = (e) => {
|
||||||
try {
|
try {
|
||||||
const settings = {};
|
const settings = {};
|
||||||
@ -34,8 +83,10 @@ export default function Room() {
|
|||||||
settings.image = e.target[6].files[0];
|
settings.image = e.target[6].files[0];
|
||||||
settings.invoice = e.target[7].files[0];
|
settings.invoice = e.target[7].files[0];
|
||||||
|
|
||||||
createItem(settings).then((res) => {
|
createItem(settings).then((_) => {
|
||||||
console.log(res);
|
// Je prefere faire ca que d'actualiser le state[data.items] car
|
||||||
|
// l'image ne se charge pas correctement
|
||||||
|
window.location.reload();
|
||||||
});
|
});
|
||||||
|
|
||||||
handleForm();
|
handleForm();
|
||||||
@ -59,15 +110,32 @@ export default function Room() {
|
|||||||
<div id="items-container">
|
<div id="items-container">
|
||||||
{data.items.map((e, i) => (
|
{data.items.map((e, i) => (
|
||||||
<div className="item-container" key={i}>
|
<div className="item-container" key={i}>
|
||||||
|
<div id="item-actions-container">
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
handleDelete(e._id);
|
||||||
|
}}
|
||||||
|
id="item-delete-btn"
|
||||||
|
>
|
||||||
|
×
|
||||||
|
</button>
|
||||||
|
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
handleFormUpdate(e);
|
||||||
|
}}
|
||||||
|
id="item-update-btn"
|
||||||
|
>
|
||||||
|
✏️
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
<div className="item-brand-container">
|
<div className="item-brand-container">
|
||||||
Marque
|
|
||||||
<a className="item-brand" href={e.link}>
|
<a className="item-brand" href={e.link}>
|
||||||
{e.brand}
|
{e.brand}
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="item-model-container">
|
<div className="item-model-container">
|
||||||
Modele
|
|
||||||
<a className="item-model" href={e.link}>
|
<a className="item-model" href={e.link}>
|
||||||
{e.model}
|
{e.model}
|
||||||
</a>
|
</a>
|
||||||
@ -86,19 +154,18 @@ export default function Room() {
|
|||||||
)}
|
)}
|
||||||
|
|
||||||
<div className="item-description-container">
|
<div className="item-description-container">
|
||||||
Description
|
Description ➜
|
||||||
<span className="item-description"> {e.description}</span>
|
<span className="item-description"> {e.description}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="item-price-container">
|
<div className="item-price-container">
|
||||||
Montant
|
Montant ➜<span className="item-price"> {e.price}$</span>
|
||||||
<span className="item-price"> {e.price}$</span>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="item-buy-date-container">
|
<div className="item-buy-date-container">
|
||||||
Date d'achat
|
Date d'achat ➜
|
||||||
<span className="item-buy-date">
|
<span className="item-buy-date">
|
||||||
{new Date(e.purchaseDate).toDateString()}
|
{new Date(e.purchaseDate).toLocaleDateString("FR-fr")}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -131,7 +198,9 @@ export default function Room() {
|
|||||||
<input type="file" placeholder="Facture ..." />
|
<input type="file" placeholder="Facture ..." />
|
||||||
|
|
||||||
<div id="actions">
|
<div id="actions">
|
||||||
<button className="actions-btn">Annuler</button>
|
<button className="actions-btn" onClick={handleForm}>
|
||||||
|
Annuler
|
||||||
|
</button>
|
||||||
<button className="actions-btn" type="submit">
|
<button className="actions-btn" type="submit">
|
||||||
Confirmer
|
Confirmer
|
||||||
</button>
|
</button>
|
||||||
@ -140,6 +209,69 @@ export default function Room() {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{isInFormUpdate && (
|
||||||
|
<div id="form-update-container">
|
||||||
|
<span>
|
||||||
|
Modification de{" "}
|
||||||
|
<b>
|
||||||
|
{formUpdateData.brand} {formUpdateData.model}
|
||||||
|
</b>
|
||||||
|
</span>
|
||||||
|
|
||||||
|
<div id="form-closure-container">
|
||||||
|
<button id="form-closure" onClick={handleFormUpdate}>
|
||||||
|
×
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div id="form-update">
|
||||||
|
<input
|
||||||
|
onChange={(e) => {
|
||||||
|
handleFormUpdateDataChange(e, "brand");
|
||||||
|
}}
|
||||||
|
type="text"
|
||||||
|
placeholder={formUpdateData.brand}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
onChange={(e) => {
|
||||||
|
handleFormUpdateDataChange(e, "model");
|
||||||
|
}}
|
||||||
|
type="text"
|
||||||
|
placeholder={formUpdateData.model}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
onChange={(e) => {
|
||||||
|
handleFormUpdateDataChange(e, "price");
|
||||||
|
}}
|
||||||
|
type="number"
|
||||||
|
placeholder={formUpdateData.price}
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
onChange={(e) => {
|
||||||
|
handleFormUpdateDataChange(e, "purchaseDate");
|
||||||
|
}}
|
||||||
|
type="date"
|
||||||
|
/>
|
||||||
|
<input
|
||||||
|
onChange={(e) => {
|
||||||
|
handleFormUpdateDataChange(e, "link");
|
||||||
|
}}
|
||||||
|
type="text"
|
||||||
|
placeholder={formUpdateData.link}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<div id="actions">
|
||||||
|
<button className="actions-btn" onClick={handleFormUpdate}>
|
||||||
|
Annuler
|
||||||
|
</button>
|
||||||
|
<button onClick={handleSubmitUpdate} className="actions-btn">
|
||||||
|
Confirmer
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
<AddBtn handle={handleForm} />
|
<AddBtn handle={handleForm} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
@ -19,17 +19,51 @@
|
|||||||
padding: 10px;
|
padding: 10px;
|
||||||
gap: 10px;
|
gap: 10px;
|
||||||
border: 1px dashed rgb(54, 54, 54);
|
border: 1px dashed rgb(54, 54, 54);
|
||||||
width: 340px;
|
width: 370px;
|
||||||
height: 340px;
|
border-radius: 6px;
|
||||||
|
height: 370px;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
|
position: relative;
|
||||||
overflow: auto;
|
overflow: auto;
|
||||||
|
|
||||||
|
#item-actions-container {
|
||||||
|
position: absolute;
|
||||||
|
width: 25px;
|
||||||
|
height: 25px;
|
||||||
|
top: 10px;
|
||||||
|
right: 10px;
|
||||||
|
|
||||||
|
#item-update-btn {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
border-radius: 50px;
|
||||||
|
border: none;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background-color: orange;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#item-delete-btn {
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
border-radius: 50px;
|
||||||
|
border: none;
|
||||||
|
|
||||||
|
&:hover {
|
||||||
|
background: red;
|
||||||
|
color: white;
|
||||||
|
font-weight: bold;
|
||||||
|
cursor: pointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
.item-brand-container {
|
.item-brand-container {
|
||||||
text-align: center;
|
text-align: center;
|
||||||
.item-brand {
|
.item-brand {
|
||||||
color: black;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,26 +72,28 @@
|
|||||||
gap: 5px;
|
gap: 5px;
|
||||||
|
|
||||||
.item-model {
|
.item-model {
|
||||||
color: black;
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.item-image-container {
|
.item-image-container {
|
||||||
width: 200px;
|
width: 100%;
|
||||||
height: auto;
|
height: auto;
|
||||||
|
text-align: center;
|
||||||
|
|
||||||
.item-image {
|
.item-image {
|
||||||
width: 100%;
|
width: 200px;
|
||||||
|
box-shadow: rgba(0, 0, 0, 0.1) 0px 4px 12px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.item-no-img {
|
.item-no-img {
|
||||||
|
color: red;
|
||||||
}
|
}
|
||||||
|
|
||||||
.item-description-container {
|
.item-description-container {
|
||||||
display: flex;
|
display: flex;
|
||||||
width: 100%;
|
|
||||||
gap: 5px;
|
gap: 5px;
|
||||||
|
width: 100%;
|
||||||
|
|
||||||
.item-description {
|
.item-description {
|
||||||
color: black;
|
color: black;
|
||||||
@ -87,15 +123,20 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#form-container {
|
#form-container,
|
||||||
|
#form-update-container {
|
||||||
border: 1px solid black;
|
border: 1px solid black;
|
||||||
width: 300px;
|
width: 300px;
|
||||||
height: 400px;
|
height: 400px;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
position: relative;
|
position: fixed;
|
||||||
gap: 20px;
|
gap: 20px;
|
||||||
padding: 20px;
|
padding: 20px;
|
||||||
|
top: 50%;
|
||||||
|
left: 50%;
|
||||||
|
transform: translate(-50%, -50%);
|
||||||
|
background: white;
|
||||||
|
|
||||||
#form-closure-container {
|
#form-closure-container {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
@ -118,7 +159,8 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#form {
|
#form,
|
||||||
|
#form-update {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 15px;
|
gap: 15px;
|
||||||
|
@ -4,84 +4,85 @@ import { createRoom, getRooms, deleteRoom } from "../../api";
|
|||||||
import { Link } from "react-router-dom";
|
import { Link } from "react-router-dom";
|
||||||
|
|
||||||
export default function Rooms() {
|
export default function Rooms() {
|
||||||
const [rooms, setRooms] = useState([]);
|
const [rooms, setRooms] = useState([]);
|
||||||
|
|
||||||
const onClickCreate = () => {
|
const onClickCreate = () => {
|
||||||
const name = prompt("Nom de la piece ?");
|
const name = prompt("Nom de la piece ?");
|
||||||
|
|
||||||
createRoom(name).then((res) => {
|
createRoom(name).then((res) => {
|
||||||
const values = [...rooms];
|
const values = [...rooms];
|
||||||
values.push(res);
|
values.push(res);
|
||||||
setRooms(values);
|
setRooms(values);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const onClickDelete = (id, name) => {
|
const onClickDelete = (id, name) => {
|
||||||
const confirmation = prompt(
|
const confirmation = prompt(
|
||||||
`Etes-vous sur de vouloir supprimer ${name} ? (Oui ou non)`
|
`Etes-vous sur de vouloir supprimer ${name} ? (Oui ou non)`,
|
||||||
);
|
"non",
|
||||||
|
|
||||||
if (confirmation.toLocaleLowerCase() !== "oui") return;
|
|
||||||
|
|
||||||
deleteRoom(id).then((res) => {
|
|
||||||
const values = rooms.filter((e) => e._id !== id);
|
|
||||||
setRooms(values);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
getRooms().then((res) => {
|
|
||||||
setRooms(res);
|
|
||||||
});
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div id="rooms-container">
|
|
||||||
{rooms.length === 0 ? (
|
|
||||||
<span id="err-no-rooms">Aucune piece enregistree</span>
|
|
||||||
) : (
|
|
||||||
<div id="rooms-list-container">
|
|
||||||
{rooms.map((i, j) => (
|
|
||||||
<div className="room" key={j}>
|
|
||||||
<div
|
|
||||||
className="room-delete"
|
|
||||||
onClick={() => {
|
|
||||||
onClickDelete(i._id, i.name);
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<span className="room-delete-ascii">×</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="room-id-container">
|
|
||||||
<span className="label-id">ID</span>
|
|
||||||
<span className="room-id">
|
|
||||||
{i._id[0]}
|
|
||||||
{i._id[1]}
|
|
||||||
{i._id[2]}
|
|
||||||
{i._id[3]}
|
|
||||||
{i._id[4]}
|
|
||||||
{i._id[5]}
|
|
||||||
...
|
|
||||||
</span>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div className="room-name-container">
|
|
||||||
<span className="label-name">Nom </span>
|
|
||||||
<Link to={`/room/${i._id}`}>
|
|
||||||
<span className="room-name">{i.name}</span>
|
|
||||||
</Link>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
))}
|
|
||||||
</div>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<div id="rooms-add-container">
|
|
||||||
<div id="rooms-text-on">Creer une nouvelle piece</div>
|
|
||||||
<button id="add-rooms" onClick={onClickCreate}>
|
|
||||||
+
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (confirmation.toLocaleLowerCase() !== "oui") return;
|
||||||
|
|
||||||
|
deleteRoom(id).then((res) => {
|
||||||
|
const values = rooms.filter((e) => e._id !== id);
|
||||||
|
setRooms(values);
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
getRooms().then((res) => {
|
||||||
|
setRooms(res);
|
||||||
|
});
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div id="rooms-container">
|
||||||
|
{rooms.length === 0 ? (
|
||||||
|
<span id="err-no-rooms">Aucune piece enregistree</span>
|
||||||
|
) : (
|
||||||
|
<div id="rooms-list-container">
|
||||||
|
{rooms.map((i, j) => (
|
||||||
|
<div className="room" key={j}>
|
||||||
|
<div
|
||||||
|
className="room-delete"
|
||||||
|
onClick={() => {
|
||||||
|
onClickDelete(i._id, i.name);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<span className="room-delete-ascii">×</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="room-id-container">
|
||||||
|
<span className="label-id">ID</span>
|
||||||
|
<span className="room-id">
|
||||||
|
{i._id[0]}
|
||||||
|
{i._id[1]}
|
||||||
|
{i._id[2]}
|
||||||
|
{i._id[3]}
|
||||||
|
{i._id[4]}
|
||||||
|
{i._id[5]}
|
||||||
|
...
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="room-name-container">
|
||||||
|
<span className="label-name">Nom </span>
|
||||||
|
<Link to={`/room/${i._id}`}>
|
||||||
|
<span className="room-name">{i.name}</span>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
<div id="rooms-add-container">
|
||||||
|
<div id="rooms-text-on">Creer une nouvelle piece</div>
|
||||||
|
<button id="add-rooms" onClick={onClickCreate}>
|
||||||
|
+
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user