Skip to content
This repository has been archived by the owner on Jan 30, 2024. It is now read-only.

Commit

Permalink
test: Integrate Rayane's recent changes (bugged)
Browse files Browse the repository at this point in the history
  • Loading branch information
Eray C committed Nov 1, 2021
1 parent d45959a commit 1575cc3
Show file tree
Hide file tree
Showing 2 changed files with 131 additions and 1 deletion.
131 changes: 131 additions & 0 deletions src/Order.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
import { useState } from "react";
import * as Data from "./Data";
import { BrowserRouter, Route, NavLink, Switch } from "react-router-dom";

export function OrderForm(props) {
const ingredients = {
sauces: [...Data.defaultBreads],
meats: [...Data.defaultMeats],
vegetables: [...Data.defaultVegetables],
sauces: [...Data.defaultSauces],
};

const [selectedProducts, setSelectedProducts] = useState(
...Data.defaultOrder
);

const [bread, setBread] = useState("");
const [meat, setMeat] = useState("");
const [vegetables, setVegetables] = useState("");
const [sauces, setSauces] = useState("");

// const [checkedState, setCheckedState] = useState(
// new Array(ingredients.length).fill(false)
// );

const { onSubmit } = props;

// const handleOnChange = (position) => {
// const updatedCheckedState = checkedState.map((item, index) =>
// index === position ? true : item
// );

const handleOnSelected = (productSelected) => {
const updatedSelectedProducts = selectedProducts.map((initialProduct) =>
initialProduct === productSelected.name ? productSelected = productSelected.value : false
);

setSelectedProducts(updatedSelectedProducts);

// setCheckedState(updatedCheckedState);
// const Finishedsauces = updatedCheckedState.reduce(
// (sauce, currentState, index) => {
// if (currentState === false) {
// switch (ingredients.vegetables) {
// case "salade":
// setSalade("");
// break;
// case "tomate":
// setTomate("");
// break;
// case "oignon":
// setOignon("");
// break;
// default:
// console.log("aucun changement");
// }
// }
// if (currentState === true) {
// switch (ingredients[index].categorie) {
// case "pains":
// setPain(ingredients[index].name);
// break;
// case "viandes":
// setViande(ingredients[index].name);
// break;
// case "salade":
// setSalade(ingredients[index].name);
// break;
// case "tomate":
// setTomate(ingredients[index].name);
// break;
// case "oignon":
// setOignon(ingredients[index].name);
// break;
// case "sauces":
// if (sauce.length < 2) {
// setSauces((sauce = [...sauce, " " + ingredients[index].name]));
// }
// return sauce;
// default:
// console.log("aucun changement");
// }
// return sauce;
// }
// return sauce;
// },
// );

setSauces(Finishedsauces);
};

const handleSubmit = (event) => {
event.preventDefault();
onSubmit({ pain, viande, salade, tomate, oignon, sauces });
};

return (
<ul className="toppings-sauce">
<form className="add-form" onSubmit={handleSubmit}>
{ingredients.map(({ name, categorie, image }, index) => {
return (
<li key={index}>
<div className="toppings-sauce-item">
<div className="left-section">
<input
key={index}
type="checkbox"
id={index}
name={name}
value={name}
checked={checkedState[index]}
onChange={() => handleOnChange(index)}
/>
<label>{name}</label>
</div>
</div>
</li>
);
})}
<button type="submit">Commander</button>
</form>
<li>
<div className="toppings-sauce-item">
<div className="left-section">Total:</div>
<div className="right-section">{sauces}</div>
</div>
</li>
</ul>
);
}
export default OrderForm;
1 change: 0 additions & 1 deletion src/data.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
export const defaultOrder = {
id: "",
bread: "",
meat: "",
vegetables: [],
Expand Down

0 comments on commit 1575cc3

Please sign in to comment.