Add login, reg, cart, newsletter und access to small batch releases
This commit is contained in:
1 parent
414967441a
commit
fb801e3752
30 files changed
+2979
-246
No files matched your search
@@ -1,11 +1,19 @@
|
||||
import { useEffect, useMemo, useState } from "react";
|
||||
import { Link, useNavigate, useParams } from "react-router";
|
||||
import perfumes from "../data/perfumes";
|
||||
import "../style/navbar.css";
|
||||
import SharedNavbar from "./SharedNavbar";
|
||||
import { formatChf } from "../shop/money";
|
||||
import { useShop } from "../shop/useShop";
|
||||
import "./ProductDetailPage.css";
|
||||
|
||||
const priceToCents = (price) => {
|
||||
const match = String(price).match(/(\d+)/);
|
||||
return match ? Number(match[1]) * 100 : 0;
|
||||
};
|
||||
|
||||
function ProductDetailContent({ perfumeSlug }) {
|
||||
const navigate = useNavigate();
|
||||
const { addToCart, subscribeToProduct, user } = useShop();
|
||||
|
||||
const perfume = useMemo(
|
||||
() => perfumes.find((item) => item.slug === perfumeSlug) || perfumes[0],
|
||||
@@ -18,6 +26,20 @@ function ProductDetailContent({ perfumeSlug }) {
|
||||
const [selectedSize, setSelectedSize] = useState("sample");
|
||||
const [showReviewDetails, setShowReviewDetails] = useState(false);
|
||||
const [commentPage, setCommentPage] = useState(0);
|
||||
const selectedProductId = `${perfume.slug}-${selectedSize === "sample" ? "sample" : "full"}`;
|
||||
const selectedProductLabel = selectedSize === "sample" ? "Sample" : "Full Size";
|
||||
const selectedPriceCents = priceToCents(perfume.prices[selectedSize]);
|
||||
const sampleCredit = user?.sampleCredits?.find(
|
||||
(credit) => credit.slug === perfume.slug && credit.status === "available"
|
||||
);
|
||||
const discountPreviewCents =
|
||||
selectedSize === "full"
|
||||
? Math.min(
|
||||
selectedPriceCents,
|
||||
(user?.discoveryStatus === "Discount available" ? 4800 : 0) +
|
||||
(sampleCredit?.amount_cents || 0)
|
||||
)
|
||||
: 0;
|
||||
|
||||
const sizeOptions = [
|
||||
{
|
||||
@@ -71,22 +93,7 @@ function ProductDetailContent({ perfumeSlug }) {
|
||||
|
||||
return (
|
||||
<div className="detail-page">
|
||||
<nav className="navbar navbar--light">
|
||||
<div className="nav-pill">
|
||||
<Link to="/" className="nav-link">
|
||||
atmos
|
||||
</Link>
|
||||
<Link to="/#dufte" className="nav-link active">
|
||||
Düfte
|
||||
</Link>
|
||||
<Link to="/discovery-set" className="nav-link">
|
||||
Testen
|
||||
</Link>
|
||||
<a href="#cart" className="nav-link">
|
||||
Cart
|
||||
</a>
|
||||
</div>
|
||||
</nav>
|
||||
<SharedNavbar variant="light" />
|
||||
|
||||
<main className="detail-shell">
|
||||
<div className="detail-topbar">
|
||||
@@ -246,11 +253,17 @@ function ProductDetailContent({ perfumeSlug }) {
|
||||
|
||||
<div className="discovery-note">
|
||||
<div className="discovery-note-text">
|
||||
<strong>Discovery Set wird angerechnet</strong>
|
||||
<strong>Discovery Set wird einmalig angerechnet</strong>
|
||||
<p>
|
||||
Hast du das Discovery Set gekauft, wird der volle Preis beim Kauf
|
||||
automatisch abgezogen.
|
||||
Nur das erste Discovery Set erzeugt CHF 48 Guthaben. Es wird
|
||||
einmal bei einem späteren Full-Size-Kauf automatisch abgezogen.
|
||||
</p>
|
||||
{discountPreviewCents > 0 && (
|
||||
<p className="discount-preview">
|
||||
Erwarteter Preis mit Rabatt:{" "}
|
||||
<strong>{formatChf(selectedPriceCents - discountPreviewCents)}</strong>
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<Link to="/discovery-set" className="discovery-note-btn">
|
||||
@@ -258,10 +271,28 @@ function ProductDetailContent({ perfumeSlug }) {
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
<button className="buy-button" type="button">
|
||||
<button
|
||||
className="buy-button"
|
||||
type="button"
|
||||
onClick={() =>
|
||||
addToCart(
|
||||
selectedProductId,
|
||||
1,
|
||||
`${perfume.name} ${selectedProductLabel} added.`
|
||||
).catch(() => {})
|
||||
}
|
||||
>
|
||||
KAUFEN
|
||||
</button>
|
||||
|
||||
<button
|
||||
className="restock-button"
|
||||
type="button"
|
||||
onClick={() => subscribeToProduct(selectedProductId, "restock").catch(() => {})}
|
||||
>
|
||||
RESTOCK UPDATE ABONNIEREN
|
||||
</button>
|
||||
|
||||
<div className="detail-description-section">
|
||||
<span className="label-title">BESCHREIBUNG</span>
|
||||
|
||||
@@ -415,8 +446,20 @@ function ProductDetailContent({ perfumeSlug }) {
|
||||
</p>
|
||||
|
||||
<div className="detail-bottom-actions">
|
||||
<button type="button">SAMPLE BESTELLEN – CHF 12</button>
|
||||
<button type="button">DISCOVERY SET – CHF 48</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() =>
|
||||
addToCart(`${perfume.slug}-sample`, 1, `${perfume.name} Sample added.`).catch(() => {})
|
||||
}
|
||||
>
|
||||
SAMPLE BESTELLEN – {perfume.prices.sample}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => addToCart("discovery-set", 1, "Discovery Set added.").catch(() => {})}
|
||||
>
|
||||
DISCOVERY SET – CHF 48
|
||||
</button>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
@@ -430,4 +473,4 @@ function ProductDetailPage() {
|
||||
return <ProductDetailContent key={perfumeSlug} perfumeSlug={perfumeSlug} />;
|
||||
}
|
||||
|
||||
export default ProductDetailPage;
|
||||
export default ProductDetailPage;
|
||||
Reference in new issue
Block a user