From 24bce444791366b8ee320e1ea176f93f5f079478 Mon Sep 17 00:00:00 2001 From: joseyvanaarsen Date: Mon, 9 Mar 2026 00:58:42 +0100 Subject: [PATCH] Added frontend for complete listing feature. You can add, (un)publish, predict, remove and edit listings --- frontend/valora-web/app/browse/[id]/page.tsx | 112 ++-- frontend/valora-web/app/dashboard/layout.tsx | 16 + .../app/dashboard/listings/[id]/edit/page.tsx | 15 + .../app/dashboard/listings/new/page.tsx | 5 + .../app/dashboard/listings/page.tsx | 5 + frontend/valora-web/app/dashboard/page.tsx | 7 +- frontend/valora-web/app/globals.css | 2 +- .../dashboard/create-listing-form.tsx | 301 +++++++++ .../components/dashboard/dashboard-header.tsx | 46 ++ .../components/dashboard/dashboard-home.tsx | 77 +-- .../components/dashboard/dashboard-shell.tsx | 18 + .../dashboard/dashboard-sidebar.tsx | 53 ++ .../dashboard/edit-listing-form.tsx | 575 ++++++++++++++++++ .../listing-image-uploader-shell.tsx | 66 ++ .../dashboard/my-listings-section.tsx | 282 +++++++++ .../components/listings/listing-card.tsx | 3 +- .../listings/listing-image-gallery.tsx | 73 +++ .../listings/listing-image-placeholder.tsx | 33 + .../components/listings/listing-image.tsx | 43 ++ .../listings/listing-status-badge.tsx | 39 ++ .../lib/listings/category-feature-config.ts | 102 ++++ .../lib/listings/feature-parser.tsx | 23 + .../valora-web/lib/listings/listing-images.ts | 25 + frontend/valora-web/types/listings.ts | 17 + 24 files changed, 1841 insertions(+), 97 deletions(-) create mode 100644 frontend/valora-web/app/dashboard/layout.tsx create mode 100644 frontend/valora-web/app/dashboard/listings/[id]/edit/page.tsx create mode 100644 frontend/valora-web/app/dashboard/listings/new/page.tsx create mode 100644 frontend/valora-web/app/dashboard/listings/page.tsx create mode 100644 frontend/valora-web/components/dashboard/create-listing-form.tsx create mode 100644 frontend/valora-web/components/dashboard/dashboard-header.tsx create mode 100644 frontend/valora-web/components/dashboard/dashboard-shell.tsx create mode 100644 frontend/valora-web/components/dashboard/dashboard-sidebar.tsx create mode 100644 frontend/valora-web/components/dashboard/edit-listing-form.tsx create mode 100644 frontend/valora-web/components/dashboard/listing-image-uploader-shell.tsx create mode 100644 frontend/valora-web/components/dashboard/my-listings-section.tsx create mode 100644 frontend/valora-web/components/listings/listing-image-gallery.tsx create mode 100644 frontend/valora-web/components/listings/listing-image-placeholder.tsx create mode 100644 frontend/valora-web/components/listings/listing-image.tsx create mode 100644 frontend/valora-web/components/listings/listing-status-badge.tsx create mode 100644 frontend/valora-web/lib/listings/category-feature-config.ts create mode 100644 frontend/valora-web/lib/listings/listing-images.ts diff --git a/frontend/valora-web/app/browse/[id]/page.tsx b/frontend/valora-web/app/browse/[id]/page.tsx index 3d1f64f..f96a75c 100644 --- a/frontend/valora-web/app/browse/[id]/page.tsx +++ b/frontend/valora-web/app/browse/[id]/page.tsx @@ -5,6 +5,7 @@ import { use } from "react"; import { useQuery } from "@tanstack/react-query"; import { ArrowLeft, CalendarDays, Sparkles, Tag } from "lucide-react"; import { FeatureBadges } from "@/components/listings/feature-badges"; +import { ListingImageGallery } from "@/components/listings/listing-image-gallery"; import { Footer } from "@/components/layout/footer"; import { Navbar } from "@/components/layout/navbar"; import { parseFeaturesJson } from "@/lib/listings/feature-parser"; @@ -81,68 +82,70 @@ export default function ListingDetailPage({ {query.data ? (
-
-
- -
-
-
-

- {formatCategory(query.data.categoryKey)} -

-

- {query.data.title} -

-
+
+ + +
+
+
+
+

+ {formatCategory(query.data.categoryKey)} +

+

+ {query.data.title} +

+
- - {query.data.status} - -
+ + {query.data.status} + +
-

- {query.data.description} -

+

+ {query.data.description} +

-
- -
+
+ +
-
-
-
- -

- Vraagprijs +

+
+
+ +

+ Vraagprijs +

+
+

+ {formatCurrency(query.data.askingPrice)}

-

- {formatCurrency(query.data.askingPrice)} -

-
-
-
- -

- Voorspelde prijs +

+
+ +

+ Voorspelde prijs +

+
+

+ {formatCurrency(query.data.predictedPrice)}

-

- {formatCurrency(query.data.predictedPrice)} -

-
-
-
- -

- Geplaatst op{" "} - {new Intl.DateTimeFormat("nl-NL", { - dateStyle: "full", - }).format(new Date(query.data.createdAtUtc))} -

+
+
+ +

+ Geplaatst op{" "} + {new Intl.DateTimeFormat("nl-NL", { + dateStyle: "full", + }).format(new Date(query.data.createdAtUtc))} +

+
@@ -182,12 +185,11 @@ export default function ListingDetailPage({

- Marketplace indruk + Afbeelding-architectuur klaar

- Deze detailpagina is nu al geschikt als basis voor je echte - marketplace flow. Straks kunnen we hier seller-info, related - listings, save actions en AI-insights aan toevoegen. + Deze detailpagina ondersteunt nu al een primary image en thumbnail + gallery zodra je backend listing images teruggeeft.

diff --git a/frontend/valora-web/app/dashboard/layout.tsx b/frontend/valora-web/app/dashboard/layout.tsx new file mode 100644 index 0000000..5fb7b82 --- /dev/null +++ b/frontend/valora-web/app/dashboard/layout.tsx @@ -0,0 +1,16 @@ +import { AuthGuard } from "@/components/auth/auth-guard"; +import { DashboardShell } from "@/components/dashboard/dashboard-shell"; + +interface DashboardLayoutProps { + children: React.ReactNode; +} + +export default function DashboardLayout({ + children, +}: DashboardLayoutProps): React.JSX.Element { + return ( + + {children} + + ); +} \ No newline at end of file diff --git a/frontend/valora-web/app/dashboard/listings/[id]/edit/page.tsx b/frontend/valora-web/app/dashboard/listings/[id]/edit/page.tsx new file mode 100644 index 0000000..2f7608c --- /dev/null +++ b/frontend/valora-web/app/dashboard/listings/[id]/edit/page.tsx @@ -0,0 +1,15 @@ +import { EditListingForm } from "@/components/dashboard/edit-listing-form"; + +interface DashboardEditListingPageProps { + params: Promise<{ + id: string; + }>; +} + +export default async function DashboardEditListingPage({ + params, +}: DashboardEditListingPageProps): Promise { + const { id } = await params; + + return ; +} \ No newline at end of file diff --git a/frontend/valora-web/app/dashboard/listings/new/page.tsx b/frontend/valora-web/app/dashboard/listings/new/page.tsx new file mode 100644 index 0000000..1256637 --- /dev/null +++ b/frontend/valora-web/app/dashboard/listings/new/page.tsx @@ -0,0 +1,5 @@ +import { CreateListingForm } from "@/components/dashboard/create-listing-form"; + +export default function DashboardNewListingPage(): React.JSX.Element { + return ; +} \ No newline at end of file diff --git a/frontend/valora-web/app/dashboard/listings/page.tsx b/frontend/valora-web/app/dashboard/listings/page.tsx new file mode 100644 index 0000000..21426d5 --- /dev/null +++ b/frontend/valora-web/app/dashboard/listings/page.tsx @@ -0,0 +1,5 @@ +import { MyListingsSection } from "@/components/dashboard/my-listings-section"; + +export default function DashboardListingsPage(): React.JSX.Element { + return ; +} \ No newline at end of file diff --git a/frontend/valora-web/app/dashboard/page.tsx b/frontend/valora-web/app/dashboard/page.tsx index 7f73f78..64beb16 100644 --- a/frontend/valora-web/app/dashboard/page.tsx +++ b/frontend/valora-web/app/dashboard/page.tsx @@ -1,10 +1,5 @@ -import { AuthGuard } from "@/components/auth/auth-guard"; import { DashboardHome } from "@/components/dashboard/dashboard-home"; export default function DashboardPage(): React.JSX.Element { - return ( - - - - ); + return ; } \ No newline at end of file diff --git a/frontend/valora-web/app/globals.css b/frontend/valora-web/app/globals.css index 71ce874..e77671b 100644 --- a/frontend/valora-web/app/globals.css +++ b/frontend/valora-web/app/globals.css @@ -6,7 +6,7 @@ radial-gradient(circle at 85% 10%, rgba(187, 247, 208, 0.85), transparent 18%), radial-gradient(circle at 40% 100%, rgba(209, 250, 229, 0.8), transparent 28%), linear-gradient(180deg, #f7fff9 0%, #f0fdf4 45%, #ecfeff 100%); - --foreground: #052e16; + --foreground: #052e06; } * { diff --git a/frontend/valora-web/components/dashboard/create-listing-form.tsx b/frontend/valora-web/components/dashboard/create-listing-form.tsx new file mode 100644 index 0000000..b274e0a --- /dev/null +++ b/frontend/valora-web/components/dashboard/create-listing-form.tsx @@ -0,0 +1,301 @@ +"use client"; + +import { useMemo, useState } from "react"; +import { useRouter } from "next/navigation"; +import { useMutation, useQueryClient } from "@tanstack/react-query"; +import { LoaderCircle, Save } from "lucide-react"; +import { DashboardHeader } from "@/components/dashboard/dashboard-header"; +import { listingsApi } from "@/lib/api/listings-api"; +import { getAccessToken } from "@/lib/auth/token-storage"; +import { + getCategoryConfig, + listingCategoryConfigs, + type ListingFeatureField, +} from "@/lib/listings/category-feature-config"; +import type { CreateListingRequest } from "@/types/listings"; + +type FeatureFormValue = string | boolean; + +function toFeatureJsonValue(field: ListingFeatureField, value: FeatureFormValue): unknown { + if (field.type === "checkbox") { + return Boolean(value); + } + + if (field.type === "number") { + if (value === "") { + return null; + } + + const parsed = Number(value); + return Number.isNaN(parsed) ? null : parsed; + } + + return String(value).trim(); +} + +export function CreateListingForm(): React.JSX.Element { + const router = useRouter(); + const queryClient = useQueryClient(); + const token = getAccessToken(); + + const [title, setTitle] = useState(""); + const [description, setDescription] = useState(""); + const [categoryKey, setCategoryKey] = useState(listingCategoryConfigs[0]?.key ?? "laptops"); + const [askingPrice, setAskingPrice] = useState(""); + const [featureValues, setFeatureValues] = useState>({}); + const [serverError, setServerError] = useState(null); + + const categoryConfig = useMemo(() => getCategoryConfig(categoryKey), [categoryKey]); + + const createMutation = useMutation({ + mutationFn: (request: CreateListingRequest) => + listingsApi.create(request, token as string), + onSuccess: async () => { + await queryClient.invalidateQueries({ queryKey: ["my-listings"] }); + router.push("/dashboard/listings"); + }, + onError: () => { + setServerError( + "De listing kon niet worden aangemaakt. Controleer je invoer en probeer opnieuw.", + ); + }, + }); + + function updateFeatureValue(key: string, value: FeatureFormValue): void { + setFeatureValues((current) => ({ + ...current, + [key]: value, + })); + } + + function buildFeaturesJson(): string { + const fields = categoryConfig?.fields ?? []; + + const features = Object.fromEntries( + fields + .map((field) => { + const rawValue = featureValues[field.key]; + + if (field.type === "checkbox") { + return [field.key, Boolean(rawValue)]; + } + + if (rawValue === undefined || rawValue === null || rawValue === "") { + return [field.key, null]; + } + + return [field.key, toFeatureJsonValue(field, rawValue)]; + }) + .filter(([, value]) => value !== null), + ); + + return JSON.stringify(features); + } + + function handleSubmit(event: React.FormEvent): void { + event.preventDefault(); + setServerError(null); + + if (!token) { + setServerError("Je bent niet ingelogd."); + return; + } + + if (!title.trim() || !description.trim() || !askingPrice.trim()) { + setServerError("Vul titel, beschrijving en vraagprijs in."); + return; + } + + const price = Number(askingPrice); + + if (Number.isNaN(price) || price <= 0) { + setServerError("Vul een geldige vraagprijs in."); + return; + } + + createMutation.mutate({ + title: title.trim(), + description: description.trim(), + categoryKey, + askingPrice: price, + featuresJson: buildFeaturesJson(), + }); + } + + return ( +
+ + +
+
+
+ + setTitle(event.target.value)} + className="w-full rounded-[1.2rem] border border-emerald-200 bg-white px-4 py-3 text-sm text-emerald-950 shadow-sm outline-none transition focus:border-emerald-400" + placeholder="Bijv. Lenovo Legion 5" + /> +
+ +
+ + +

+ {categoryConfig?.description} +

+
+ +
+ +