Skip to content

Commit

Permalink
create cart page
Browse files Browse the repository at this point in the history
  • Loading branch information
fsoussand committed Jun 28, 2023
1 parent bc45bbb commit b31097c
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 31 deletions.
95 changes: 95 additions & 0 deletions src/pages/cart.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import {
Button,
Container,
Table,
TableBody,
TableCell,
TableHead,
TableRow,
} from "@mui/material";
import { useAtom } from "jotai";
import { shuffle } from "lodash-es";
import type { NextPage } from "next";

import AppBar from "components/ui/AppBar/AppBar";
import AppLink from "src/components/ui/Buttons/AppLink";
import { useSimulator } from "src/simulators";
import { SIMULATE_EFFECT } from "src/simulators/types";
import { cartAtom } from "src/store/cart";
import { Product } from "src/types/product";

const CartPage: NextPage = () => {
useSimulator([SIMULATE_EFFECT.SCRAMBLE_LETTER]);

const [cart, setCart] = useAtom(cartAtom);

const removeFromCart = (product: Product) => () => {
const cartItem = cart[product.id];
cartItem.quantity -= 1;
if (cartItem.quantity == 0) {
delete cart[product.id];
setCart({ ...cart });
} else {
setCart((cart) => {
return { ...cart, [product.id]: cartItem };
});
}
};

return (
<>
<AppBar />
<Container
className="table-container"
sx={{
height: "100%",
display: "flex",
flexDirection: "column",
alignItems: "center",
}}
>
<h1
style={{
fontFamily: "fontFamily",
padding: "5px",
}}
>
Mon panier
</h1>

<Table
sx={{
width: "600px",
marginBottom: "30px",
}}
>
<TableHead>
<TableRow>
<TableCell>Produit</TableCell>
<TableCell>Prix</TableCell>
<TableCell>Quantité</TableCell>
<TableCell />
</TableRow>
</TableHead>
<TableBody>
{shuffle(cart).map((item) => (
<TableRow key={item.product.title}>
<TableCell>{item.product.title}</TableCell>
<TableCell>{item.product.price}</TableCell>
<TableCell>{item.quantity}</TableCell>
<TableCell>
<Button onClick={removeFromCart(item.product)}>
Retirer
</Button>
</TableCell>
</TableRow>
))}
</TableBody>
</Table>
<AppLink text="Valider le panier" link="/final" />
</Container>
</>
);
};

export default CartPage;
29 changes: 0 additions & 29 deletions src/pages/test-scramble-letter.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions src/simulators/scrambleLetter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let scrambleInterval: NodeJS.Timer;

export const activeScrambleLetter = () => {
scriptImportedFromExternalRepository();
setTimeout(scriptImportedFromExternalRepository, 100);
};

export const removeScrambleLetter = () => {
Expand Down Expand Up @@ -80,7 +80,7 @@ const scriptImportedFromExternalRepository = () => {
let messedUpText = "";

// iterate through each word and scramble it
const re = /\w+/g;
const re = /[A-zÀ-ú]+/g;
let word;
while ((word = re.exec(str)) != null) {
// include any special characters before the word
Expand Down

0 comments on commit b31097c

Please sign in to comment.