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
@@ -6,9 +6,12 @@ import ImpressumPage from "./pages/ImpressumPage";
|
||||
import DatenschutzPage from "./pages/DatenschutzPage";
|
||||
import SupportPage from "./pages/SupportPage";
|
||||
import DiscoverySetPage from "./pages/DiscoverySetPage";
|
||||
import SmallBatchPage from "./pages/SmallBatchPage";
|
||||
import Footer from "./components/Footer";
|
||||
import SupportChatbot from "./components/SupportChatbot";
|
||||
import ScrollToTop from "./components/ScrollToTop";
|
||||
import ShopDrawer from "./components/ShopDrawer";
|
||||
import CartToast from "./components/CartToast";
|
||||
|
||||
function App() {
|
||||
return (
|
||||
@@ -23,12 +26,15 @@ function App() {
|
||||
<Route path="/datenschutz" element={<DatenschutzPage />} />
|
||||
<Route path="/support" element={<SupportPage />} />
|
||||
<Route path="/discovery-set" element={<DiscoverySetPage />} />
|
||||
<Route path="/small-batch" element={<SmallBatchPage />} />
|
||||
</Routes>
|
||||
|
||||
<ShopDrawer />
|
||||
<CartToast />
|
||||
<Footer />
|
||||
<SupportChatbot />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default App;
|
||||
export default App;
|
||||
@@ -0,0 +1,40 @@
|
||||
import { useShop } from "../shop/useShop";
|
||||
import "./ShopDrawer.css";
|
||||
|
||||
function CartToast() {
|
||||
const {
|
||||
cartToast,
|
||||
dismissToast,
|
||||
openCart,
|
||||
openProfile,
|
||||
} = useShop();
|
||||
|
||||
if (!cartToast) return null;
|
||||
|
||||
const runAction = () => {
|
||||
dismissToast();
|
||||
if (cartToast.actionPanel === "cart") {
|
||||
openCart();
|
||||
}
|
||||
if (cartToast.actionPanel === "profile") {
|
||||
openProfile();
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="cart-toast">
|
||||
<button className="cart-toast-close" type="button" onClick={dismissToast}>
|
||||
x
|
||||
</button>
|
||||
<strong>{cartToast.title}</strong>
|
||||
<p>{cartToast.message}</p>
|
||||
{cartToast.actionLabel && (
|
||||
<button type="button" onClick={runAction}>
|
||||
{cartToast.actionLabel}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default CartToast;
|
||||
@@ -922,6 +922,11 @@
|
||||
max-width: 420px;
|
||||
}
|
||||
|
||||
.discovery-note-text .discount-preview {
|
||||
margin-top: 8px;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.discovery-note-btn {
|
||||
border: none;
|
||||
border-radius: 999px;
|
||||
@@ -972,6 +977,23 @@
|
||||
background: rgba(255, 106, 0, 0.8);
|
||||
}
|
||||
|
||||
.restock-button {
|
||||
width: 100%;
|
||||
min-height: 48px;
|
||||
margin-top: 10px;
|
||||
border: 1px solid #d6d6d6;
|
||||
border-radius: 0;
|
||||
background: #f8f8f8;
|
||||
color: #1f1f1f;
|
||||
font-size: 12px;
|
||||
letter-spacing: 0.13em;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.restock-button:hover {
|
||||
outline: 1px solid #ff6a00;
|
||||
}
|
||||
|
||||
/* --- Discovery Hinweis + Kaufen Button End --- */
|
||||
|
||||
/* --- Bottom CTA Start --- */
|
||||
@@ -1149,4 +1171,4 @@
|
||||
}
|
||||
}
|
||||
|
||||
/* --- Responsive End --- */
|
||||
/* --- Responsive End --- */
|
||||
@@ -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;
|
||||
@@ -0,0 +1,33 @@
|
||||
import { Link } from "react-router";
|
||||
import { useShop } from "../shop/useShop";
|
||||
import "../style/navbar.css";
|
||||
|
||||
function SharedNavbar({ variant = "light", active = "" }) {
|
||||
const { cart, openCart, openProfile, user } = useShop();
|
||||
const cartLabel =
|
||||
cart.total_quantity > 0 ? `Cart ${cart.total_quantity}` : "Cart";
|
||||
|
||||
return (
|
||||
<nav className={`navbar navbar--${variant}`} aria-label="Hauptnavigation">
|
||||
<div className="nav-pill">
|
||||
<Link to="/" className={`nav-link ${active === "atmos" ? "active" : ""}`}>
|
||||
atmos
|
||||
</Link>
|
||||
<Link
|
||||
to="/discovery-set"
|
||||
className={`nav-link ${active === "testen" ? "active" : ""}`}
|
||||
>
|
||||
Testen
|
||||
</Link>
|
||||
<button type="button" className="nav-link nav-button" onClick={openCart}>
|
||||
{cartLabel}
|
||||
</button>
|
||||
<button type="button" className="nav-link nav-button" onClick={openProfile}>
|
||||
{user ? "Profile" : "Profile"}
|
||||
</button>
|
||||
</div>
|
||||
</nav>
|
||||
);
|
||||
}
|
||||
|
||||
export default SharedNavbar;
|
||||
@@ -0,0 +1,495 @@
|
||||
.drawer-backdrop {
|
||||
position: fixed;
|
||||
inset: 0;
|
||||
z-index: 80;
|
||||
background: rgba(0, 0, 0, 0.58);
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
transition: opacity 0.22s ease;
|
||||
}
|
||||
|
||||
.drawer-backdrop.open {
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.shop-drawer {
|
||||
position: fixed;
|
||||
top: 0;
|
||||
right: 0;
|
||||
z-index: 90;
|
||||
width: min(560px, 100%);
|
||||
height: 100vh;
|
||||
padding: 22px;
|
||||
overflow-y: auto;
|
||||
background: #f5f5f5;
|
||||
border-left: 1px solid #d9d9d9;
|
||||
color: #1f1f1f;
|
||||
transform: translateX(100%);
|
||||
transition: transform 0.24s ease;
|
||||
}
|
||||
|
||||
.shop-drawer.open {
|
||||
transform: translateX(0);
|
||||
}
|
||||
|
||||
.drawer-top,
|
||||
.profile-section-header,
|
||||
.drawer-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.drawer-top {
|
||||
padding-bottom: 18px;
|
||||
border-bottom: 1px solid #d9d9d9;
|
||||
margin-bottom: 18px;
|
||||
font-size: 12px;
|
||||
letter-spacing: 0.24em;
|
||||
}
|
||||
|
||||
.drawer-top button,
|
||||
.cart-toast-close {
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
border: 1px solid #d6d6d6;
|
||||
background: #f1f1f1;
|
||||
color: #1f1f1f;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.drawer-stack,
|
||||
.auth-panel,
|
||||
.cart-items,
|
||||
.order-list,
|
||||
.requirements,
|
||||
.sample-credit-list,
|
||||
.subscription-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.drawer-section {
|
||||
padding: 18px;
|
||||
background: #f1f1f1;
|
||||
border: 1px solid #dddddd;
|
||||
}
|
||||
|
||||
.drawer-section h2,
|
||||
.drawer-section h3,
|
||||
.drawer-section p {
|
||||
margin-top: 0;
|
||||
}
|
||||
|
||||
.drawer-kicker {
|
||||
display: block;
|
||||
margin-bottom: 12px;
|
||||
font-size: 10px;
|
||||
letter-spacing: 0.22em;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.drawer-grid {
|
||||
display: grid;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.drawer-grid--two,
|
||||
.profile-read-grid,
|
||||
.toggle-grid,
|
||||
.payment-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.shop-field {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 7px;
|
||||
font-size: 11px;
|
||||
letter-spacing: 0.08em;
|
||||
text-transform: uppercase;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.shop-field input {
|
||||
width: 100%;
|
||||
min-height: 42px;
|
||||
border: 1px solid #d6d6d6;
|
||||
border-radius: 0;
|
||||
background: #f8f8f8;
|
||||
padding: 10px 11px;
|
||||
color: #1f1f1f;
|
||||
font: inherit;
|
||||
letter-spacing: 0;
|
||||
text-transform: none;
|
||||
}
|
||||
|
||||
.drawer-primary,
|
||||
.drawer-secondary,
|
||||
.cart-remove,
|
||||
.pref-toggle,
|
||||
.payment-card,
|
||||
.cart-controls button,
|
||||
.cart-toast button {
|
||||
border-radius: 0;
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
.drawer-primary {
|
||||
width: 100%;
|
||||
min-height: 46px;
|
||||
border: 1px solid #1f1f1f;
|
||||
background: #1f1f1f;
|
||||
color: #fff;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.12em;
|
||||
}
|
||||
|
||||
.drawer-primary:disabled {
|
||||
opacity: 0.45;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
|
||||
.drawer-secondary {
|
||||
min-height: 38px;
|
||||
border: 1px solid #d6d6d6;
|
||||
background: #f8f8f8;
|
||||
color: #1f1f1f;
|
||||
padding: 0 13px;
|
||||
}
|
||||
|
||||
.drawer-link-primary {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.cart-item,
|
||||
.order-card,
|
||||
.read-block,
|
||||
.status-box,
|
||||
.requirement-row {
|
||||
background: #f8f8f8;
|
||||
border: 1px solid #dddddd;
|
||||
}
|
||||
|
||||
.cart-item {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) auto auto;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
padding: 14px;
|
||||
}
|
||||
|
||||
.cart-item h3 {
|
||||
margin-bottom: 4px;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.cart-item p,
|
||||
.drawer-muted,
|
||||
.order-card p {
|
||||
margin: 0;
|
||||
color: #666;
|
||||
font-size: 13px;
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
.cart-controls {
|
||||
display: grid;
|
||||
grid-template-columns: 32px 32px 32px;
|
||||
align-items: center;
|
||||
border: 1px solid #d6d6d6;
|
||||
background: #f1f1f1;
|
||||
}
|
||||
|
||||
.cart-controls button {
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.cart-controls span {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.cart-remove {
|
||||
min-height: 34px;
|
||||
border: 1px solid #d6d6d6;
|
||||
background: #f8f8f8;
|
||||
padding: 0 10px;
|
||||
}
|
||||
|
||||
.payment-card {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
min-height: 60px;
|
||||
border: 1px solid #d6d6d6;
|
||||
background: #f8f8f8;
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.payment-card span {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 44px;
|
||||
height: 28px;
|
||||
background: #1f1f1f;
|
||||
color: #fff;
|
||||
font-size: 10px;
|
||||
letter-spacing: 0.08em;
|
||||
}
|
||||
|
||||
.payment-card.active {
|
||||
border-color: #ff6a00;
|
||||
background: rgba(255, 106, 0, 0.12);
|
||||
}
|
||||
|
||||
.totals-box {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.totals-box > div,
|
||||
.requirement-row {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.totals-box .discount-explainer {
|
||||
display: block;
|
||||
padding: 12px;
|
||||
border: 1px solid #dddddd;
|
||||
background: #f8f8f8;
|
||||
}
|
||||
|
||||
.discount-explainer span {
|
||||
display: block;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.discount-explainer p {
|
||||
margin: 0;
|
||||
color: #1f1f1f;
|
||||
font-size: 13px;
|
||||
line-height: 1.45;
|
||||
}
|
||||
|
||||
.discount-explainer p + p {
|
||||
margin-top: 6px;
|
||||
}
|
||||
|
||||
.total-row {
|
||||
padding-top: 10px;
|
||||
border-top: 1px solid #d6d6d6;
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.drawer-error {
|
||||
margin: 0;
|
||||
padding: 12px 14px;
|
||||
border: 1px solid #dddddd;
|
||||
background: #f8f8f8;
|
||||
color: #1f1f1f;
|
||||
}
|
||||
|
||||
.drawer-error {
|
||||
border-color: #ff6a00;
|
||||
}
|
||||
|
||||
.profile-head {
|
||||
display: grid;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.profile-head h2 {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.profile-read-grid {
|
||||
margin-top: 14px;
|
||||
}
|
||||
|
||||
.read-block {
|
||||
padding: 13px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 7px;
|
||||
}
|
||||
|
||||
.read-block span,
|
||||
.requirement-row span,
|
||||
.totals-box span {
|
||||
color: #666;
|
||||
font-size: 11px;
|
||||
letter-spacing: 0.08em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.status-box {
|
||||
padding: 14px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.sample-credit-list {
|
||||
margin-top: 12px;
|
||||
}
|
||||
|
||||
.sample-credit-list span {
|
||||
padding: 10px;
|
||||
background: #f8f8f8;
|
||||
border: 1px solid #dddddd;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.pref-toggle {
|
||||
min-height: 58px;
|
||||
padding: 12px;
|
||||
border: 1px solid #d6d6d6;
|
||||
background: #f8f8f8;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 6px;
|
||||
}
|
||||
|
||||
.pref-toggle.active {
|
||||
border-color: #ff6a00;
|
||||
background: rgba(255, 106, 0, 0.12);
|
||||
}
|
||||
|
||||
.subscription-list {
|
||||
margin-top: 16px;
|
||||
padding-top: 16px;
|
||||
border-top: 1px solid #d6d6d6;
|
||||
}
|
||||
|
||||
.subscription-list-title {
|
||||
color: #666;
|
||||
font-size: 10px;
|
||||
letter-spacing: 0.18em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.subscription-row {
|
||||
display: grid;
|
||||
grid-template-columns: minmax(0, 1fr) auto;
|
||||
gap: 12px;
|
||||
align-items: center;
|
||||
padding: 12px;
|
||||
border: 1px solid #dddddd;
|
||||
background: #f8f8f8;
|
||||
}
|
||||
|
||||
.subscription-row div {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.subscription-row span {
|
||||
color: #666;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.subscription-row button {
|
||||
min-height: 34px;
|
||||
border: 1px solid #d6d6d6;
|
||||
border-radius: 0;
|
||||
background: #f1f1f1;
|
||||
color: #1f1f1f;
|
||||
padding: 0 12px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.subscription-row button:hover {
|
||||
border-color: #ff6a00;
|
||||
}
|
||||
|
||||
.requirement-row {
|
||||
padding: 12px;
|
||||
}
|
||||
|
||||
.requirement-row strong.met {
|
||||
color: #ff6a00;
|
||||
}
|
||||
|
||||
.order-card {
|
||||
padding: 14px;
|
||||
}
|
||||
|
||||
.order-card div {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.cart-toast {
|
||||
position: fixed;
|
||||
right: 22px;
|
||||
bottom: 22px;
|
||||
z-index: 100;
|
||||
width: min(360px, calc(100vw - 44px));
|
||||
padding: 18px;
|
||||
border: 1px solid #d6d6d6;
|
||||
background: #f5f5f5;
|
||||
color: #1f1f1f;
|
||||
box-shadow: 0 18px 42px rgba(0, 0, 0, 0.22);
|
||||
}
|
||||
|
||||
.cart-toast p {
|
||||
margin: 8px 38px 14px 0;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
.cart-toast > button:last-child {
|
||||
min-height: 40px;
|
||||
width: 100%;
|
||||
border: 1px solid #1f1f1f;
|
||||
background: #1f1f1f;
|
||||
color: #fff;
|
||||
}
|
||||
|
||||
.cart-toast > button.cart-toast-close:last-child {
|
||||
width: 34px;
|
||||
min-height: 34px;
|
||||
border: 1px solid #d6d6d6;
|
||||
background: #f1f1f1;
|
||||
color: #1f1f1f;
|
||||
}
|
||||
|
||||
.cart-toast-close {
|
||||
position: absolute;
|
||||
top: 12px;
|
||||
right: 12px;
|
||||
}
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.shop-drawer {
|
||||
padding: 16px;
|
||||
}
|
||||
|
||||
.drawer-grid--two,
|
||||
.profile-read-grid,
|
||||
.toggle-grid,
|
||||
.payment-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
|
||||
.cart-item {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,476 @@
|
||||
import { useState } from "react";
|
||||
import { Link } from "react-router";
|
||||
import { formatChf } from "../shop/money";
|
||||
import { useShop } from "../shop/useShop";
|
||||
import "./ShopDrawer.css";
|
||||
|
||||
const paymentMethods = [
|
||||
{ key: "Bill", badge: "BILL", label: "Bill" },
|
||||
{ key: "Card", badge: "CARD", label: "Card" },
|
||||
{ key: "Twint", badge: "TW", label: "Twint" },
|
||||
{ key: "PayPal", badge: "PP", label: "PayPal" },
|
||||
];
|
||||
|
||||
const notificationLabels = [
|
||||
["drops_enabled", "New Drops"],
|
||||
["restocks_enabled", "Restocks"],
|
||||
["small_batch_enabled", "Small Batch Releases"],
|
||||
["discovery_enabled", "Discovery Set Updates"],
|
||||
];
|
||||
|
||||
function Field({ label, value, onChange, type = "text", readOnly = false }) {
|
||||
return (
|
||||
<label className="shop-field">
|
||||
<span>{label}</span>
|
||||
<input
|
||||
type={type}
|
||||
value={value}
|
||||
readOnly={readOnly}
|
||||
onChange={(event) => onChange?.(event.target.value)}
|
||||
/>
|
||||
</label>
|
||||
);
|
||||
}
|
||||
|
||||
function AuthPanel() {
|
||||
const { busy, error, login, register } = useShop();
|
||||
const [mode, setMode] = useState("login");
|
||||
const [form, setForm] = useState({
|
||||
first_name: "",
|
||||
surname: "",
|
||||
email: "",
|
||||
password: "",
|
||||
});
|
||||
|
||||
const update = (key, value) => setForm((current) => ({ ...current, [key]: value }));
|
||||
|
||||
const submit = (event) => {
|
||||
event.preventDefault();
|
||||
if (mode === "login") {
|
||||
login({ email: form.email, password: form.password }).catch(() => {});
|
||||
return;
|
||||
}
|
||||
register(form).catch(() => {});
|
||||
};
|
||||
|
||||
return (
|
||||
<form className="drawer-section auth-panel" onSubmit={submit}>
|
||||
<span className="drawer-kicker">{mode === "login" ? "LOGIN" : "REGISTER"}</span>
|
||||
<h2>{mode === "login" ? "Welcome back." : "Create your atmos account."}</h2>
|
||||
|
||||
{mode === "register" && (
|
||||
<div className="drawer-grid drawer-grid--two">
|
||||
<Field label="Name" value={form.first_name} onChange={(value) => update("first_name", value)} />
|
||||
<Field label="Surname" value={form.surname} onChange={(value) => update("surname", value)} />
|
||||
</div>
|
||||
)}
|
||||
|
||||
<Field label="Email address" value={form.email} onChange={(value) => update("email", value)} />
|
||||
<Field
|
||||
label="Password"
|
||||
type="password"
|
||||
value={form.password}
|
||||
onChange={(value) => update("password", value)}
|
||||
/>
|
||||
|
||||
{error && <p className="drawer-error">{error}</p>}
|
||||
|
||||
<button className="drawer-primary" type="submit" disabled={busy}>
|
||||
{mode === "login" ? "Login" : "Register"}
|
||||
</button>
|
||||
|
||||
<button
|
||||
className="drawer-secondary"
|
||||
type="button"
|
||||
onClick={() => setMode((current) => (current === "login" ? "register" : "login"))}
|
||||
>
|
||||
{mode === "login" ? "Create account" : "Use existing account"}
|
||||
</button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
function CartPanel() {
|
||||
const {
|
||||
cart,
|
||||
checkout,
|
||||
removeCartItem,
|
||||
updateCartQuantity,
|
||||
busy,
|
||||
error,
|
||||
user,
|
||||
} = useShop();
|
||||
const [address, setAddress] = useState(() => ({
|
||||
street_name: user?.street_name || "",
|
||||
house_number: user?.house_number || "",
|
||||
zip_code: user?.zip_code || "",
|
||||
city: user?.city || "",
|
||||
}));
|
||||
const [paymentMethod, setPaymentMethod] = useState("Bill");
|
||||
|
||||
const updateAddress = (key, value) =>
|
||||
setAddress((current) => ({ ...current, [key]: value }));
|
||||
|
||||
const submit = (event) => {
|
||||
event.preventDefault();
|
||||
checkout({ ...address, payment_method: paymentMethod }).catch(() => {});
|
||||
};
|
||||
|
||||
return (
|
||||
<form className="drawer-stack" onSubmit={submit}>
|
||||
<section className="drawer-section">
|
||||
<span className="drawer-kicker">CART</span>
|
||||
{cart.items.length === 0 ? (
|
||||
<p className="drawer-muted">Your cart is empty.</p>
|
||||
) : (
|
||||
<div className="cart-items">
|
||||
{cart.items.map((item) => (
|
||||
<article className="cart-item" key={item.product_id}>
|
||||
<div>
|
||||
<h3>{item.product.name}</h3>
|
||||
<p>
|
||||
{item.product.size_label} · {formatChf(item.product.price_cents)}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="cart-controls">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => updateCartQuantity(item.product_id, item.quantity - 1)}
|
||||
>
|
||||
-
|
||||
</button>
|
||||
<span>{item.quantity}</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => updateCartQuantity(item.product_id, item.quantity + 1)}
|
||||
>
|
||||
+
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<button
|
||||
className="cart-remove"
|
||||
type="button"
|
||||
onClick={() => removeCartItem(item.product_id)}
|
||||
>
|
||||
Remove
|
||||
</button>
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
<section className="drawer-section">
|
||||
<span className="drawer-kicker">SHIPPING</span>
|
||||
<div className="drawer-grid drawer-grid--two">
|
||||
<Field label="Street Name" value={address.street_name} onChange={(value) => updateAddress("street_name", value)} />
|
||||
<Field label="House Number" value={address.house_number} onChange={(value) => updateAddress("house_number", value)} />
|
||||
<Field label="ZIP Code" value={address.zip_code} onChange={(value) => updateAddress("zip_code", value)} />
|
||||
<Field label="City" value={address.city} onChange={(value) => updateAddress("city", value)} />
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="drawer-section">
|
||||
<span className="drawer-kicker">PAYMENT</span>
|
||||
<div className="payment-grid">
|
||||
{paymentMethods.map((method) => (
|
||||
<button
|
||||
type="button"
|
||||
className={`payment-card ${paymentMethod === method.key ? "active" : ""}`}
|
||||
key={method.key}
|
||||
onClick={() => setPaymentMethod(method.key)}
|
||||
>
|
||||
<span>{method.badge}</span>
|
||||
<strong>{method.label}</strong>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="drawer-section totals-box">
|
||||
<div>
|
||||
<span>Subtotal</span>
|
||||
<strong>{formatChf(cart.subtotal_cents)}</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span>Rabatte</span>
|
||||
<strong>-{formatChf(cart.discount_cents)}</strong>
|
||||
</div>
|
||||
{cart.discounts?.length > 0 && (
|
||||
<div className="discount-explainer">
|
||||
<span>Applied automatically</span>
|
||||
{cart.discounts.map((discount) => (
|
||||
<p key={`${discount.type}-${discount.creditId}`}>
|
||||
<strong>{formatChf(discount.amount_cents)}</strong>
|
||||
{" - "}
|
||||
{discount.type === "discovery"
|
||||
? "Discovery Set credit for a full-size bottle"
|
||||
: `Sample credit for ${discount.slug}`}
|
||||
</p>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
<div className="total-row">
|
||||
<span>Total</span>
|
||||
<strong>{formatChf(cart.total_cents)}</strong>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{error && <p className="drawer-error">{error}</p>}
|
||||
|
||||
<button className="drawer-primary" type="submit" disabled={busy || cart.items.length === 0}>
|
||||
Checkout
|
||||
</button>
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
function RequirementRow({ label, met, children }) {
|
||||
return (
|
||||
<div className="requirement-row">
|
||||
<span>{label}</span>
|
||||
<strong className={met ? "met" : ""}>{children || (met ? "met" : "open")}</strong>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ProfilePanel() {
|
||||
const {
|
||||
busy,
|
||||
error,
|
||||
logout,
|
||||
orders,
|
||||
removeProductSubscription,
|
||||
updateNotifications,
|
||||
updateProfile,
|
||||
user,
|
||||
closePanel,
|
||||
} = useShop();
|
||||
const [editing, setEditing] = useState(false);
|
||||
const [form, setForm] = useState(user || {});
|
||||
|
||||
const update = (key, value) => setForm((current) => ({ ...current, [key]: value }));
|
||||
const notifications = user?.notifications || {};
|
||||
const restockSubscriptions = (user?.productSubscriptions || []).filter(
|
||||
(subscription) => subscription.type === "restock"
|
||||
);
|
||||
const loyalty = user?.loyaltyStatus || {
|
||||
hasDiscoverySet: false,
|
||||
hasFullSize: false,
|
||||
purchases: 0,
|
||||
spent_cents: 0,
|
||||
unlocked: false,
|
||||
};
|
||||
|
||||
const save = () => {
|
||||
updateProfile({
|
||||
first_name: form.first_name,
|
||||
surname: form.surname,
|
||||
street_name: form.street_name,
|
||||
house_number: form.house_number,
|
||||
zip_code: form.zip_code,
|
||||
city: form.city,
|
||||
birthdate: form.birthdate,
|
||||
})
|
||||
.then(() => setEditing(false))
|
||||
.catch(() => {});
|
||||
};
|
||||
|
||||
const togglePreference = (key) => {
|
||||
updateNotifications({ ...notifications, [key]: !notifications[key] }).catch(() => {});
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="drawer-stack">
|
||||
<section className="drawer-section profile-head">
|
||||
<span className="drawer-kicker">PROFILE</span>
|
||||
<h2>Hi, {user.first_name}</h2>
|
||||
<button className="drawer-secondary" type="button" onClick={logout}>
|
||||
Logout
|
||||
</button>
|
||||
</section>
|
||||
|
||||
<section className="drawer-section">
|
||||
<div className="profile-section-header">
|
||||
<span className="drawer-kicker">PROFILE INFORMATION</span>
|
||||
{!editing && (
|
||||
<button className="drawer-secondary" type="button" onClick={() => setEditing(true)}>
|
||||
Profil bearbeiten
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{editing ? (
|
||||
<>
|
||||
<div className="drawer-grid drawer-grid--two">
|
||||
<Field label="Name" value={form.first_name || ""} onChange={(value) => update("first_name", value)} />
|
||||
<Field label="Surname" value={form.surname || ""} onChange={(value) => update("surname", value)} />
|
||||
<Field label="Street Name" value={form.street_name || ""} onChange={(value) => update("street_name", value)} />
|
||||
<Field label="House Number" value={form.house_number || ""} onChange={(value) => update("house_number", value)} />
|
||||
<Field label="ZIP Code" value={form.zip_code || ""} onChange={(value) => update("zip_code", value)} />
|
||||
<Field label="City" value={form.city || ""} onChange={(value) => update("city", value)} />
|
||||
<Field label="Birthdate" type="date" value={form.birthdate || ""} onChange={(value) => update("birthdate", value)} />
|
||||
</div>
|
||||
<div className="drawer-actions">
|
||||
<button className="drawer-primary" type="button" disabled={busy} onClick={save}>
|
||||
Save profile
|
||||
</button>
|
||||
<button
|
||||
className="drawer-secondary"
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setForm(user);
|
||||
setEditing(false);
|
||||
}}
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<div className="profile-read-grid">
|
||||
<ReadBlock label="Name" value={user.first_name} />
|
||||
<ReadBlock label="Surname" value={user.surname} />
|
||||
<ReadBlock label="Street Name" value={user.street_name || "-"} />
|
||||
<ReadBlock label="House Number" value={user.house_number || "-"} />
|
||||
<ReadBlock label="ZIP Code" value={user.zip_code || "-"} />
|
||||
<ReadBlock label="City" value={user.city || "-"} />
|
||||
<ReadBlock label="Birthdate" value={user.birthdate || "-"} />
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
<section className="drawer-section">
|
||||
<span className="drawer-kicker">DISCOUNT STATUS</span>
|
||||
<div className="status-box">{user.discoveryStatus}</div>
|
||||
{user.sampleCredits?.length > 0 && (
|
||||
<div className="sample-credit-list">
|
||||
{user.sampleCredits.map((credit) => (
|
||||
<span key={`${credit.slug}-${credit.created_at}`}>
|
||||
{credit.slug}: {credit.status}
|
||||
</span>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
<section className="drawer-section">
|
||||
<span className="drawer-kicker">DROP / RESTOCK PREFERENCES</span>
|
||||
<div className="toggle-grid">
|
||||
{notificationLabels.map(([key, label]) => (
|
||||
<button
|
||||
key={key}
|
||||
type="button"
|
||||
className={`pref-toggle ${notifications[key] ? "active" : ""}`}
|
||||
onClick={() => togglePreference(key)}
|
||||
>
|
||||
<span>{label}</span>
|
||||
<strong>{notifications[key] ? "Active" : "Inactive"}</strong>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
<div className="subscription-list">
|
||||
<span className="subscription-list-title">Subscribed Restocks</span>
|
||||
{restockSubscriptions.length === 0 ? (
|
||||
<p className="drawer-muted">No product-specific restock updates yet.</p>
|
||||
) : (
|
||||
restockSubscriptions.map((subscription) => (
|
||||
<article className="subscription-row" key={subscription.id}>
|
||||
<div>
|
||||
<strong>{subscription.name}</strong>
|
||||
<span>{subscription.size_label}</span>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => removeProductSubscription(subscription.id).catch(() => {})}
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
</article>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<section className="drawer-section">
|
||||
<span className="drawer-kicker">SMALL BATCH ACCESS</span>
|
||||
<div className="status-box">{loyalty.unlocked ? "Unlocked" : "Locked"}</div>
|
||||
<div className="requirements">
|
||||
<RequirementRow label="Discovery Set" met={loyalty.hasDiscoverySet} />
|
||||
<RequirementRow label="Full Size" met={loyalty.hasFullSize} />
|
||||
<RequirementRow label="Purchases" met={loyalty.purchases >= 3}>
|
||||
{loyalty.purchases}/3 Purchases
|
||||
</RequirementRow>
|
||||
<RequirementRow label="Spend" met={loyalty.spent_cents > 50000}>
|
||||
{formatChf(loyalty.spent_cents)} / CHF 500+
|
||||
</RequirementRow>
|
||||
</div>
|
||||
<Link
|
||||
className="drawer-primary drawer-link-primary"
|
||||
to="/small-batch"
|
||||
onClick={closePanel}
|
||||
>
|
||||
Small Batch ansehen
|
||||
</Link>
|
||||
</section>
|
||||
|
||||
<section className="drawer-section">
|
||||
<span className="drawer-kicker">PURCHASES</span>
|
||||
{orders.length === 0 ? (
|
||||
<p className="drawer-muted">No orders yet.</p>
|
||||
) : (
|
||||
<div className="order-list">
|
||||
{orders.map((order) => (
|
||||
<article className="order-card" key={order.id}>
|
||||
<div>
|
||||
<strong>Order #{order.id}</strong>
|
||||
<span>{new Date(order.created_at).toLocaleDateString("de-CH")}</span>
|
||||
</div>
|
||||
<p>{order.items.map((item) => `${item.quantity} x ${item.product.name}`).join(", ")}</p>
|
||||
<strong>{formatChf(order.total_cents)}</strong>
|
||||
</article>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
{error && <p className="drawer-error">{error}</p>}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ReadBlock({ label, value }) {
|
||||
return (
|
||||
<div className="read-block">
|
||||
<span>{label}</span>
|
||||
<strong>{value}</strong>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ShopDrawer() {
|
||||
const { closePanel, panelOpen, panelType, user } = useShop();
|
||||
|
||||
return (
|
||||
<>
|
||||
<div
|
||||
className={`drawer-backdrop ${panelOpen ? "open" : ""}`}
|
||||
onClick={closePanel}
|
||||
/>
|
||||
<aside className={`shop-drawer ${panelOpen ? "open" : ""}`} aria-hidden={!panelOpen}>
|
||||
<div className="drawer-top">
|
||||
<span>{!user ? "ACCOUNT" : panelType === "cart" ? "CART" : "PROFILE"}</span>
|
||||
<button type="button" onClick={closePanel} aria-label="Close panel">
|
||||
x
|
||||
</button>
|
||||
</div>
|
||||
{!user ? <AuthPanel /> : panelType === "cart" ? <CartPanel /> : <ProfilePanel />}
|
||||
</aside>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default ShopDrawer;
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Link } from "react-router";
|
||||
import IntroOverlay from "./IntroOverlay";
|
||||
import SharedNavbar from "../SharedNavbar";
|
||||
|
||||
function HeroSection({
|
||||
heroImageWrapRef,
|
||||
@@ -32,22 +33,7 @@ function HeroSection({
|
||||
/>
|
||||
</Link>
|
||||
|
||||
<nav className="navbar navbar--hero" aria-label="Hauptnavigation">
|
||||
<div className="nav-pill">
|
||||
<a href="#home" className="nav-link active">
|
||||
atmos
|
||||
</a>
|
||||
<a href="#dufte" className="nav-link">
|
||||
{"D\u00FCfte"}
|
||||
</a>
|
||||
<Link to="/discovery-set" className="nav-link">
|
||||
Testen
|
||||
</Link>
|
||||
<a href="#cart" className="nav-link">
|
||||
Cart
|
||||
</a>
|
||||
</div>
|
||||
</nav>
|
||||
<SharedNavbar variant="hero" active="atmos" />
|
||||
|
||||
<div className="hero-content">
|
||||
<h1 className="hero-title">
|
||||
|
||||
@@ -2,12 +2,15 @@ import React from "react";
|
||||
import ReactDOM from "react-dom/client";
|
||||
import { BrowserRouter } from "react-router";
|
||||
import App from "./App";
|
||||
import { ShopProvider } from "./shop/ShopContext";
|
||||
import "./App.css";
|
||||
|
||||
ReactDOM.createRoot(document.getElementById("root")).render(
|
||||
<React.StrictMode>
|
||||
<BrowserRouter>
|
||||
<App />
|
||||
<ShopProvider>
|
||||
<App />
|
||||
</ShopProvider>
|
||||
</BrowserRouter>
|
||||
</React.StrictMode>
|
||||
);
|
||||
);
|
||||
@@ -1,26 +1,10 @@
|
||||
import { Link } from "react-router";
|
||||
import "../style/navbar.css";
|
||||
import SharedNavbar from "../components/SharedNavbar";
|
||||
import "./AboutPage.css";
|
||||
|
||||
function AboutPage() {
|
||||
return (
|
||||
<div className="about-page">
|
||||
<nav className="navbar navbar--light">
|
||||
<div className="nav-pill">
|
||||
<Link to="/" className="nav-link">
|
||||
atmos
|
||||
</Link>
|
||||
<Link to="/#dufte" className="nav-link">
|
||||
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="about-shell">
|
||||
<section className="about-hero">
|
||||
@@ -314,4 +298,4 @@ function AboutPage() {
|
||||
);
|
||||
}
|
||||
|
||||
export default AboutPage;
|
||||
export default AboutPage;
|
||||
@@ -1,26 +1,10 @@
|
||||
import { Link } from "react-router";
|
||||
import "../style/navbar.css";
|
||||
import SharedNavbar from "../components/SharedNavbar";
|
||||
import "./DatenschutzPage.css";
|
||||
|
||||
function DatenschutzPage() {
|
||||
return (
|
||||
<div className="datenschutz-page">
|
||||
<nav className="navbar navbar--light">
|
||||
<div className="nav-pill">
|
||||
<Link to="/" className="nav-link">
|
||||
atmos
|
||||
</Link>
|
||||
<Link to="/#dufte" className="nav-link">
|
||||
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="datenschutz-shell">
|
||||
<section className="datenschutz-hero">
|
||||
@@ -227,4 +211,4 @@ function DatenschutzPage() {
|
||||
);
|
||||
}
|
||||
|
||||
export default DatenschutzPage;
|
||||
export default DatenschutzPage;
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Link, useNavigate } from "react-router";
|
||||
import { useNavigate } from "react-router";
|
||||
import perfumes from "../data/perfumes";
|
||||
import "../style/navbar.css";
|
||||
import SharedNavbar from "../components/SharedNavbar";
|
||||
import { useShop } from "../shop/useShop";
|
||||
import "./DiscoverySetPage.css";
|
||||
|
||||
const moodImages = [
|
||||
@@ -14,25 +15,13 @@ const moodImages = [
|
||||
|
||||
function DiscoverySetPage() {
|
||||
const navigate = useNavigate();
|
||||
const { addToCart } = useShop();
|
||||
const buyDiscoverySet = () =>
|
||||
addToCart("discovery-set", 1, "Discovery Set added.").catch(() => {});
|
||||
|
||||
return (
|
||||
<div className="discovery-page">
|
||||
<nav className="navbar navbar--light">
|
||||
<div className="nav-pill">
|
||||
<Link to="/" className="nav-link">
|
||||
atmos
|
||||
</Link>
|
||||
<Link to="/#dufte" className="nav-link">
|
||||
Düfte
|
||||
</Link>
|
||||
<Link to="/discovery-set" className="nav-link active">
|
||||
Testen
|
||||
</Link>
|
||||
<a href="#cart" className="nav-link">
|
||||
Cart
|
||||
</a>
|
||||
</div>
|
||||
</nav>
|
||||
<SharedNavbar variant="light" active="testen" />
|
||||
|
||||
<main className="discovery-shell">
|
||||
<div className="discovery-topbar">
|
||||
@@ -75,8 +64,8 @@ function DiscoverySetPage() {
|
||||
<div>
|
||||
<strong>CHF 48 Gutschein automatisch im Set</strong>
|
||||
<p>
|
||||
Wird beim späteren Full-Size-Kauf angerechnet – kein manuelles
|
||||
Einlösen nötig.
|
||||
Nur das erste Discovery Set erstellt den einmaligen Rabatt.
|
||||
Er wird bei einem späteren Full-Size-Kauf automatisch angerechnet.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
@@ -105,10 +94,10 @@ function DiscoverySetPage() {
|
||||
</div>
|
||||
|
||||
<div className="discovery-hero-actions">
|
||||
<button type="button" className="discovery-primary-btn">
|
||||
<button type="button" className="discovery-primary-btn" onClick={buyDiscoverySet}>
|
||||
DISCOVERY SET BESTELLEN – CHF 48.–
|
||||
</button>
|
||||
<p>Wird bei jedem Full-Size-Kauf angerechnet</p>
|
||||
<p>Nur das erste Set erstellt einen einmaligen CHF 48 Full-Size-Rabatt</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -158,8 +147,8 @@ function DiscoverySetPage() {
|
||||
<div className="discovery-step-number">1</div>
|
||||
<h3>Bestellen</h3>
|
||||
<p>
|
||||
Discovery Set für CHF 48 bestellen. Der Gutschein-Code ist
|
||||
automatisch im Set enthalten.
|
||||
Discovery Set für CHF 48 bestellen. Nur dein erstes Set erzeugt
|
||||
automatisch einen einmaligen Rabatt.
|
||||
</p>
|
||||
</article>
|
||||
|
||||
@@ -176,8 +165,8 @@ function DiscoverySetPage() {
|
||||
<div className="discovery-step-number">3</div>
|
||||
<h3>Entscheiden</h3>
|
||||
<p>
|
||||
Full-Size bestellen. CHF 48 werden automatisch angerechnet.
|
||||
Kein Risiko, kein Verlust.
|
||||
Full-Size bestellen. CHF 48 werden automatisch angerechnet,
|
||||
sofern der Rabatt noch nicht genutzt wurde.
|
||||
</p>
|
||||
</article>
|
||||
</div>
|
||||
@@ -215,17 +204,17 @@ function DiscoverySetPage() {
|
||||
</div>
|
||||
<p>
|
||||
CHF 48 investieren, alle Düfte testen, bewusst entscheiden. Die
|
||||
Investition wird vollständig angerechnet – der Einstieg bleibt
|
||||
kontrolliert und nachvollziehbar.
|
||||
erste Investition wird einmalig angerechnet – der Einstieg bleibt
|
||||
kontrolliert, nachvollziehbar und fair.
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="discovery-bottom-cta">
|
||||
<button type="button" className="discovery-primary-btn">
|
||||
<button type="button" className="discovery-primary-btn" onClick={buyDiscoverySet}>
|
||||
DISCOVERY SET BESTELLEN – CHF 48.–
|
||||
</button>
|
||||
<p>Kostenloser Versand · 2–3 Werktage · Volle Anrechnung bei Full-Size</p>
|
||||
<p>Kostenloser Versand · 2–3 Werktage · Einmalige Anrechnung bei Full-Size</p>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
@@ -233,4 +222,4 @@ function DiscoverySetPage() {
|
||||
);
|
||||
}
|
||||
|
||||
export default DiscoverySetPage;
|
||||
export default DiscoverySetPage;
|
||||
@@ -1,26 +1,10 @@
|
||||
import { Link } from "react-router";
|
||||
import "../style/navbar.css";
|
||||
import SharedNavbar from "../components/SharedNavbar";
|
||||
import "./ImpressumPage.css";
|
||||
|
||||
function ImpressumPage() {
|
||||
return (
|
||||
<div className="impressum-page">
|
||||
<nav className="navbar navbar--light">
|
||||
<div className="nav-pill">
|
||||
<Link to="/" className="nav-link">
|
||||
atmos
|
||||
</Link>
|
||||
<Link to="/#dufte" className="nav-link">
|
||||
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="impressum-shell">
|
||||
<section className="impressum-hero">
|
||||
@@ -160,4 +144,4 @@ function ImpressumPage() {
|
||||
);
|
||||
}
|
||||
|
||||
export default ImpressumPage;
|
||||
export default ImpressumPage;
|
||||
@@ -0,0 +1,125 @@
|
||||
.small-page {
|
||||
min-height: 100vh;
|
||||
padding: 26px 38px 38px;
|
||||
background: #efefef;
|
||||
color: #1f1f1f;
|
||||
}
|
||||
|
||||
.small-shell {
|
||||
background: #f5f5f5;
|
||||
border: 1px solid #d9d9d9;
|
||||
padding: 38px;
|
||||
}
|
||||
|
||||
.small-hero {
|
||||
max-width: 780px;
|
||||
padding-bottom: 34px;
|
||||
border-bottom: 1px solid #dddddd;
|
||||
margin-bottom: 28px;
|
||||
}
|
||||
|
||||
.small-kicker {
|
||||
display: block;
|
||||
margin-bottom: 12px;
|
||||
color: #666;
|
||||
font-size: 10px;
|
||||
letter-spacing: 0.22em;
|
||||
}
|
||||
|
||||
.small-hero h1,
|
||||
.small-panel h2 {
|
||||
margin: 0 0 14px;
|
||||
letter-spacing: 0;
|
||||
}
|
||||
|
||||
.small-hero h1 {
|
||||
font-size: clamp(42px, 8vw, 92px);
|
||||
line-height: 0.92;
|
||||
}
|
||||
|
||||
.small-hero p,
|
||||
.small-panel p,
|
||||
.release-card p {
|
||||
margin: 0;
|
||||
color: #666;
|
||||
line-height: 1.55;
|
||||
}
|
||||
|
||||
.small-panel,
|
||||
.release-card,
|
||||
.small-error {
|
||||
background: #f1f1f1;
|
||||
border: 1px solid #dddddd;
|
||||
padding: 22px;
|
||||
}
|
||||
|
||||
.small-panel button,
|
||||
.release-card button {
|
||||
min-height: 44px;
|
||||
margin-top: 18px;
|
||||
border: 1px solid #1f1f1f;
|
||||
border-radius: 0;
|
||||
background: #1f1f1f;
|
||||
color: #fff;
|
||||
padding: 0 18px;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.small-requirements {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 12px;
|
||||
margin-top: 18px;
|
||||
}
|
||||
|
||||
.small-requirement {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
gap: 12px;
|
||||
padding: 14px;
|
||||
background: #f8f8f8;
|
||||
border: 1px solid #dddddd;
|
||||
}
|
||||
|
||||
.small-requirement span,
|
||||
.release-card span {
|
||||
color: #666;
|
||||
font-size: 10px;
|
||||
letter-spacing: 0.18em;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.small-requirement strong.met {
|
||||
color: #ff6a00;
|
||||
}
|
||||
|
||||
.release-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 16px;
|
||||
margin-top: 22px;
|
||||
}
|
||||
|
||||
.release-card h3 {
|
||||
margin: 10px 0 12px;
|
||||
}
|
||||
|
||||
.small-error {
|
||||
margin: 16px 0 0;
|
||||
border-color: #ff6a00;
|
||||
}
|
||||
|
||||
@media (max-width: 760px) {
|
||||
.small-page {
|
||||
padding: 18px;
|
||||
}
|
||||
|
||||
.small-shell {
|
||||
padding: 24px 18px;
|
||||
}
|
||||
|
||||
.small-requirements,
|
||||
.release-grid {
|
||||
grid-template-columns: 1fr;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,123 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import SharedNavbar from "../components/SharedNavbar";
|
||||
import { formatChf } from "../shop/money";
|
||||
import { useShop } from "../shop/useShop";
|
||||
import "./SmallBatchPage.css";
|
||||
|
||||
function Requirement({ label, met, children }) {
|
||||
return (
|
||||
<div className="small-requirement">
|
||||
<span>{label}</span>
|
||||
<strong className={met ? "met" : ""}>{children || (met ? "met" : "open")}</strong>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function SmallBatchPage() {
|
||||
const { openProfile, token, user } = useShop();
|
||||
const [state, setState] = useState({
|
||||
loading: false,
|
||||
error: "",
|
||||
loyaltyStatus: user?.loyaltyStatus || null,
|
||||
releases: [],
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (!token) return;
|
||||
|
||||
fetch("/api/small-batch", {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
})
|
||||
.then(async (response) => {
|
||||
const data = await response.json().catch(() => ({}));
|
||||
if (!response.ok) throw new Error(data.error || "Small Batch request failed.");
|
||||
setState({
|
||||
loading: false,
|
||||
error: "",
|
||||
loyaltyStatus: data.loyaltyStatus,
|
||||
releases: data.releases || [],
|
||||
});
|
||||
})
|
||||
.catch((error) => {
|
||||
setState((current) => ({
|
||||
...current,
|
||||
loading: false,
|
||||
error:
|
||||
error instanceof Error
|
||||
? error.message
|
||||
: "Shop API unreachable. Start it with npm run dev and try again.",
|
||||
}));
|
||||
});
|
||||
}, [token, user?.loyaltyStatus]);
|
||||
|
||||
const loyalty = state.loyaltyStatus || {
|
||||
hasDiscoverySet: false,
|
||||
hasFullSize: false,
|
||||
purchases: 0,
|
||||
spent_cents: 0,
|
||||
unlocked: false,
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="small-page">
|
||||
<SharedNavbar variant="light" />
|
||||
|
||||
<main className="small-shell">
|
||||
<section className="small-hero">
|
||||
<span className="small-kicker">SMALL BATCH / ARCHIVE / PROTOTYPE</span>
|
||||
<h1>EARLY ACCESS</h1>
|
||||
<p>
|
||||
Limited releases are reserved for customers with enough purchase
|
||||
history to understand the atmos material language.
|
||||
</p>
|
||||
</section>
|
||||
|
||||
{!user ? (
|
||||
<section className="small-panel">
|
||||
<span className="small-kicker">LOGIN REQUIRED</span>
|
||||
<h2>Sign in to check access.</h2>
|
||||
<p>Small Batch access is calculated from your completed orders.</p>
|
||||
<button type="button" onClick={openProfile}>
|
||||
Login / Register
|
||||
</button>
|
||||
</section>
|
||||
) : (
|
||||
<>
|
||||
<section className="small-panel">
|
||||
<span className="small-kicker">ACCESS STATUS</span>
|
||||
<h2>{loyalty.unlocked ? "Unlocked" : "Locked"}</h2>
|
||||
<div className="small-requirements">
|
||||
<Requirement label="Discovery Set" met={loyalty.hasDiscoverySet} />
|
||||
<Requirement label="Full Size" met={loyalty.hasFullSize} />
|
||||
<Requirement label="Purchases" met={loyalty.purchases >= 3}>
|
||||
{loyalty.purchases}/3 Purchases
|
||||
</Requirement>
|
||||
<Requirement label="Spend" met={loyalty.spent_cents > 50000}>
|
||||
{formatChf(loyalty.spent_cents)} / CHF 500+
|
||||
</Requirement>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
{state.error && <p className="small-error">{state.error}</p>}
|
||||
{state.loading && <p className="small-error">Loading access...</p>}
|
||||
|
||||
{loyalty.unlocked && (
|
||||
<section className="release-grid">
|
||||
{state.releases.map((release) => (
|
||||
<article className="release-card" key={release.name}>
|
||||
<span>{release.type}</span>
|
||||
<h3>{release.name}</h3>
|
||||
<p>{release.note}</p>
|
||||
<button type="button">Request Allocation</button>
|
||||
</article>
|
||||
))}
|
||||
</section>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</main>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default SmallBatchPage;
|
||||
@@ -1,26 +1,10 @@
|
||||
import { Link } from "react-router";
|
||||
import "../style/navbar.css";
|
||||
import SharedNavbar from "../components/SharedNavbar";
|
||||
import "./SupportPage.css";
|
||||
|
||||
function SupportPage() {
|
||||
return (
|
||||
<div className="support-page">
|
||||
<nav className="navbar navbar--light">
|
||||
<div className="nav-pill">
|
||||
<Link to="/" className="nav-link">
|
||||
atmos
|
||||
</Link>
|
||||
<Link to="/#dufte" className="nav-link">
|
||||
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="support-shell">
|
||||
<section className="support-hero">
|
||||
@@ -210,4 +194,4 @@ function SupportPage() {
|
||||
);
|
||||
}
|
||||
|
||||
export default SupportPage;
|
||||
export default SupportPage;
|
||||
@@ -0,0 +1,408 @@
|
||||
import {
|
||||
useCallback,
|
||||
useEffect,
|
||||
useMemo,
|
||||
useState,
|
||||
} from "react";
|
||||
import { ShopContext } from "./ShopContextBase";
|
||||
|
||||
const TOKEN_KEY = "atmos-shop-token";
|
||||
|
||||
const request = async (path, options = {}, token) => {
|
||||
const headers = {
|
||||
"Content-Type": "application/json",
|
||||
...(options.headers || {}),
|
||||
};
|
||||
|
||||
if (token) {
|
||||
headers.Authorization = `Bearer ${token}`;
|
||||
}
|
||||
|
||||
let response;
|
||||
try {
|
||||
response = await fetch(path, { ...options, headers });
|
||||
} catch {
|
||||
throw new Error("Shop API unreachable. Start it with npm run dev and try again.");
|
||||
}
|
||||
|
||||
const data = await response.json().catch(() => ({}));
|
||||
if (!response.ok) {
|
||||
throw new Error(data.error || "Shop request failed.");
|
||||
}
|
||||
return data;
|
||||
};
|
||||
|
||||
export function ShopProvider({ children }) {
|
||||
const [token, setToken] = useState(() => localStorage.getItem(TOKEN_KEY));
|
||||
const [user, setUser] = useState(null);
|
||||
const [cart, setCart] = useState({
|
||||
items: [],
|
||||
subtotal_cents: 0,
|
||||
discount_cents: 0,
|
||||
total_cents: 0,
|
||||
total_quantity: 0,
|
||||
discounts: [],
|
||||
});
|
||||
const [orders, setOrders] = useState([]);
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
const [panelOpen, setPanelOpen] = useState(false);
|
||||
const [panelType, setPanelType] = useState("profile");
|
||||
const [cartToast, setCartToast] = useState(null);
|
||||
|
||||
const applyState = useCallback((payload) => {
|
||||
if (payload.user) setUser(payload.user);
|
||||
if (payload.cart) setCart(payload.cart);
|
||||
if (payload.orders) setOrders(payload.orders);
|
||||
if (payload.token) {
|
||||
setToken(payload.token);
|
||||
localStorage.setItem(TOKEN_KEY, payload.token);
|
||||
}
|
||||
}, []);
|
||||
|
||||
const run = useCallback(
|
||||
async (task) => {
|
||||
setBusy(true);
|
||||
setError("");
|
||||
try {
|
||||
return await task();
|
||||
} catch (err) {
|
||||
const message = err instanceof Error ? err.message : "Something went wrong.";
|
||||
setError(message);
|
||||
throw err;
|
||||
} finally {
|
||||
setBusy(false);
|
||||
}
|
||||
},
|
||||
[]
|
||||
);
|
||||
|
||||
const showToast = useCallback((toast) => {
|
||||
setCartToast(toast);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!token) return;
|
||||
request("/api/auth/session", {}, token)
|
||||
.then(applyState)
|
||||
.catch(() => {
|
||||
localStorage.removeItem(TOKEN_KEY);
|
||||
setToken(null);
|
||||
setUser(null);
|
||||
});
|
||||
}, [applyState, token]);
|
||||
|
||||
const register = useCallback(
|
||||
(payload) =>
|
||||
run(async () => {
|
||||
const data = await request(
|
||||
"/api/auth/register",
|
||||
{ method: "POST", body: JSON.stringify(payload) },
|
||||
null
|
||||
);
|
||||
applyState(data);
|
||||
setPanelType("profile");
|
||||
showToast({
|
||||
title: "Account created",
|
||||
message: "Your profile is ready.",
|
||||
actionLabel: "Profile",
|
||||
actionPanel: "profile",
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[applyState, run, showToast]
|
||||
);
|
||||
|
||||
const login = useCallback(
|
||||
(payload) =>
|
||||
run(async () => {
|
||||
const data = await request(
|
||||
"/api/auth/login",
|
||||
{ method: "POST", body: JSON.stringify(payload) },
|
||||
null
|
||||
);
|
||||
applyState(data);
|
||||
setPanelType("profile");
|
||||
showToast({
|
||||
title: "Logged in",
|
||||
message: "Welcome back to atmos.",
|
||||
actionLabel: "Profile",
|
||||
actionPanel: "profile",
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[applyState, run, showToast]
|
||||
);
|
||||
|
||||
const logout = useCallback(
|
||||
() =>
|
||||
run(async () => {
|
||||
if (token) {
|
||||
await request("/api/auth/logout", { method: "POST" }, token);
|
||||
}
|
||||
localStorage.removeItem(TOKEN_KEY);
|
||||
setToken(null);
|
||||
setUser(null);
|
||||
setOrders([]);
|
||||
setCart({
|
||||
items: [],
|
||||
subtotal_cents: 0,
|
||||
discount_cents: 0,
|
||||
total_cents: 0,
|
||||
total_quantity: 0,
|
||||
discounts: [],
|
||||
});
|
||||
showToast({
|
||||
title: "Logged out",
|
||||
message: "Your session has ended.",
|
||||
});
|
||||
}),
|
||||
[run, showToast, token]
|
||||
);
|
||||
|
||||
const openCart = useCallback(() => {
|
||||
setPanelType("cart");
|
||||
setPanelOpen(true);
|
||||
}, []);
|
||||
|
||||
const openProfile = useCallback(() => {
|
||||
setPanelType("profile");
|
||||
setPanelOpen(true);
|
||||
}, []);
|
||||
|
||||
const closePanel = useCallback(() => setPanelOpen(false), []);
|
||||
const dismissToast = useCallback(() => setCartToast(null), []);
|
||||
|
||||
const addToCart = useCallback(
|
||||
(productId, quantity = 1, itemMessage) =>
|
||||
run(async () => {
|
||||
if (!token || !user) {
|
||||
setPanelType("profile");
|
||||
setPanelOpen(true);
|
||||
throw new Error("Please log in before adding products to the cart.");
|
||||
}
|
||||
const data = await request(
|
||||
"/api/cart/items",
|
||||
{ method: "POST", body: JSON.stringify({ productId, quantity }) },
|
||||
token
|
||||
);
|
||||
setCart(data.cart);
|
||||
showToast({
|
||||
title: "Added to cart",
|
||||
message: itemMessage || data.message,
|
||||
actionLabel: "To the cart",
|
||||
actionPanel: "cart",
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[run, showToast, token, user]
|
||||
);
|
||||
|
||||
const updateCartQuantity = useCallback(
|
||||
(productId, quantity) =>
|
||||
run(async () => {
|
||||
const data = await request(
|
||||
`/api/cart/items/${encodeURIComponent(productId)}`,
|
||||
{ method: "PATCH", body: JSON.stringify({ quantity }) },
|
||||
token
|
||||
);
|
||||
setCart(data.cart);
|
||||
return data;
|
||||
}),
|
||||
[run, token]
|
||||
);
|
||||
|
||||
const removeCartItem = useCallback(
|
||||
(productId) =>
|
||||
run(async () => {
|
||||
const data = await request(
|
||||
`/api/cart/items/${encodeURIComponent(productId)}`,
|
||||
{ method: "DELETE" },
|
||||
token
|
||||
);
|
||||
setCart(data.cart);
|
||||
return data;
|
||||
}),
|
||||
[run, token]
|
||||
);
|
||||
|
||||
const checkout = useCallback(
|
||||
(payload) =>
|
||||
run(async () => {
|
||||
const data = await request(
|
||||
"/api/cart/checkout",
|
||||
{ method: "POST", body: JSON.stringify(payload) },
|
||||
token
|
||||
);
|
||||
applyState(data);
|
||||
showToast({
|
||||
title: "Checkout complete",
|
||||
message: "Your order was placed and your purchase history was updated.",
|
||||
actionLabel: "Profile",
|
||||
actionPanel: "profile",
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[applyState, run, showToast, token]
|
||||
);
|
||||
|
||||
const updateProfile = useCallback(
|
||||
(payload) =>
|
||||
run(async () => {
|
||||
const data = await request(
|
||||
"/api/profile",
|
||||
{ method: "PATCH", body: JSON.stringify(payload) },
|
||||
token
|
||||
);
|
||||
setUser(data.user);
|
||||
showToast({
|
||||
title: "Profile saved",
|
||||
message: "Your profile details were updated.",
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[run, showToast, token]
|
||||
);
|
||||
|
||||
const updateNotifications = useCallback(
|
||||
(payload) =>
|
||||
run(async () => {
|
||||
const data = await request(
|
||||
"/api/notifications",
|
||||
{ method: "PATCH", body: JSON.stringify(payload) },
|
||||
token
|
||||
);
|
||||
setUser((current) =>
|
||||
current ? { ...current, notifications: data.notifications } : current
|
||||
);
|
||||
showToast({
|
||||
title: "Preferences saved",
|
||||
message: "Your drop and restock settings were updated.",
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[run, showToast, token]
|
||||
);
|
||||
|
||||
const subscribeToProduct = useCallback(
|
||||
(productId, type = "restock") =>
|
||||
run(async () => {
|
||||
if (!token || !user) {
|
||||
setPanelType("profile");
|
||||
setPanelOpen(true);
|
||||
throw new Error("Please log in to subscribe to restock updates.");
|
||||
}
|
||||
const data = await request(
|
||||
"/api/product-subscriptions",
|
||||
{ method: "POST", body: JSON.stringify({ product_id: productId, type }) },
|
||||
token
|
||||
);
|
||||
setUser((current) =>
|
||||
current ? { ...current, productSubscriptions: data.subscriptions } : current
|
||||
);
|
||||
showToast({
|
||||
title: "Subscription saved",
|
||||
message: "You will receive updates for this product.",
|
||||
actionLabel: "Profile",
|
||||
actionPanel: "profile",
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[run, showToast, token, user]
|
||||
);
|
||||
|
||||
const removeProductSubscription = useCallback(
|
||||
(subscriptionId) =>
|
||||
run(async () => {
|
||||
const data = await request(
|
||||
`/api/product-subscriptions/${encodeURIComponent(subscriptionId)}`,
|
||||
{ method: "DELETE" },
|
||||
token
|
||||
);
|
||||
setUser((current) =>
|
||||
current ? { ...current, productSubscriptions: data.subscriptions } : current
|
||||
);
|
||||
showToast({
|
||||
title: "Subscription removed",
|
||||
message: "That restock update was deleted.",
|
||||
});
|
||||
return data;
|
||||
}),
|
||||
[run, showToast, token]
|
||||
);
|
||||
|
||||
const refreshSession = useCallback(
|
||||
() =>
|
||||
token
|
||||
? request("/api/auth/session", {}, token).then((data) => {
|
||||
applyState(data);
|
||||
return data;
|
||||
})
|
||||
: Promise.resolve(null),
|
||||
[applyState, token]
|
||||
);
|
||||
|
||||
const value = useMemo(
|
||||
() => ({
|
||||
token,
|
||||
user,
|
||||
cart,
|
||||
orders,
|
||||
busy,
|
||||
error,
|
||||
panelOpen,
|
||||
panelType,
|
||||
cartToast,
|
||||
register,
|
||||
login,
|
||||
logout,
|
||||
updateProfile,
|
||||
updateNotifications,
|
||||
addToCart,
|
||||
updateCartQuantity,
|
||||
removeCartItem,
|
||||
checkout,
|
||||
subscribeToProduct,
|
||||
removeProductSubscription,
|
||||
refreshSession,
|
||||
openCart,
|
||||
openProfile,
|
||||
closePanel,
|
||||
dismissToast,
|
||||
showToast,
|
||||
setPanelType,
|
||||
setPanelOpen,
|
||||
setError,
|
||||
}),
|
||||
[
|
||||
token,
|
||||
user,
|
||||
cart,
|
||||
orders,
|
||||
busy,
|
||||
error,
|
||||
panelOpen,
|
||||
panelType,
|
||||
cartToast,
|
||||
register,
|
||||
login,
|
||||
logout,
|
||||
updateProfile,
|
||||
updateNotifications,
|
||||
addToCart,
|
||||
updateCartQuantity,
|
||||
removeCartItem,
|
||||
checkout,
|
||||
subscribeToProduct,
|
||||
removeProductSubscription,
|
||||
refreshSession,
|
||||
openCart,
|
||||
openProfile,
|
||||
closePanel,
|
||||
dismissToast,
|
||||
showToast,
|
||||
]
|
||||
);
|
||||
|
||||
return <ShopContext.Provider value={value}>{children}</ShopContext.Provider>;
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
import { createContext } from "react";
|
||||
|
||||
export const ShopContext = createContext(null);
|
||||
@@ -0,0 +1,5 @@
|
||||
export const formatChf = (cents = 0) =>
|
||||
new Intl.NumberFormat("de-CH", {
|
||||
style: "currency",
|
||||
currency: "CHF",
|
||||
}).format(cents / 100);
|
||||
@@ -0,0 +1,10 @@
|
||||
import { useContext } from "react";
|
||||
import { ShopContext } from "./ShopContextBase";
|
||||
|
||||
export const useShop = () => {
|
||||
const value = useContext(ShopContext);
|
||||
if (!value) {
|
||||
throw new Error("useShop must be used inside ShopProvider.");
|
||||
}
|
||||
return value;
|
||||
};
|
||||
@@ -17,6 +17,9 @@
|
||||
}
|
||||
|
||||
.nav-link {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
text-decoration: none;
|
||||
font-size: 13px;
|
||||
padding: 8px 14px;
|
||||
@@ -24,6 +27,12 @@
|
||||
transition: 0.2s ease;
|
||||
}
|
||||
|
||||
.nav-button {
|
||||
border: none;
|
||||
font-family: inherit;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* Hero variant */
|
||||
.navbar--hero {
|
||||
padding-top: 22px;
|
||||
@@ -37,6 +46,10 @@
|
||||
color: rgba(255, 255, 255, 0.88);
|
||||
}
|
||||
|
||||
.navbar--hero .nav-button {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.navbar--hero .nav-link:hover,
|
||||
.navbar--hero .nav-link.active {
|
||||
background: rgba(255, 255, 255, 0.22);
|
||||
@@ -56,6 +69,10 @@
|
||||
color: #1d1d1d;
|
||||
}
|
||||
|
||||
.navbar--light .nav-button {
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.navbar--light .nav-link:hover,
|
||||
.navbar--light .nav-link.active {
|
||||
background: #ebebeb;
|
||||
@@ -73,4 +90,4 @@
|
||||
padding: 8px 10px;
|
||||
font-size: 12px;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user