mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-21 11:51:14 -05:00
Fix photo_delete display issues
This commit is contained in:
@@ -104,6 +104,27 @@ export function PhotoManagementDialog({
|
|||||||
const { data: { user } } = await supabase.auth.getUser();
|
const { data: { user } } = await supabase.auth.getUser();
|
||||||
if (!user) throw new Error('Not authenticated');
|
if (!user) throw new Error('Not authenticated');
|
||||||
|
|
||||||
|
// Fetch entity name from database based on entity type
|
||||||
|
let entityName = 'Unknown';
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (entityType === 'park') {
|
||||||
|
const { data } = await supabase.from('parks').select('name').eq('id', entityId).single();
|
||||||
|
if (data?.name) entityName = data.name;
|
||||||
|
} else if (entityType === 'ride') {
|
||||||
|
const { data } = await supabase.from('rides').select('name').eq('id', entityId).single();
|
||||||
|
if (data?.name) entityName = data.name;
|
||||||
|
} else if (entityType === 'ride_model') {
|
||||||
|
const { data } = await supabase.from('ride_models').select('name').eq('id', entityId).single();
|
||||||
|
if (data?.name) entityName = data.name;
|
||||||
|
} else if (['manufacturer', 'operator', 'designer', 'property_owner'].includes(entityType)) {
|
||||||
|
const { data } = await supabase.from('companies').select('name').eq('id', entityId).single();
|
||||||
|
if (data?.name) entityName = data.name;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error fetching entity name:', err);
|
||||||
|
}
|
||||||
|
|
||||||
// Create content submission
|
// Create content submission
|
||||||
const { data: submission, error: submissionError } = await supabase
|
const { data: submission, error: submissionError } = await supabase
|
||||||
.from('content_submissions')
|
.from('content_submissions')
|
||||||
@@ -120,7 +141,7 @@ export function PhotoManagementDialog({
|
|||||||
|
|
||||||
if (submissionError) throw submissionError;
|
if (submissionError) throw submissionError;
|
||||||
|
|
||||||
// Create submission item
|
// Create submission item with all necessary data
|
||||||
const { error: itemError } = await supabase
|
const { error: itemError } = await supabase
|
||||||
.from('submission_items')
|
.from('submission_items')
|
||||||
.insert({
|
.insert({
|
||||||
@@ -130,9 +151,11 @@ export function PhotoManagementDialog({
|
|||||||
photo_id: photoToDelete.id,
|
photo_id: photoToDelete.id,
|
||||||
entity_type: entityType,
|
entity_type: entityType,
|
||||||
entity_id: entityId,
|
entity_id: entityId,
|
||||||
|
entity_name: entityName,
|
||||||
cloudflare_image_url: photoToDelete.cloudflare_image_url,
|
cloudflare_image_url: photoToDelete.cloudflare_image_url,
|
||||||
|
title: photoToDelete.title,
|
||||||
caption: photoToDelete.caption,
|
caption: photoToDelete.caption,
|
||||||
reason: deleteReason
|
deletion_reason: deleteReason
|
||||||
},
|
},
|
||||||
status: 'pending'
|
status: 'pending'
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -97,12 +97,12 @@ async function detectPhotoChanges(submissionId: string): Promise<PhotoChange[]>
|
|||||||
changes.push({
|
changes.push({
|
||||||
type: 'deleted',
|
type: 'deleted',
|
||||||
photo: {
|
photo: {
|
||||||
url: itemData.photo_url || itemData.cloudflare_image_url || '',
|
url: itemData.cloudflare_image_url || itemData.photo_url || '',
|
||||||
title: itemData.title,
|
title: itemData.title,
|
||||||
caption: itemData.caption,
|
caption: itemData.caption,
|
||||||
entity_type: itemData.entity_type,
|
entity_type: itemData.entity_type,
|
||||||
entity_name: itemData.entity_name,
|
entity_name: itemData.entity_name,
|
||||||
deletion_reason: itemData.deletion_reason
|
deletion_reason: itemData.deletion_reason || itemData.reason
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else if (item.item_type === 'photo_edit' && itemData && originalData) {
|
} else if (item.item_type === 'photo_edit' && itemData && originalData) {
|
||||||
@@ -256,8 +256,39 @@ export async function detectChanges(
|
|||||||
detectImageChanges(originalData, itemData, imageChanges);
|
detectImageChanges(originalData, itemData, imageChanges);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get entity name
|
// Get entity name - handle different item types
|
||||||
const entityName = itemData.name || originalData?.name || 'Unknown';
|
let entityName = 'Unknown';
|
||||||
|
if (item.item_type === 'photo_delete' || item.item_type === 'photo_edit' || item.item_type === 'photo') {
|
||||||
|
// For photo operations, prioritize entity_name from item_data
|
||||||
|
entityName = itemData.entity_name || itemData.caption || itemData.title || 'Photo';
|
||||||
|
|
||||||
|
// If we have entity_type and entity_id but no entity_name, fetch it from DB
|
||||||
|
if (!itemData.entity_name && itemData.entity_type && itemData.entity_id) {
|
||||||
|
try {
|
||||||
|
const entityType = itemData.entity_type;
|
||||||
|
const entityId = itemData.entity_id;
|
||||||
|
|
||||||
|
if (entityType === 'park') {
|
||||||
|
const { data } = await supabase.from('parks').select('name').eq('id', entityId).single();
|
||||||
|
if (data?.name) entityName = `${data.name} (${formatEntityType(entityType)})`;
|
||||||
|
} else if (entityType === 'ride') {
|
||||||
|
const { data } = await supabase.from('rides').select('name').eq('id', entityId).single();
|
||||||
|
if (data?.name) entityName = `${data.name} (${formatEntityType(entityType)})`;
|
||||||
|
} else if (entityType === 'ride_model') {
|
||||||
|
const { data } = await supabase.from('ride_models').select('name').eq('id', entityId).single();
|
||||||
|
if (data?.name) entityName = `${data.name} (${formatEntityType(entityType)})`;
|
||||||
|
} else if (['manufacturer', 'operator', 'designer', 'property_owner'].includes(entityType)) {
|
||||||
|
const { data } = await supabase.from('companies').select('name').eq('id', entityId).single();
|
||||||
|
if (data?.name) entityName = `${data.name} (${formatEntityType(entityType)})`;
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
console.error('Error fetching entity name:', err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// For regular entities, use name field
|
||||||
|
entityName = itemData.name || originalData?.name || 'Unknown';
|
||||||
|
}
|
||||||
|
|
||||||
// Detect photo changes if submissionId provided
|
// Detect photo changes if submissionId provided
|
||||||
const photoChanges = submissionId ? await detectPhotoChanges(submissionId) : [];
|
const photoChanges = submissionId ? await detectPhotoChanges(submissionId) : [];
|
||||||
@@ -413,6 +444,32 @@ export function formatFieldName(field: string): string {
|
|||||||
.trim();
|
.trim();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get table name for entity type
|
||||||
|
*/
|
||||||
|
function getTableNameForEntityType(entityType: string): string | null {
|
||||||
|
const mapping: Record<string, string> = {
|
||||||
|
'park': 'parks',
|
||||||
|
'ride': 'rides',
|
||||||
|
'manufacturer': 'companies',
|
||||||
|
'operator': 'companies',
|
||||||
|
'designer': 'companies',
|
||||||
|
'property_owner': 'companies',
|
||||||
|
'ride_model': 'ride_models'
|
||||||
|
};
|
||||||
|
return mapping[entityType] || null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format entity type for display
|
||||||
|
*/
|
||||||
|
function formatEntityType(entityType: string): string {
|
||||||
|
return entityType
|
||||||
|
.split('_')
|
||||||
|
.map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase())
|
||||||
|
.join(' ');
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Format field value for display
|
* Format field value for display
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user