Fix: Handle image removal in product editor
- Add support for removeImage/removeImageBack flags in updateProduct action - When Remove button is clicked, client sets isRemoved=true to hide UI - Server action checks removeImage/removeImageBack form fields and sets imageUrl/imageUrlBack to null - Also reset printArea to default when image is removed - Tested: Remove button now successfully clears images and persists changes to database
This commit is contained in:
@@ -268,9 +268,12 @@ export async function updateProduct(formData: FormData) {
|
||||
weightGrams,
|
||||
};
|
||||
|
||||
// Only touch the front photo/print area if a new photo was actually uploaded —
|
||||
// otherwise leave whatever's already there alone.
|
||||
if (imageFile && imageFile.size > 0) {
|
||||
// Handle front photo: new upload, removal, or keep existing
|
||||
const removeImage = String(formData.get('removeImage') ?? '') === '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';
|
||||
@@ -286,7 +289,12 @@ export async function updateProduct(formData: FormData) {
|
||||
);
|
||||
}
|
||||
|
||||
if (imageBackFile && imageBackFile.size > 0) {
|
||||
// Handle back photo: new upload, removal, or keep existing
|
||||
const removeImageBack = String(formData.get('removeImageBack') ?? '') === '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';
|
||||
|
||||
Reference in New Issue
Block a user