From 6a6c6ba4ccb4c0b6750a78c623e0df3a6a215e64 Mon Sep 17 00:00:00 2001 From: Tero Halla-aho Date: Mon, 15 Dec 2025 23:30:17 +0200 Subject: [PATCH] Fix edit lint/typing issues and preload listing images --- app/api/listings/[id]/route.ts | 6 +++--- app/listings/edit/[id]/page.tsx | 17 +++++++++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/app/api/listings/[id]/route.ts b/app/api/listings/[id]/route.ts index 5981401..45554b5 100644 --- a/app/api/listings/[id]/route.ts +++ b/app/api/listings/[id]/route.ts @@ -1,4 +1,4 @@ -import { ListingStatus, UserRole, UserStatus } from '@prisma/client'; +import { ListingStatus, Role, UserStatus } from '@prisma/client'; import { NextResponse } from 'next/server'; import { prisma } from '../../../../lib/prisma'; import { requireAuth } from '../../../../lib/jwt'; @@ -117,7 +117,7 @@ export async function PUT(req: Request, { params }: { params: { id: string } }) } let status = existing.status; - const autoApprove = !saveDraft && (process.env.AUTO_APPROVE_LISTINGS === 'true' || auth.role === UserRole.ADMIN); + const autoApprove = !saveDraft && (process.env.AUTO_APPROVE_LISTINGS === 'true' || auth.role === Role.ADMIN); if (saveDraft) { status = ListingStatus.DRAFT; } else if (existing.status === ListingStatus.PUBLISHED) { @@ -186,7 +186,7 @@ export async function PUT(req: Request, { params }: { params: { id: string } }) const updateData: any = { status, approvedAt: status === ListingStatus.PUBLISHED ? existing.approvedAt ?? new Date() : null, - approvedById: status === ListingStatus.PUBLISHED && auth.role === UserRole.ADMIN ? auth.userId : existing.approvedById, + approvedById: status === ListingStatus.PUBLISHED && auth.role === Role.ADMIN ? auth.userId : existing.approvedById, country: country || null, region: region || null, city: city || null, diff --git a/app/listings/edit/[id]/page.tsx b/app/listings/edit/[id]/page.tsx index 3473c83..5646703 100644 --- a/app/listings/edit/[id]/page.tsx +++ b/app/listings/edit/[id]/page.tsx @@ -88,8 +88,12 @@ export default function EditListingPage({ params }: { params: { id: string } }) } const listing = data.listing; setInitialStatus(listing.status as ListingStatus); - const translationMap = { ...translations }; - const slugMap = { ...suggestedSlugs }; + const translationMap: Record = { + en: { title: '', description: '', teaser: '' }, + fi: { title: '', description: '', teaser: '' }, + sv: { title: '', description: '', teaser: '' }, + }; + const slugMap: Record = { en: '', fi: '', sv: '' }; SUPPORTED_LOCALES.forEach((loc) => { const found = listing.translations.find((t: any) => t.locale === loc); if (found) { @@ -138,6 +142,15 @@ export default function EditListingPage({ params }: { params: { id: string } }) if (listing.images?.length) { const coverIdx = listing.images.find((img: any) => img.isCover)?.order ?? 1; setCoverImageIndex(coverIdx); + setSelectedImages( + listing.images.map((img: any) => ({ + name: img.altText || img.url || `image-${img.id}`, + size: img.size || 0, + mimeType: img.mimeType || 'image/jpeg', + dataUrl: img.url || `/api/images/${img.id}`, + isExisting: true, + })), + ); } } catch (err: any) { setError(err.message || 'Failed to load listing');