diff --git a/.claude/settings.local.json b/.claude/settings.local.json index a9b7449..064707f 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -105,7 +105,8 @@ "Bash(git commit -m 'Fix: Handle image removal in product editor *)", "Bash(git commit -m 'Refactor: Move image display into PhotoPrintAreaField component *)", "Bash(git commit -m 'Optimize: Skip color photo processing when not uploading new photos *)", - "Bash(git commit -m 'Optimize: Fetch only necessary fields from database *)" + "Bash(git commit -m 'Optimize: Fetch only necessary fields from database *)", + "Bash(git commit -m 'Fix: Always update print area coordinates when editing product *)" ] } } diff --git a/src/app/admin/products/actions.ts b/src/app/admin/products/actions.ts index 9fc401a..e0f9139 100644 --- a/src/app/admin/products/actions.ts +++ b/src/app/admin/products/actions.ts @@ -291,13 +291,13 @@ export async function updateProduct(formData: FormData) { // Handle front photo: new upload, removal, or keep existing const removeImage = String(formData.get('removeImage') ?? '') === '1'; + const hasCustomPrintArea = String(formData.get('hasCustomPrintArea') ?? '') === '1'; + if (removeImage) { data.imageUrl = null; data.printArea = JSON.stringify(DEFAULT_PRINT_AREAS[mockup] ?? DEFAULT_PRINT_AREAS.tshirt); } else if (imageFile && imageFile.size > 0) { data.imageUrl = await fileToDataUrl(imageFile); - - const hasCustomPrintArea = String(formData.get('hasCustomPrintArea') ?? '') === '1'; data.printArea = JSON.stringify( hasCustomPrintArea ? { @@ -308,17 +308,37 @@ export async function updateProduct(formData: FormData) { } : DEFAULT_PRINT_AREAS[mockup] ?? DEFAULT_PRINT_AREAS.tshirt, ); + } else if (existing.imageUrl) { + // No new image uploaded, but existing image present — still update print area if custom + if (hasCustomPrintArea) { + data.printArea = JSON.stringify({ + xPct: Number(formData.get('printX') ?? 0.3), + yPct: Number(formData.get('printY') ?? 0.25), + wPct: Number(formData.get('printW') ?? 0.4), + hPct: Number(formData.get('printH') ?? 0.35), + }); + } } // Handle back photo: new upload, removal, or keep existing const removeImageBack = String(formData.get('removeImageBack') ?? '') === '1'; + const hasCustomPrintAreaBack = String(formData.get('hasCustomPrintAreaBack') ?? '') === '1'; + if (removeImageBack) { data.imageUrlBack = null; data.printAreaBack = null; } else if (imageBackFile && imageBackFile.size > 0) { data.imageUrlBack = await fileToDataUrl(imageBackFile); - - const hasCustomPrintAreaBack = String(formData.get('hasCustomPrintAreaBack') ?? '') === '1'; + if (hasCustomPrintAreaBack) { + data.printAreaBack = JSON.stringify({ + xPct: Number(formData.get('printXBack') ?? 0.3), + yPct: Number(formData.get('printYBack') ?? 0.25), + wPct: Number(formData.get('printWBack') ?? 0.4), + hPct: Number(formData.get('printHBack') ?? 0.35), + }); + } + } else if (existing.imageUrlBack) { + // No new image uploaded, but existing image present — still update print area if custom if (hasCustomPrintAreaBack) { data.printAreaBack = JSON.stringify({ xPct: Number(formData.get('printXBack') ?? 0.3),