feat: toast feedback, skip-to-content, deposit success notification

- toast.success/error on order creation (bestall/page.tsx)
- toast.success/error on order approval (validera/page.tsx) + fix silent
  success even when API failed (was always setting approved=true)
- toast.success/error on subscription creation (portal/subscriptions)
- toast.success/error on admin status advance (admin/page.tsx)
- toast.success on production page when Stripe redirects back with ?deposit=success
- layout.tsx: skip-to-main-content link (sr-only, visible on focus)
- app/page.tsx: id="main-content" anchor for skip link

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-25 17:41:59 +02:00
co-authored by Claude Sonnet 4.6
parent df63d3a6dd
commit b95507e601
7 changed files with 60 additions and 12 deletions
+12 -2
View File
@@ -1,6 +1,7 @@
"use client";
import { useCallback, useEffect, useState } from "react";
import { toast } from "sonner";
import { useT } from "@/components/locale-provider";
import { PortalShell, StatusPill } from "@/components/portal-shell";
import { LoadingSkeleton, ErrorState, EmptyState } from "@/components/states";
@@ -56,8 +57,17 @@ export default function AdminPage() {
async function advance(id: string, status: string) {
const next = NEXT_STATUS[status];
if (!next) return;
await fetch(`/api/orders/${id}`, { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ status: next }) });
void load();
try {
const r = await fetch(`/api/orders/${id}`, { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ status: next }) });
if (r.ok) {
toast.success(`${id.slice(0, 8)}… → ${next}`);
void load();
} else {
toast.error(t({ en: "Could not advance order.", sv: "Kunde inte flytta fram ordern." }));
}
} catch {
toast.error(t({ en: "Network error.", sv: "Nätverksfel." }));
}
}
return (
+8 -1
View File
@@ -2,6 +2,7 @@
import { useRouter } from "next/navigation";
import { useMemo, useState, useEffect } from "react";
import { toast } from "sonner";
import { OrderStepper } from "@/components/order-stepper";
import { ProvenanceBadge } from "@/components/provenance-badge";
import { useT } from "@/components/locale-provider";
@@ -64,7 +65,13 @@ export default function ConfiguratorPage() {
setCreating(true);
const config = { markets, type, fieldIds, enrichmentIds, volume, frequency, confidence, formats, service_type: service };
const id = await createOrder(frequency === "Engångs" ? "custom" : "subscription", config);
router.push(id ? `/bestall/forskott?order=${encodeURIComponent(id)}` : "/bestall/forskott");
if (id) {
toast.success(t({ en: "Order created. Proceeding to deposit.", sv: "Order skapad. Fortsätter till förskott." }));
router.push(`/bestall/forskott?order=${encodeURIComponent(id)}`);
} else {
toast.error(t({ en: "Could not create order. Please try again.", sv: "Kunde inte skapa order. Försök igen." }));
setCreating(false);
}
}
const toggle = (arr: string[], v: string, set: (x: string[]) => void) =>
+6
View File
@@ -20,6 +20,12 @@ export default function RootLayout({ children }: Readonly<{ children: React.Reac
return (
<html lang="en">
<body className={`${inter.variable} ${jetbrainsMono.variable} font-sans antialiased`}>
<a
href="#main-content"
className="sr-only focus:not-sr-only focus:fixed focus:left-4 focus:top-4 focus:z-[100] focus:bg-foreground focus:px-4 focus:py-2 focus:font-mono focus:text-[11px] focus:uppercase focus:tracking-[0.12em] focus:text-background"
>
Skip to content
</a>
<LocaleProvider>{children}</LocaleProvider>
<Toaster position="bottom-right" toastOptions={{ classNames: { toast: "font-mono text-xs tracking-[0.06em] rounded-none border border-border bg-background text-foreground", title: "font-mono", description: "font-mono text-muted-foreground" } }} />
<Analytics />
+11 -1
View File
@@ -1,8 +1,9 @@
"use client";
import Link from "next/link";
import { useParams } from "next/navigation";
import { useParams, useSearchParams } from "next/navigation";
import { useEffect, useRef, useState } from "react";
import { toast } from "sonner";
import { OrderStepper } from "@/components/order-stepper";
import { useT } from "@/components/locale-provider";
import { useReveal } from "@/hooks/use-reveal";
@@ -29,6 +30,7 @@ function prefersReduced() {
export default function ProductionPage() {
const t = useT();
const { id } = useParams<{ id: string }>();
const searchParams = useSearchParams();
const reveal = useReveal<HTMLDivElement>();
const [running, setRunning] = useState(false);
const [done, setDone] = useState(false);
@@ -39,6 +41,14 @@ export default function ProductionPage() {
const timer = useRef<ReturnType<typeof setInterval> | null>(null);
const tick = useRef(0);
const [order, setOrder] = useState<{ markets: string[]; volume: number } | null>(null);
useEffect(() => {
if (searchParams.get("deposit") === "success") {
toast.success(t({ en: "Deposit received. Production has started.", sv: "Förskott mottaget. Produktionen har startat." }));
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);
useEffect(() => {
const fromLocal = () => {
const c = getLocalOrder(id)?.config as { markets?: string[]; volume?: number } | undefined;
+8 -3
View File
@@ -2,6 +2,7 @@
import { useParams } from "next/navigation";
import { useState } from "react";
import { toast } from "sonner";
import { OrderStepper } from "@/components/order-stepper";
import { useT } from "@/components/locale-provider";
import { useReveal } from "@/hooks/use-reveal";
@@ -78,13 +79,17 @@ export default function ValidationPage() {
async function approve() {
try {
await fetch(`/api/orders/${id}`, {
const r = await fetch(`/api/orders/${id}`, {
method: "PATCH",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ status: "accepted" }),
});
} catch {}
setApproved(true);
if (!r.ok) throw new Error("api");
setApproved(true);
toast.success(t({ en: "Order approved. Escrow released.", sv: "Order godkänd. Escrow frigiven." }));
} catch {
toast.error(t({ en: "Could not approve. Try again.", sv: "Kunde inte godkänna. Försök igen." }));
}
}
return (
+1 -1
View File
@@ -12,7 +12,7 @@ import { FooterSection } from "@/components/sections/footer-section";
export default function Home() {
return (
<main className="min-h-screen bg-background">
<main id="main-content" className="min-h-screen bg-background">
<Header />
<HeroSection />
<PhilosophySection />
+14 -4
View File
@@ -1,6 +1,7 @@
"use client";
import { useCallback, useEffect, useState } from "react";
import { toast } from "sonner";
import { useT } from "@/components/locale-provider";
import { PortalShell, StatusPill } from "@/components/portal-shell";
import { LoadingSkeleton, EmptyState, ErrorState } from "@/components/states";
@@ -29,12 +30,21 @@ export default function SubscriptionsPage() {
useEffect(() => { void load(); }, [load]);
async function create() {
if (!orderId || busy) return;
if (!orderId.trim() || busy) return;
setBusy(true);
await fetch("/api/subscriptions", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ order_id: orderId, cadence }) }).catch(() => {});
setOrderId("");
try {
const r = await fetch("/api/subscriptions", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ order_id: orderId.trim(), cadence }) });
if (r.ok) {
toast.success(t({ en: "Flow created.", sv: "Flöde skapat." }));
setOrderId("");
void load();
} else {
toast.error(t({ en: "Could not create flow. Check the order ID.", sv: "Kunde inte skapa flöde. Kontrollera order-ID." }));
}
} catch {
toast.error(t({ en: "Network error. Try again.", sv: "Nätverksfel. Försök igen." }));
}
setBusy(false);
void load();
}
return (