diff --git a/01-frontend/public/locales/de/translation.json b/01-frontend/public/locales/de/translation.json index fcd36ed..127163c 100644 --- a/01-frontend/public/locales/de/translation.json +++ b/01-frontend/public/locales/de/translation.json @@ -59,7 +59,7 @@ "other": "Sonstiges", "outOfStock": "Ausverkauft", "payment": "Bezahlung", - "paymentNotAvailable": "Keine Zahlungsmöglichkeit hinterlegt.", + "paymentNotAvailable": "Keine Zahlungsmethoden verfügbar.", "pageDoesNotExist": "Ups! Diese Seite existiert nicht.", "phone": "Telefon", "placeOrder": "Zahlungspflichtig bestellen", @@ -91,5 +91,7 @@ "noRatingsYet": "Noch keine Bewertungen vorhanden.", "accounts": "Konten", "statistics": "Statistiken", - "thanksForRating": "Vielen Dank für die Bewertung!" + "thanksForRating": "Vielen Dank für die Bewertung!", + "telephone": "Telefon", + "basketEmpty": "Der Warenkorb ist leer." } diff --git a/01-frontend/public/locales/en/translation.json b/01-frontend/public/locales/en/translation.json index ae59e40..d0e827c 100644 --- a/01-frontend/public/locales/en/translation.json +++ b/01-frontend/public/locales/en/translation.json @@ -91,5 +91,7 @@ "noRatingsYet": "No ratings yet", "accounts": "Accounts", "statistics": "Statistics", - "thanksForRating": "Thank you for rating!" + "thanksForRating": "Thank you for rating!", + "telephone": "Telephone", + "basketEmpty": "The shopping cart is empty." } diff --git a/01-frontend/src/helper/BasketProvider.tsx b/01-frontend/src/helper/BasketProvider.tsx index 95e3937..693e27e 100644 --- a/01-frontend/src/helper/BasketProvider.tsx +++ b/01-frontend/src/helper/BasketProvider.tsx @@ -1,13 +1,14 @@ import React, { createContext, useContext, useState } from 'react'; +import Item from '../components/Item'; interface BasketItem { - itemId: string; + item: Item; quantity: number; } interface BasketContextType { basket: BasketItem[]; - addToBasket: (itemId: string, quantity: number) => void; + addToBasket: (item: Item, quantity: number) => void; clearBasket: () => void; } @@ -16,19 +17,19 @@ const BasketContext = createContext(undefined); export const BasketProvider: React.FC<{ children: React.ReactNode }> = ({ children }) => { const [basket, setBasket] = useState([]); - const addToBasket = (itemId: string, quantity: number) => { + const addToBasket = (item: Item, quantity: number) => { setBasket((prevBasket) => { - const existingItem = prevBasket.find((item) => item.itemId === itemId); + const existingItem = prevBasket.find((basketItem) => basketItem.item.uuid === item.uuid); if (existingItem) { // Update quantity if item already exists - return prevBasket.map((item) => - item.itemId === itemId - ? { ...item, quantity: item.quantity + quantity } - : item + return prevBasket.map((basketItem) => + basketItem.item.uuid === item.uuid + ? { ...basketItem, quantity: basketItem.quantity + quantity } + : basketItem ); } // Add new item to basket - return [...prevBasket, { itemId, quantity }]; + return [...prevBasket, { item, quantity }]; }); }; diff --git a/01-frontend/src/helper/homepage/ItemCard.tsx b/01-frontend/src/helper/homepage/ItemCard.tsx index a418120..da9b7e6 100644 --- a/01-frontend/src/helper/homepage/ItemCard.tsx +++ b/01-frontend/src/helper/homepage/ItemCard.tsx @@ -14,7 +14,7 @@ export default function ItemCard({ item }: { item: Item }) { const { addToBasket } = useBasket(); const handleAddToCart = () => { - addToBasket(item.id, 1); + addToBasket(item, 1); console.log(`Added ${1} of ${item.name} to basket`); }; diff --git a/01-frontend/src/helper/navbar/LoginPopUp.tsx b/01-frontend/src/helper/navbar/LoginPopUp.tsx new file mode 100644 index 0000000..11b81a0 --- /dev/null +++ b/01-frontend/src/helper/navbar/LoginPopUp.tsx @@ -0,0 +1,18 @@ +export default function LoginPopUp() { + return ( +
+

Login

+
+
+ + +
+
+ + +
+ +
+
+ ); +} \ No newline at end of file diff --git a/01-frontend/src/helper/productpage/ProductInfo.tsx b/01-frontend/src/helper/productpage/ProductInfo.tsx index d64ead6..a5c778d 100644 --- a/01-frontend/src/helper/productpage/ProductInfo.tsx +++ b/01-frontend/src/helper/productpage/ProductInfo.tsx @@ -41,7 +41,7 @@ export default function ProductInfo({ item }: { item: Item }) { const handleAddToCart = () => { - addToBasket(item.id, quantity); + addToBasket(item, quantity); setOpen(true); console.log(`Added {quantity} of €{item.name} to basket`); }; diff --git a/01-frontend/src/pages/Payment.tsx b/01-frontend/src/pages/Payment.tsx index fbf47ad..8baff7d 100644 --- a/01-frontend/src/pages/Payment.tsx +++ b/01-frontend/src/pages/Payment.tsx @@ -1,32 +1,33 @@ -import React, { useState } from 'react'; import { Box, Button, Container, - Step, - StepLabel, - Stepper, - Typography, - TextField, + Divider, Grid, - Paper, List, ListItem, ListItemText, - Divider, - styled, + Paper, + Step, + StepLabel, + Stepper, + TextField, + Typography } from '@mui/material'; -import { useBasket } from '../helper/BasketProvider'; +import React, { useState } from 'react'; +import { useTranslation } from "react-i18next"; import { useNavigate } from 'react-router-dom'; -import {useTranslation} from "react-i18next"; +import { useBasket } from '../helper/BasketProvider'; -const Item = styled(Paper)(({ theme }) => ({ - backgroundColor: theme.palette.background.paper, - color: theme.palette.text.primary, - ...theme.typography.body2, - padding: theme.spacing(1), - textAlign: 'center', -})); +type ShippingDetails = { + firstName: string; + lastName: string; + telefon: string; + address: string; + postalCode: string; + city: string; + country: string; +}; export default function Payment() { @@ -35,13 +36,14 @@ export default function Payment() { const navigator = useNavigate(); const { basket, clearBasket } = useBasket(); const [activeStep, setActiveStep] = useState(0); - const [shippingDetails, setShippingDetails] = useState({ + const [shippingDetails, setShippingDetails] = useState({ firstName: '', lastName: '', + telefon: '', address: '', postalCode: '', city: '', - country: '' + country: 'Deutschland', }); const [orderNumber, setOrderNumber] = useState(null); const steps = [t('reviewCart'), t('shippingDetails'), t('payment'), t('orderSummary')]; @@ -71,6 +73,18 @@ export default function Payment() { clearBasket(); }; + // Hilfsfunktion prüfen, ob alle Pflichtfelder ausgefüllt sind + const isShippingDetailsValid = () => { + return ( + shippingDetails.firstName.trim() !== '' && + shippingDetails.lastName.trim() !== '' && + shippingDetails.address.trim() !== '' && + shippingDetails.postalCode.trim() !== '' && + shippingDetails.city.trim() !== '' && + shippingDetails.country.trim() !== '' + ); + }; + const renderStepContent = (step: number) => { switch (step) { case 0: @@ -79,18 +93,24 @@ export default function Payment() { {t('reviewCart')} - - {basket.map((item) => ( - - - - ))} - + {basket.length === 0 ? ( + + {t('basketEmpty')} + + ) : ( + + {basket.map((item) => ( + + + + ))} + + )} - @@ -102,60 +122,70 @@ export default function Payment() { {t('shippingDetails')} - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + ); @@ -194,10 +224,10 @@ export default function Payment() { {t('orderedItems')}: {basket.map((item) => ( - + ))} @@ -211,45 +241,53 @@ export default function Payment() { return (
- - - - {t('completeYourOrder')} - - - {steps.map((label) => ( - - {label} - - ))} - - {renderStepContent(activeStep)} - - - {activeStep === steps.length - 1 ? ( + + + + {t('completeYourOrder')} + + + {steps.map((label) => ( + + {label} + + ))} + + {renderStepContent(activeStep)} + - ) : ( - - )} - - - + {activeStep === steps.length - 1 ? ( + + ) : ( + + )} + + +
); } \ No newline at end of file