Merge pull request 'Fix edit lint/typing issues and preload listing images' (#7) from feature/listing-edit into master
Some checks are pending
CI / checks (push) Waiting to run
Some checks are pending
CI / checks (push) Waiting to run
Reviewed-on: #7
This commit is contained in:
commit
b2afa1fae0
2 changed files with 18 additions and 5 deletions
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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<Locale, LocaleFields> = {
|
||||
en: { title: '', description: '', teaser: '' },
|
||||
fi: { title: '', description: '', teaser: '' },
|
||||
sv: { title: '', description: '', teaser: '' },
|
||||
};
|
||||
const slugMap: Record<Locale, string> = { 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');
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue