feat: Implement comprehensive plan

This commit is contained in:
gpt-engineer-app[bot]
2025-09-29 20:31:28 +00:00
parent 07b036bb7d
commit f586b31954
6 changed files with 990 additions and 19 deletions

View File

@@ -355,6 +355,117 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
setActionLoading(item.id);
try {
// Handle composite ride submissions with sequential entity creation
if (action === 'approved' && item.type === 'content_submission' &&
(item.submission_type === 'ride_with_manufacturer' ||
item.submission_type === 'ride_with_model' ||
item.submission_type === 'ride_with_manufacturer_and_model')) {
let manufacturerId = item.content.ride?.manufacturer_id;
let rideModelId = item.content.ride?.ride_model_id;
// STEP 1: Create manufacturer if needed
if (item.content.new_manufacturer) {
const { data: newManufacturer, error: mfrError } = await supabase
.from('companies')
.insert({
name: item.content.new_manufacturer.name,
slug: item.content.new_manufacturer.slug,
description: item.content.new_manufacturer.description,
company_type: 'manufacturer',
person_type: item.content.new_manufacturer.person_type || 'company',
website_url: item.content.new_manufacturer.website_url,
founded_year: item.content.new_manufacturer.founded_year,
headquarters_location: item.content.new_manufacturer.headquarters_location
})
.select()
.single();
if (mfrError) {
throw new Error(`Failed to create manufacturer: ${mfrError.message}`);
}
manufacturerId = newManufacturer.id;
toast({
title: "Manufacturer Created",
description: `Created ${newManufacturer.name}`,
});
}
// STEP 2: Create ride model if needed
if (item.content.new_ride_model) {
const modelManufacturerId = manufacturerId || item.content.new_ride_model.manufacturer_id;
if (!modelManufacturerId) {
throw new Error('Cannot create ride model: No manufacturer ID available');
}
const { data: newModel, error: modelError } = await supabase
.from('ride_models')
.insert({
name: item.content.new_ride_model.name,
slug: item.content.new_ride_model.slug,
manufacturer_id: modelManufacturerId,
category: item.content.new_ride_model.category,
ride_type: item.content.new_ride_model.ride_type,
description: item.content.new_ride_model.description,
technical_specs: item.content.new_ride_model.technical_specs
})
.select()
.single();
if (modelError) {
throw new Error(`Failed to create ride model: ${modelError.message}`);
}
rideModelId = newModel.id;
toast({
title: "Ride Model Created",
description: `Created ${newModel.name}`,
});
}
// STEP 3: Create the ride
const { error: rideError } = await supabase
.from('rides')
.insert({
...item.content.ride,
manufacturer_id: manufacturerId,
ride_model_id: rideModelId,
park_id: item.content.park_id
});
if (rideError) {
throw new Error(`Failed to create ride: ${rideError.message}`);
}
// STEP 4: Update submission status
const { data: { user } } = await supabase.auth.getUser();
const { error: updateError } = await supabase
.from('content_submissions')
.update({
status: 'approved',
reviewer_id: user?.id,
reviewed_at: new Date().toISOString(),
reviewer_notes: moderatorNotes
})
.eq('id', item.id);
if (updateError) throw updateError;
toast({
title: "Submission Approved",
description: "All entities created successfully",
});
// Refresh the queue
fetchItems(activeEntityFilter, activeStatusFilter);
return;
}
// Standard moderation flow for other items
const table = item.type === 'review' ? 'reviews' : 'content_submissions';
const statusField = item.type === 'review' ? 'moderation_status' : 'status';
@@ -927,12 +1038,154 @@ export const ModerationQueue = forwardRef<ModerationQueueRef>((props, ref) => {
</div>
) : (
<div>
<div className="text-sm text-muted-foreground mb-2">
Type: {item.content.submission_type}
</div>
<pre className="text-sm whitespace-pre-wrap">
{JSON.stringify(item.content.content, null, 2)}
</pre>
{/* Composite Submissions (Ride with Manufacturer/Model) */}
{(item.submission_type === 'ride_with_manufacturer' ||
item.submission_type === 'ride_with_model' ||
item.submission_type === 'ride_with_manufacturer_and_model') ? (
<div className="space-y-4">
{/* New Manufacturer Card */}
{item.content.new_manufacturer && (
<Card className="border-blue-300 dark:border-blue-700">
<CardHeader className="pb-3">
<div className="flex items-center gap-2">
<Badge variant="secondary" className="bg-blue-100 dark:bg-blue-900">
New Manufacturer
</Badge>
<span className="font-semibold">{item.content.new_manufacturer.name}</span>
</div>
</CardHeader>
<CardContent className="space-y-2 text-sm">
{item.content.new_manufacturer.description && (
<div>
<span className="font-medium">Description: </span>
<span className="text-muted-foreground">{item.content.new_manufacturer.description}</span>
</div>
)}
<div className="grid grid-cols-2 gap-2">
{item.content.new_manufacturer.person_type && (
<div>
<span className="font-medium">Type: </span>
<span className="text-muted-foreground capitalize">{item.content.new_manufacturer.person_type}</span>
</div>
)}
{item.content.new_manufacturer.founded_year && (
<div>
<span className="font-medium">Founded: </span>
<span className="text-muted-foreground">{item.content.new_manufacturer.founded_year}</span>
</div>
)}
{item.content.new_manufacturer.headquarters_location && (
<div>
<span className="font-medium">HQ: </span>
<span className="text-muted-foreground">{item.content.new_manufacturer.headquarters_location}</span>
</div>
)}
{item.content.new_manufacturer.website_url && (
<div>
<span className="font-medium">Website: </span>
<a href={item.content.new_manufacturer.website_url} target="_blank" rel="noopener noreferrer" className="text-primary hover:underline text-xs">
{item.content.new_manufacturer.website_url}
</a>
</div>
)}
</div>
</CardContent>
</Card>
)}
{/* New Ride Model Card */}
{item.content.new_ride_model && (
<Card className="border-purple-300 dark:border-purple-700">
<CardHeader className="pb-3">
<div className="flex items-center gap-2">
<Badge variant="secondary" className="bg-purple-100 dark:bg-purple-900">
New Ride Model
</Badge>
<span className="font-semibold">{item.content.new_ride_model.name}</span>
</div>
</CardHeader>
<CardContent className="space-y-2 text-sm">
<div>
<span className="font-medium">Manufacturer: </span>
<span className="text-muted-foreground">
{item.content.new_manufacturer
? item.content.new_manufacturer.name
: 'Existing manufacturer'}
</span>
</div>
<div className="grid grid-cols-2 gap-2">
<div>
<span className="font-medium">Category: </span>
<span className="text-muted-foreground capitalize">{item.content.new_ride_model.category?.replace('_', ' ')}</span>
</div>
<div>
<span className="font-medium">Type: </span>
<span className="text-muted-foreground">{item.content.new_ride_model.ride_type}</span>
</div>
</div>
{item.content.new_ride_model.description && (
<div>
<span className="font-medium">Description: </span>
<span className="text-muted-foreground">{item.content.new_ride_model.description}</span>
</div>
)}
</CardContent>
</Card>
)}
{/* Ride Details Card */}
<Card className="border-green-300 dark:border-green-700">
<CardHeader className="pb-3">
<div className="flex items-center gap-2">
<Badge variant="secondary" className="bg-green-100 dark:bg-green-900">
Ride
</Badge>
<span className="font-semibold">{item.content.ride?.name}</span>
</div>
</CardHeader>
<CardContent className="space-y-2 text-sm">
{item.content.ride?.description && (
<p className="text-muted-foreground">{item.content.ride.description}</p>
)}
<div className="grid grid-cols-2 gap-2">
{item.content.ride?.category && (
<div>
<span className="font-medium">Category: </span>
<span className="text-muted-foreground capitalize">{item.content.ride.category.replace('_', ' ')}</span>
</div>
)}
{item.content.ride?.status && (
<div>
<span className="font-medium">Status: </span>
<span className="text-muted-foreground">{item.content.ride.status}</span>
</div>
)}
{item.content.ride?.max_speed_kmh && (
<div>
<span className="font-medium">Max Speed: </span>
<span className="text-muted-foreground">{item.content.ride.max_speed_kmh} km/h</span>
</div>
)}
{item.content.ride?.max_height_meters && (
<div>
<span className="font-medium">Max Height: </span>
<span className="text-muted-foreground">{item.content.ride.max_height_meters} m</span>
</div>
)}
</div>
</CardContent>
</Card>
</div>
) : (
<div>
<div className="text-sm text-muted-foreground mb-2">
Type: {item.content.submission_type}
</div>
<pre className="text-sm whitespace-pre-wrap">
{JSON.stringify(item.content.content, null, 2)}
</pre>
</div>
)}
</div>
)}
</div>