Implémente le back end du panier avec l'utilisation des cookies qui ne sont pas encore…
- User
Implémente le back end du panier avec l'utilisation des cookies qui ne sont pas encore liées à ces pages : import React from 'react' import {useState} from 'react'; import { getCookie, setCookie } from '../../../../cookies/CookiesLib.tsx';
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 MenuConnexion(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 { 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 - Assistant
- User
[{ "resource": "/c:/Users/alexa/Desktop/sae-fest-iuto-front/src/components/nav/side-menus/Panier/MenuPanier.tsx", "owner": "typescript", "code": "2339", "severity": 8, "message": "Property 'quantite' does not exist on type 'never'.", "source": "ts", "startLineNumber": 55, "startColumn": 77, "endLineNumber": 55, "endColumn": 85 }]
- Assistant
L'erreur TypeScript que vous rencontrez indique que le type de l'objet sur lequel vous tentez d'accéder à la propriété
quantiteestnever. Le typeneverest utilisé pour des valeurs qui ne devraient jamais se produire. Voyons cela dans le contexte de votre code :Vous avez essayé d'accéder à
quantiteavec cette ligne de code dansMenuConnexion: - User
- Assistant
- User
[{ "resource": "/c:/Users/alexa/Desktop/sae-fest-iuto-front/src/components/nav/side-menus/Panier/MenuPanier.tsx", "owner": "typescript", "code": "2304", "severity": 8, "message": "Cannot find name 'useContext'.", "source": "ts", "startLineNumber": 16, "startColumn": 29, "endLineNumber": 16, "endColumn": 39 }]
- Assistant
The error message "Cannot find name 'useContext'" typically indicates that TypeScript cannot find the definition or import of
useContext. This is usually due to eitheruseContextnot being imported from the React library, or a typo in the code.To fix this error, make sure to import
useContextproperly at the top of your fileMenuPanier.tsx. It should look like this:import React, { useContext, useState } from 'react'; // Other importsThe
useContexthook is part of the default React exports, so you must import it from 'react' in order to use it.Check all your files to ensure that
useContextis indeed being imported wherever you are trying to use it. If it's not imported, it will cause the TypeScript compiler to throw such an error.If the import is present, and you're still seeing the error, try restarting your IDE or TypeScript server as sometimes the environment may not pick up changes correctly.
- User
- Assistant
- User
[{ "resource": "/C:/Users/alexa/Desktop/sae-fest-iuto-front/src/components/TicketCard.tsx", "owner": "typescript", "code": "2552", "severity": 8, "message": "Cannot find name 'CartItem'. Did you mean 'Artiste'?", "source": "ts", "startLineNumber": 37, "startColumn": 26, "endLineNumber": 37, "endColumn": 34 }]
- Assistant
The TypeScript error you are seeing, "Cannot find name 'CartItem'. Did you mean 'Artiste'?", suggests that TypeScript is unable to find a definition for the
CartItemtype in yourTicketCard.tsxfile. This could be because theCartItemtype hasn't been defined or imported into the file where you're trying to use it.To fix this, you need to ensure that the
CartItemtype is defined and that it is visible to the file. There are a couple of ways to do this.