J'ai un CartContext qui me permet d'avoir connaisance en tout lieu du site des cookies qui correspond aux
panier avec les billets ajoutées, je veux que tu implémentes le back end des pages MenuPanier et ItemPanier en prenant compte
du cart de CartContext (je m'occuperais de faire la requete à la BD plus tard ). EN sachant que dans Item Panierje veux afficher un seul
billet et que dans MenuPanier je veux afficher chacun.
import React from 'react'
import {useState} from 'react';
type Props = {
typeBillet: number,
quantite: number,
}
export default function ItemPanier(props: Props) {
const [quantite, setQuantite] = useState(props.quantite);
return (
Pass 1 jour - fosse
35,99€
<span className='ajout-retrait' onClick={() => setQuantite(quantite-1)}>-
<span className='ajout-retrait' onClick={() => setQuantite(quantite+1)}>+
import { motion } from 'framer-motion'
import React from 'react'
import { Link } from 'react-router-dom'
import {useState} from 'react';
import TextField from '../../../form/TextField';
import Button from '../../../form/Button';
import ItemPanier from './ItemPanier';
type Props = {
isOpen: boolean;
setIsOpen: (isOpen : boolean) => void;
}
export default function MenuPanier(props: Props) {
const menuVariants = {
hidden:{
x: "42rem",
transition:{
duration: 0.5,
ease: [1, -0.02, 0,1]
}
},
visible:{
x: 0,
transition:{
duration: 0.5,
ease: [1, -0.02, 0,1]
}
}
}
return (
<motion.div className='side-menu cart'
variants={menuVariants}
initial="hidden"
animate={props.isOpen ? "visible" : "hidden"}>
<div className="cross" onClick={() => props.setIsOpen(false)}>
Mon panier
<section className='le-panier'>
<ItemPanier typeBillet={1} quantite={1}/>
<ItemPanier typeBillet={1} quantite={1}/>
</section>
<div className="sous-total">
<h4>Sous total: </h4>
<h4>35,99€</h4>
</div>
<Button text="RESERVER"/>
</div>
</motion.div>
)
}
import { useContext, useEffect, useState } from 'react'
import { motion, useAnimation } from 'framer-motion';
import { easeOut } from 'framer-motion/dom';
import { setCookie, getCookie } from '../../cookies/CookiesLib';
import { CartContext } from '../../App';
type Props =
{
isCart? : boolean
setIsOpen: (isOpen : boolean) => void;
}
export default function NavButton(props:Props) {
const [cartItemCount, setCartItemCount] = useState(0);
const {cart, setCart} = useContext(CartContext);
const controls = useAnimation();
const popAnim = {
scale: [1, 1.5, 1], // de sa taille a 1,5x fois sa taille puis retour a sa taille initiale
transition: { duration: 0.5 },
};
// Handler pour mettre à jour le nombre total d’articles dans l’état local
const updateCartItemCount = () => {
const cartItems = getCookie('cart');
if (cartItems) {
const total = cartItems.reduce((sum: number, item: { quantity: number; }) => sum + item.quantity, 0);
setCartItemCount(total);
}else {
setCartItemCount(0);
}
};
useEffect(() => {
updateCartItemCount();
if (cart.length > 0) {
controls.start(popAnim); // Trigger the animation
}
}, [cart]);
const bgVariants = {
default : {
backgroundColor: '#E45A3B00',
stroke: "#E45A3B",
transition:{
duration: 0.3,
ease:easeOut,
}
},
hover: {
backgroundColor: '#E45A3B',
stroke: "#FFFBEE",
transition:{
duration: 0.3,
ease:easeOut,
}
}
}
return (
<motion.div className='nav-btn'
variants={bgVariants}
initial='default'
whileHover="hover"
onClick={() => props.setIsOpen(true)}
>
{props.isCart ?
<>
{cartItemCount > 0 && (
<motion.div
animate={controls}
className="cart-notification"
>
{cartItemCount}
</motion.div>
)}
<svg width="37" height="37" viewBox="0 0 37 37" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M12.4856 30.6457C13.1125 30.6457 13.6206 30.1375 13.6206 29.5106C13.6206 28.8838 13.1125 28.3756 12.4856 28.3756C11.8588 28.3756 11.3506 28.8838 11.3506 29.5106C11.3506 30.1375 11.8588 30.6457 12.4856 30.6457Z" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M28.3753 30.6457C29.0021 30.6457 29.5103 30.1375 29.5103 29.5106C29.5103 28.8838 29.0021 28.3756 28.3753 28.3756C27.7484 28.3756 27.2402 28.8838 27.2402 29.5106C27.2402 30.1375 27.7484 30.6457 28.3753 30.6457Z" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M3.40527 5.67517H7.94537L11.3504 24.9706H29.5108" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M11.3501 20.4304H29.0451C29.1764 20.4305 29.3036 20.3851 29.4051 20.302C29.5067 20.2188 29.5763 20.103 29.602 19.9743L31.6451 9.75909C31.6615 9.67672 31.6595 9.59171 31.6392 9.51021C31.6188 9.42871 31.5806 9.35274 31.5274 9.28779C31.4741 9.22284 31.4071 9.17053 31.3311 9.13463C31.2552 9.09873 31.1722 9.08014 31.0882 9.0802H9.08008" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</>
:
<svg width="35" height="35" viewBox="0 0 35 35" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M23.5154 9.84375C23.2474 13.4579 20.5076 16.4062 17.4998 16.4062C14.4919 16.4062 11.7473 13.4586 11.4841 9.84375C11.2107 6.08398 13.8767 3.28125 17.4998 3.28125C21.1228 3.28125 23.7888 6.15234 23.5154 9.84375Z" stroke-width="3" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M17.5002 20.7812C11.5529 20.7812 5.51677 24.0625 4.39978 30.2559C4.26511 31.0023 4.68757 31.7188 5.46892 31.7188H29.5314C30.3134 31.7188 30.7359 31.0023 30.6012 30.2559C29.4836 24.0625 23.4474 20.7812 17.5002 20.7812Z" stroke-width="3" stroke-miterlimit="10"/>
</svg>
}
</motion.div>
)
}import { motion } from 'framer-motion';
import { useContext, useState } from 'react';
import Button from '../components/form/Button';
import { getCookie, setCookie } from '../cookies/CookiesLib.tsx';
import { CartContext } from '../App';
const initialDays = { '20Juillet': false, '21Juillet': false, '22Juillet': false };
type Props = {
id: number;
title: string;
price: number|string;
nbTicket: number;
isForfait?: boolean;
};
export default function TicketCard({ id, title, price, nbTicket, isForfait }: Props) {
const [isOpen, setIsOpen] = useState(false);
const [tickets, setTickets] = useState(nbTicket);
const [rotation, setRotation] = useState(0);
const [days, setDays] = useState(initialDays);
const { cart, setCart } = useContext(CartContext);
const handleTicketChange = (newTickets: number, event: React.MouseEvent) => {
event.stopPropagation();
setTickets(newTickets);
};
const addToCartHandler = () => {
const selectedDays = isForfait ?
Object.entries(days).filter(([_, isChosen]) => isChosen).map(([day, _]) => day) :
[];
const itemForCart = {
id,
title,
price: typeof price === 'number' ? price : 0,
quantity: tickets,
selectedDays,
};
let newCart = cart.slice();
const billetIndex = newCart.findIndex(billet => billet.id === itemForCart.id);
if (billetIndex > -1) {
newCart[billetIndex].quantity += itemForCart.quantity;
} else {
newCart.push(itemForCart);
}
setCart(newCart); // Met à jour l'état global du panier
setCookie('cart', newCart, { expires: 7, sameSite: 'None', secure: true }); // Met à jour le cookie
};
const contentVariants = {
closed: {
opacity: 0,
height: 0,
overflow: 'hidden',
transition: {
duration: 0.2,
ease: 'easeInOut',
when: 'afterChildren',
},
},
open: {
opacity: 1,
height: title === "Forfait 2 jours" ? 150 : 120,
transition: {
duration: 0.2,
ease: 'easeInOut',
when: 'beforeChildren',
}
},
};
const cardVariants = {
hidden: { opacity: 0, y: 50 },
visible: {
opacity: 1,
y: 0,
transition: {
type: 'spring',
stiffness: 120,
},
},
};
const maxSelectedDays = 2;
const selectedDayCount = () => {
return Object.values(days).filter(Boolean).length;
};
const toggleDaySelection = (day: keyof typeof initialDays) => {
setDays(prevDays => {
const isSelected = prevDays[day];
const count = selectedDayCount();
if (!isSelected && count >= maxSelectedDays) {
return prevDays;
}
return { ...prevDays, [day]: !prevDays[day] };
});
};
return (
<motion.div
className="ticket-card"
layout
initial="hidden"
animate="visible"
variants={cardVariants}
onClick={() => {
setIsOpen(!isOpen);
setRotation(rotation === 0 ? 90 : 0);
}}
>
{title}
Les tickets ne sont pas remboursables.
Dernière entrée à 11H.
{price}€
<motion.div className="svg-container" animate={{ rotate: rotation }}>
</motion.div>
<motion.div
className={sub-menu ${title === "Forfait 2 jours" ? "forfait-2j" : ""}}
variants={contentVariants}
initial="closed"
animate={isOpen ? "open" : "closed"}
exit="closed"
</motion.div>
</motion.div>
);import { useEffect } from "react";
import TicketCard from "../../components/TicketCard";
import Footer from "../../components/footer";
import axios from 'axios';
type Props = {
isNavInFocus: boolean;
setIsNavTransparent: (isNavTransparent: boolean) => void;
};
type Billet = {
idB: number;
title: string;
prix: number|string;
nbTicket: number;
};
export default function Billeterie(props: Props) {
const billets: Billet[] = [
{
idB: 1,
title: "Accès Samedi 20 Juillet",
prix: 60,
nbTicket: 0,
},
{
idB: 2,
title: "Accès Dimanche 21 Juillet",
prix: 80,
nbTicket: 0,
},
{
idB: 3,
title: "Accès Lundi 22 Juillet",
prix: 90,
nbTicket: 0,
},
{
idB: 4,
title: "Forfait 2 jours",
prix: "À partir de 140",
nbTicket: 0,
},
{
idB: 5,
title: "Forfait 3 jours",
prix: "180",
nbTicket: 0,
},
];
useEffect(() => {
window.scrollTo(0, 0);
props.setIsNavTransparent(false);
}, []);
return (
<>
BILLETERIE
<main className="billets">
<section className="header-billet">
<div>
<p>samedi 20 Juillet 2024 - lundi 22 Juillet 2024</p>
<h2>FESTI'IUTO ÉDITION 2024</h2>
<div className="lieu">
<svg
xmlns="http://www.w3.org/2000/svg"
width="14"
height="20"
viewBox="0 0 14 20"
fill="none"
>
<path
d="M7 0C3.13 0 0 3.13 0 7C0 12.25 7 20 7 20C7 20 14 12.25 14 7C14 3.13 10.87 0 7 0ZM7 9.5C6.33696 9.5 5.70107 9.23661 5.23223 8.76777C4.76339 8.29893 4.5 7.66304 4.5 7C4.5 6.33696 4.76339 5.70107 5.23223 5.23223C5.70107 4.76339 6.33696 4.5 7 4.5C7.66304 4.5 8.29893 4.76339 8.76777 5.23223C9.23661 5.70107 9.5 6.33696 9.5 7C9.5 7.66304 9.23661 8.29893 8.76777 8.76777C8.29893 9.23661 7.66304 9.5 7 9.5Z"
fill="#4E4E4E"
/>
</svg>
<p>3 rue Montorgueil, 45000, France</p>
</div>
</div>
<div>
<svg
width="64"
height="64"
viewBox="0 0 64 64"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M62.9991 27.739L42.1815 27.7675L56.8787 13.0286L50.7001 6.86056L36.0029 21.5994L35.9744 0.785744L27.2406 0.797718L27.2692 21.6114L12.5316 6.91288L6.36413 13.0979L21.1017 27.7964L0.289932 27.825L0.301899 36.5537L21.1137 36.5251L6.41646 51.2641L12.6009 57.4321L27.2981 42.6932L27.3266 63.5069L36.0603 63.4949L36.0318 42.6812L50.7694 57.3798L56.931 51.1948L42.1934 36.4962L63.011 36.4677L62.9991 27.739Z"
fill="#FFD600"
/>
</svg>
</div>
</section>
<section className="billets-content">
<h3>Billets</h3>
<div className="achat-billets">
{billets.map((billet) => (
<TicketCard
key={billet.idB}
id={billet.idB}
title={billet.title}
price={billet.prix}
nbTicket={billet.nbTicket}
isForfait={billet.idB === 4}
/>
))}
</div>
</section>
</main>
</div>
<Footer />
</>
);
}
}
)
}