feat: Implement company management plan

This commit is contained in:
gpt-engineer-app[bot]
2025-09-30 03:01:53 +00:00
parent 93f86fc503
commit 556d1c5a97
11 changed files with 1938 additions and 9 deletions

View File

@@ -13,9 +13,13 @@ import ParkDetail from "./pages/ParkDetail";
import RideDetail from "./pages/RideDetail"; import RideDetail from "./pages/RideDetail";
import Rides from "./pages/Rides"; import Rides from "./pages/Rides";
import Manufacturers from "./pages/Manufacturers"; import Manufacturers from "./pages/Manufacturers";
import ManufacturerDetail from "./pages/ManufacturerDetail";
import Designers from "./pages/Designers"; import Designers from "./pages/Designers";
import DesignerDetail from "./pages/DesignerDetail";
import ParkOwners from "./pages/ParkOwners"; import ParkOwners from "./pages/ParkOwners";
import PropertyOwnerDetail from "./pages/PropertyOwnerDetail";
import Operators from "./pages/Operators"; import Operators from "./pages/Operators";
import OperatorDetail from "./pages/OperatorDetail";
import Auth from "./pages/Auth"; import Auth from "./pages/Auth";
import Profile from "./pages/Profile"; import Profile from "./pages/Profile";
import UserSettings from "./pages/UserSettings"; import UserSettings from "./pages/UserSettings";
@@ -46,9 +50,13 @@ function AppContent() {
<Route path="/rides" element={<Rides />} /> <Route path="/rides" element={<Rides />} />
<Route path="/search" element={<Search />} /> <Route path="/search" element={<Search />} />
<Route path="/manufacturers" element={<Manufacturers />} /> <Route path="/manufacturers" element={<Manufacturers />} />
<Route path="/manufacturers/:slug" element={<ManufacturerDetail />} />
<Route path="/designers" element={<Designers />} /> <Route path="/designers" element={<Designers />} />
<Route path="/designers/:slug" element={<DesignerDetail />} />
<Route path="/owners" element={<ParkOwners />} /> <Route path="/owners" element={<ParkOwners />} />
<Route path="/owners/:slug" element={<PropertyOwnerDetail />} />
<Route path="/operators" element={<Operators />} /> <Route path="/operators" element={<Operators />} />
<Route path="/operators/:slug" element={<OperatorDetail />} />
<Route path="/auth" element={<Auth />} /> <Route path="/auth" element={<Auth />} />
<Route path="/profile" element={<Profile />} /> <Route path="/profile" element={<Profile />} />
<Route path="/profile/:username" element={<Profile />} /> <Route path="/profile/:username" element={<Profile />} />

View File

@@ -0,0 +1,207 @@
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import * as z from 'zod';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Textarea } from '@/components/ui/textarea';
import { Label } from '@/components/ui/label';
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Ruler, Save, X } from 'lucide-react';
import { Combobox } from '@/components/ui/combobox';
import { useCompanyHeadquarters } from '@/hooks/useAutocompleteData';
const designerSchema = z.object({
name: z.string().min(1, 'Name is required'),
slug: z.string().min(1, 'Slug is required'),
description: z.string().optional(),
person_type: z.enum(['company', 'individual', 'firm', 'organization']),
website_url: z.string().url().optional().or(z.literal('')),
founded_year: z.number().min(1800).max(new Date().getFullYear()).optional(),
headquarters_location: z.string().optional()
});
type DesignerFormData = z.infer<typeof designerSchema>;
interface DesignerFormProps {
onSubmit: (data: DesignerFormData) => void;
onCancel: () => void;
initialData?: Partial<DesignerFormData>;
}
export function DesignerForm({ onSubmit, onCancel, initialData }: DesignerFormProps) {
const { headquarters } = useCompanyHeadquarters();
const {
register,
handleSubmit,
setValue,
watch,
formState: { errors }
} = useForm<DesignerFormData>({
resolver: zodResolver(designerSchema),
defaultValues: {
name: initialData?.name || '',
slug: initialData?.slug || '',
description: initialData?.description || '',
person_type: initialData?.person_type || 'company',
website_url: initialData?.website_url || '',
founded_year: initialData?.founded_year || undefined,
headquarters_location: initialData?.headquarters_location || ''
}
});
const generateSlug = (name: string) => {
return name
.toLowerCase()
.replace(/[^a-z0-9\s-]/g, '')
.replace(/\s+/g, '-')
.replace(/-+/g, '-')
.trim();
};
const handleNameChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const name = e.target.value;
const slug = generateSlug(name);
setValue('slug', slug);
};
return (
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Ruler className="w-5 h-5" />
{initialData ? 'Edit Designer' : 'Create New Designer'}
</CardTitle>
</CardHeader>
<CardContent>
<form onSubmit={handleSubmit(onSubmit)} className="space-y-6">
{/* Basic Information */}
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
<div className="space-y-2">
<Label htmlFor="name">Name *</Label>
<Input
id="name"
{...register('name')}
onChange={(e) => {
register('name').onChange(e);
handleNameChange(e);
}}
placeholder="Enter designer name"
/>
{errors.name && (
<p className="text-sm text-destructive">{errors.name.message}</p>
)}
</div>
<div className="space-y-2">
<Label htmlFor="slug">URL Slug *</Label>
<Input
id="slug"
{...register('slug')}
placeholder="designer-slug"
/>
{errors.slug && (
<p className="text-sm text-destructive">{errors.slug.message}</p>
)}
</div>
</div>
{/* Description */}
<div className="space-y-2">
<Label htmlFor="description">Description</Label>
<Textarea
id="description"
{...register('description')}
placeholder="Describe the designer..."
rows={3}
/>
</div>
{/* Person Type */}
<div className="space-y-2">
<Label>Entity Type *</Label>
<RadioGroup
value={watch('person_type')}
onValueChange={(value) => setValue('person_type', value as any)}
className="grid grid-cols-2 md:grid-cols-4 gap-4"
>
<div className="flex items-center space-x-2">
<RadioGroupItem value="company" id="company" />
<Label htmlFor="company" className="cursor-pointer">Company</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="individual" id="individual" />
<Label htmlFor="individual" className="cursor-pointer">Individual</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="firm" id="firm" />
<Label htmlFor="firm" className="cursor-pointer">Firm</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="organization" id="organization" />
<Label htmlFor="organization" className="cursor-pointer">Organization</Label>
</div>
</RadioGroup>
</div>
{/* Additional Details */}
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
<div className="space-y-2">
<Label htmlFor="founded_year">Founded Year</Label>
<Input
id="founded_year"
type="number"
min="1800"
max={new Date().getFullYear()}
{...register('founded_year', { valueAsNumber: true })}
placeholder="e.g. 1972"
/>
{errors.founded_year && (
<p className="text-sm text-destructive">{errors.founded_year.message}</p>
)}
</div>
<div className="space-y-2">
<Label htmlFor="headquarters_location">Headquarters Location</Label>
<Combobox
options={headquarters}
value={watch('headquarters_location')}
onValueChange={(value) => setValue('headquarters_location', value)}
placeholder="Select or type location"
searchPlaceholder="Search locations..."
emptyText="No locations found"
/>
</div>
</div>
{/* Website */}
<div className="space-y-2">
<Label htmlFor="website_url">Website URL</Label>
<Input
id="website_url"
type="url"
{...register('website_url')}
placeholder="https://example.com"
/>
{errors.website_url && (
<p className="text-sm text-destructive">{errors.website_url.message}</p>
)}
</div>
{/* Actions */}
<div className="flex gap-3 justify-end">
<Button type="button" variant="outline" onClick={onCancel}>
<X className="w-4 h-4 mr-2" />
Cancel
</Button>
<Button type="submit">
<Save className="w-4 h-4 mr-2" />
Save Designer
</Button>
</div>
</form>
</CardContent>
</Card>
);
}

View File

@@ -0,0 +1,207 @@
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import * as z from 'zod';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Textarea } from '@/components/ui/textarea';
import { Label } from '@/components/ui/label';
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { FerrisWheel, Save, X } from 'lucide-react';
import { Combobox } from '@/components/ui/combobox';
import { useCompanyHeadquarters } from '@/hooks/useAutocompleteData';
const operatorSchema = z.object({
name: z.string().min(1, 'Name is required'),
slug: z.string().min(1, 'Slug is required'),
description: z.string().optional(),
person_type: z.enum(['company', 'individual', 'firm', 'organization']),
website_url: z.string().url().optional().or(z.literal('')),
founded_year: z.number().min(1800).max(new Date().getFullYear()).optional(),
headquarters_location: z.string().optional()
});
type OperatorFormData = z.infer<typeof operatorSchema>;
interface OperatorFormProps {
onSubmit: (data: OperatorFormData) => void;
onCancel: () => void;
initialData?: Partial<OperatorFormData>;
}
export function OperatorForm({ onSubmit, onCancel, initialData }: OperatorFormProps) {
const { headquarters } = useCompanyHeadquarters();
const {
register,
handleSubmit,
setValue,
watch,
formState: { errors }
} = useForm<OperatorFormData>({
resolver: zodResolver(operatorSchema),
defaultValues: {
name: initialData?.name || '',
slug: initialData?.slug || '',
description: initialData?.description || '',
person_type: initialData?.person_type || 'company',
website_url: initialData?.website_url || '',
founded_year: initialData?.founded_year || undefined,
headquarters_location: initialData?.headquarters_location || ''
}
});
const generateSlug = (name: string) => {
return name
.toLowerCase()
.replace(/[^a-z0-9\s-]/g, '')
.replace(/\s+/g, '-')
.replace(/-+/g, '-')
.trim();
};
const handleNameChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const name = e.target.value;
const slug = generateSlug(name);
setValue('slug', slug);
};
return (
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<FerrisWheel className="w-5 h-5" />
{initialData ? 'Edit Operator' : 'Create New Operator'}
</CardTitle>
</CardHeader>
<CardContent>
<form onSubmit={handleSubmit(onSubmit)} className="space-y-6">
{/* Basic Information */}
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
<div className="space-y-2">
<Label htmlFor="name">Name *</Label>
<Input
id="name"
{...register('name')}
onChange={(e) => {
register('name').onChange(e);
handleNameChange(e);
}}
placeholder="Enter operator name"
/>
{errors.name && (
<p className="text-sm text-destructive">{errors.name.message}</p>
)}
</div>
<div className="space-y-2">
<Label htmlFor="slug">URL Slug *</Label>
<Input
id="slug"
{...register('slug')}
placeholder="operator-slug"
/>
{errors.slug && (
<p className="text-sm text-destructive">{errors.slug.message}</p>
)}
</div>
</div>
{/* Description */}
<div className="space-y-2">
<Label htmlFor="description">Description</Label>
<Textarea
id="description"
{...register('description')}
placeholder="Describe the operator..."
rows={3}
/>
</div>
{/* Person Type */}
<div className="space-y-2">
<Label>Entity Type *</Label>
<RadioGroup
value={watch('person_type')}
onValueChange={(value) => setValue('person_type', value as any)}
className="grid grid-cols-2 md:grid-cols-4 gap-4"
>
<div className="flex items-center space-x-2">
<RadioGroupItem value="company" id="company" />
<Label htmlFor="company" className="cursor-pointer">Company</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="individual" id="individual" />
<Label htmlFor="individual" className="cursor-pointer">Individual</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="firm" id="firm" />
<Label htmlFor="firm" className="cursor-pointer">Firm</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="organization" id="organization" />
<Label htmlFor="organization" className="cursor-pointer">Organization</Label>
</div>
</RadioGroup>
</div>
{/* Additional Details */}
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
<div className="space-y-2">
<Label htmlFor="founded_year">Founded Year</Label>
<Input
id="founded_year"
type="number"
min="1800"
max={new Date().getFullYear()}
{...register('founded_year', { valueAsNumber: true })}
placeholder="e.g. 1972"
/>
{errors.founded_year && (
<p className="text-sm text-destructive">{errors.founded_year.message}</p>
)}
</div>
<div className="space-y-2">
<Label htmlFor="headquarters_location">Headquarters Location</Label>
<Combobox
options={headquarters}
value={watch('headquarters_location')}
onValueChange={(value) => setValue('headquarters_location', value)}
placeholder="Select or type location"
searchPlaceholder="Search locations..."
emptyText="No locations found"
/>
</div>
</div>
{/* Website */}
<div className="space-y-2">
<Label htmlFor="website_url">Website URL</Label>
<Input
id="website_url"
type="url"
{...register('website_url')}
placeholder="https://example.com"
/>
{errors.website_url && (
<p className="text-sm text-destructive">{errors.website_url.message}</p>
)}
</div>
{/* Actions */}
<div className="flex gap-3 justify-end">
<Button type="button" variant="outline" onClick={onCancel}>
<X className="w-4 h-4 mr-2" />
Cancel
</Button>
<Button type="submit">
<Save className="w-4 h-4 mr-2" />
Save Operator
</Button>
</div>
</form>
</CardContent>
</Card>
);
}

View File

@@ -0,0 +1,207 @@
import { useForm } from 'react-hook-form';
import { zodResolver } from '@hookform/resolvers/zod';
import * as z from 'zod';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Textarea } from '@/components/ui/textarea';
import { Label } from '@/components/ui/label';
import { RadioGroup, RadioGroupItem } from '@/components/ui/radio-group';
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
import { Building2, Save, X } from 'lucide-react';
import { Combobox } from '@/components/ui/combobox';
import { useCompanyHeadquarters } from '@/hooks/useAutocompleteData';
const propertyOwnerSchema = z.object({
name: z.string().min(1, 'Name is required'),
slug: z.string().min(1, 'Slug is required'),
description: z.string().optional(),
person_type: z.enum(['company', 'individual', 'firm', 'organization']),
website_url: z.string().url().optional().or(z.literal('')),
founded_year: z.number().min(1800).max(new Date().getFullYear()).optional(),
headquarters_location: z.string().optional()
});
type PropertyOwnerFormData = z.infer<typeof propertyOwnerSchema>;
interface PropertyOwnerFormProps {
onSubmit: (data: PropertyOwnerFormData) => void;
onCancel: () => void;
initialData?: Partial<PropertyOwnerFormData>;
}
export function PropertyOwnerForm({ onSubmit, onCancel, initialData }: PropertyOwnerFormProps) {
const { headquarters } = useCompanyHeadquarters();
const {
register,
handleSubmit,
setValue,
watch,
formState: { errors }
} = useForm<PropertyOwnerFormData>({
resolver: zodResolver(propertyOwnerSchema),
defaultValues: {
name: initialData?.name || '',
slug: initialData?.slug || '',
description: initialData?.description || '',
person_type: initialData?.person_type || 'company',
website_url: initialData?.website_url || '',
founded_year: initialData?.founded_year || undefined,
headquarters_location: initialData?.headquarters_location || ''
}
});
const generateSlug = (name: string) => {
return name
.toLowerCase()
.replace(/[^a-z0-9\s-]/g, '')
.replace(/\s+/g, '-')
.replace(/-+/g, '-')
.trim();
};
const handleNameChange = (e: React.ChangeEvent<HTMLInputElement>) => {
const name = e.target.value;
const slug = generateSlug(name);
setValue('slug', slug);
};
return (
<Card>
<CardHeader>
<CardTitle className="flex items-center gap-2">
<Building2 className="w-5 h-5" />
{initialData ? 'Edit Property Owner' : 'Create New Property Owner'}
</CardTitle>
</CardHeader>
<CardContent>
<form onSubmit={handleSubmit(onSubmit)} className="space-y-6">
{/* Basic Information */}
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
<div className="space-y-2">
<Label htmlFor="name">Name *</Label>
<Input
id="name"
{...register('name')}
onChange={(e) => {
register('name').onChange(e);
handleNameChange(e);
}}
placeholder="Enter property owner name"
/>
{errors.name && (
<p className="text-sm text-destructive">{errors.name.message}</p>
)}
</div>
<div className="space-y-2">
<Label htmlFor="slug">URL Slug *</Label>
<Input
id="slug"
{...register('slug')}
placeholder="property-owner-slug"
/>
{errors.slug && (
<p className="text-sm text-destructive">{errors.slug.message}</p>
)}
</div>
</div>
{/* Description */}
<div className="space-y-2">
<Label htmlFor="description">Description</Label>
<Textarea
id="description"
{...register('description')}
placeholder="Describe the property owner..."
rows={3}
/>
</div>
{/* Person Type */}
<div className="space-y-2">
<Label>Entity Type *</Label>
<RadioGroup
value={watch('person_type')}
onValueChange={(value) => setValue('person_type', value as any)}
className="grid grid-cols-2 md:grid-cols-4 gap-4"
>
<div className="flex items-center space-x-2">
<RadioGroupItem value="company" id="company" />
<Label htmlFor="company" className="cursor-pointer">Company</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="individual" id="individual" />
<Label htmlFor="individual" className="cursor-pointer">Individual</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="firm" id="firm" />
<Label htmlFor="firm" className="cursor-pointer">Firm</Label>
</div>
<div className="flex items-center space-x-2">
<RadioGroupItem value="organization" id="organization" />
<Label htmlFor="organization" className="cursor-pointer">Organization</Label>
</div>
</RadioGroup>
</div>
{/* Additional Details */}
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
<div className="space-y-2">
<Label htmlFor="founded_year">Founded Year</Label>
<Input
id="founded_year"
type="number"
min="1800"
max={new Date().getFullYear()}
{...register('founded_year', { valueAsNumber: true })}
placeholder="e.g. 1972"
/>
{errors.founded_year && (
<p className="text-sm text-destructive">{errors.founded_year.message}</p>
)}
</div>
<div className="space-y-2">
<Label htmlFor="headquarters_location">Headquarters Location</Label>
<Combobox
options={headquarters}
value={watch('headquarters_location')}
onValueChange={(value) => setValue('headquarters_location', value)}
placeholder="Select or type location"
searchPlaceholder="Search locations..."
emptyText="No locations found"
/>
</div>
</div>
{/* Website */}
<div className="space-y-2">
<Label htmlFor="website_url">Website URL</Label>
<Input
id="website_url"
type="url"
{...register('website_url')}
placeholder="https://example.com"
/>
{errors.website_url && (
<p className="text-sm text-destructive">{errors.website_url.message}</p>
)}
</div>
{/* Actions */}
<div className="flex gap-3 justify-end">
<Button type="button" variant="outline" onClick={onCancel}>
<X className="w-4 h-4 mr-2" />
Cancel
</Button>
<Button type="submit">
<Save className="w-4 h-4 mr-2" />
Save Property Owner
</Button>
</div>
</form>
</CardContent>
</Card>
);
}

86
src/lib/companyHelpers.ts Normal file
View File

@@ -0,0 +1,86 @@
import { supabase } from '@/integrations/supabase/client';
export interface CompanyFormData {
name: string;
slug: string;
description?: string;
person_type: 'company' | 'individual' | 'firm' | 'organization';
website_url?: string;
founded_year?: number;
headquarters_location?: string;
}
export async function submitCompanyCreation(
data: CompanyFormData,
companyType: 'manufacturer' | 'designer' | 'operator' | 'property_owner',
userId: string,
isModerator: boolean
) {
if (isModerator) {
// Moderators can create directly
const { data: newCompany, error } = await supabase
.from('companies')
.insert({
...data,
company_type: companyType
})
.select()
.single();
if (error) throw error;
return { company: newCompany, submitted: false };
} else {
// Regular users submit for moderation
const { error } = await supabase
.from('content_submissions')
.insert({
user_id: userId,
submission_type: 'company_create',
content: {
...data,
company_type: companyType
},
status: 'pending'
});
if (error) throw error;
return { company: null, submitted: true };
}
}
export async function submitCompanyUpdate(
companyId: string,
data: CompanyFormData,
userId: string,
isModerator: boolean
) {
if (isModerator) {
// Moderators can update directly
const { error } = await supabase
.from('companies')
.update({
...data,
updated_at: new Date().toISOString()
})
.eq('id', companyId);
if (error) throw error;
return { submitted: false };
} else {
// Regular users submit for moderation
const { error } = await supabase
.from('content_submissions')
.insert({
user_id: userId,
submission_type: 'company_edit',
content: {
company_id: companyId,
...data
},
status: 'pending'
});
if (error) throw error;
return { submitted: true };
}
}

View File

@@ -0,0 +1,277 @@
import { useState, useEffect } from 'react';
import { useParams, useNavigate } from 'react-router-dom';
import { Header } from '@/components/layout/Header';
import { Button } from '@/components/ui/button';
import { Badge } from '@/components/ui/badge';
import { Card, CardContent } from '@/components/ui/card';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
import { Dialog, DialogContent } from '@/components/ui/dialog';
import { ArrowLeft, MapPin, Star, Globe, Calendar, Edit, Ruler } from 'lucide-react';
import { Company } from '@/types/database';
import { supabase } from '@/integrations/supabase/client';
import { DesignerForm } from '@/components/admin/DesignerForm';
import { DesignerPhotoGallery } from '@/components/companies/DesignerPhotoGallery';
import { useAuth } from '@/hooks/useAuth';
import { useUserRole } from '@/hooks/useUserRole';
import { toast } from '@/hooks/use-toast';
import { submitCompanyUpdate } from '@/lib/companyHelpers';
export default function DesignerDetail() {
const { slug } = useParams<{ slug: string }>();
const navigate = useNavigate();
const [designer, setDesigner] = useState<Company | null>(null);
const [loading, setLoading] = useState(true);
const [isEditModalOpen, setIsEditModalOpen] = useState(false);
const { user } = useAuth();
const { isModerator } = useUserRole();
useEffect(() => {
if (slug) {
fetchDesignerData();
}
}, [slug]);
const fetchDesignerData = async () => {
try {
const { data, error } = await supabase
.from('companies')
.select('*')
.eq('slug', slug)
.eq('company_type', 'designer')
.maybeSingle();
if (error) throw error;
setDesigner(data);
} catch (error) {
console.error('Error fetching designer:', error);
} finally {
setLoading(false);
}
};
const handleEditSubmit = async (data: any) => {
try {
const result = await submitCompanyUpdate(
designer!.id,
data,
user!.id,
isModerator()
);
toast({
title: result.submitted ? "Edit Submitted" : "Designer Updated",
description: result.submitted
? "Your edit has been submitted for review."
: "The designer has been updated successfully."
});
setIsEditModalOpen(false);
if (!result.submitted) {
fetchDesignerData();
}
} catch (error: any) {
toast({
title: "Error",
description: error.message || "Failed to submit edit.",
variant: "destructive"
});
}
};
if (loading) {
return (
<div className="min-h-screen bg-background">
<Header />
<div className="container mx-auto px-4 py-8">
<div className="animate-pulse space-y-6">
<div className="h-64 bg-muted rounded-lg"></div>
<div className="h-8 bg-muted rounded w-1/2"></div>
</div>
</div>
</div>
);
}
if (!designer) {
return (
<div className="min-h-screen bg-background">
<Header />
<div className="container mx-auto px-4 py-8">
<div className="text-center py-12">
<h1 className="text-2xl font-bold mb-4">Designer Not Found</h1>
<Button onClick={() => navigate('/designers')}>
<ArrowLeft className="w-4 h-4 mr-2" />
Back to Designers
</Button>
</div>
</div>
</div>
);
}
return (
<div className="min-h-screen bg-background">
<Header />
<main className="container mx-auto px-4 py-8">
{/* Back Button and Edit Button */}
<div className="flex items-center justify-between mb-6">
<Button variant="ghost" onClick={() => navigate('/designers')}>
<ArrowLeft className="w-4 h-4 mr-2" />
Back to Designers
</Button>
<Button
variant="outline"
onClick={() => {
if (!user) {
navigate('/auth');
} else {
setIsEditModalOpen(true);
}
}}
>
<Edit className="w-4 h-4 mr-2" />
Edit Designer
</Button>
</div>
{/* Hero Section */}
<div className="relative mb-8">
<div className="aspect-[21/9] bg-gradient-to-br from-primary/20 via-secondary/20 to-accent/20 rounded-lg overflow-hidden relative">
{designer.logo_url ? (
<div className="flex items-center justify-center h-full bg-background/90">
<img
src={designer.logo_url}
alt={designer.name}
className="max-h-48 object-contain"
/>
</div>
) : (
<div className="flex items-center justify-center h-full">
<Ruler className="w-24 h-24 opacity-50" />
</div>
)}
<div className="absolute bottom-0 left-0 right-0 p-8 bg-gradient-to-t from-black/60 to-transparent">
<div className="flex items-end justify-between">
<div>
<Badge variant="outline" className="bg-black/20 text-white border-white/20 mb-2">
Designer
</Badge>
<h1 className="text-4xl md:text-6xl font-bold text-white mb-2">
{designer.name}
</h1>
{designer.headquarters_location && (
<div className="flex items-center text-white/90 text-lg">
<MapPin className="w-5 h-5 mr-2" />
{designer.headquarters_location}
</div>
)}
</div>
{designer.average_rating > 0 && (
<div className="bg-black/30 backdrop-blur-md rounded-lg p-6 text-center">
<div className="flex items-center gap-2 text-white mb-2">
<Star className="w-6 h-6 fill-yellow-400 text-yellow-400" />
<span className="text-3xl font-bold">
{designer.average_rating.toFixed(1)}
</span>
</div>
<div className="text-white/90 text-sm">
{designer.review_count} {designer.review_count === 1 ? "review" : "reviews"}
</div>
</div>
)}
</div>
</div>
</div>
</div>
{/* Company Info */}
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 mb-8">
{designer.founded_year && (
<Card>
<CardContent className="p-4 text-center">
<Calendar className="w-6 h-6 text-primary mx-auto mb-2" />
<div className="text-2xl font-bold">{designer.founded_year}</div>
<div className="text-sm text-muted-foreground">Founded</div>
</CardContent>
</Card>
)}
{designer.website_url && (
<Card>
<CardContent className="p-4 text-center">
<Globe className="w-6 h-6 text-primary mx-auto mb-2" />
<a
href={designer.website_url}
target="_blank"
rel="noopener noreferrer"
className="text-sm text-primary hover:underline break-all"
>
Visit Website
</a>
</CardContent>
</Card>
)}
</div>
{/* Tabs */}
<Tabs defaultValue="overview" className="w-full">
<TabsList className="grid w-full grid-cols-3">
<TabsTrigger value="overview">Overview</TabsTrigger>
<TabsTrigger value="rides">Rides</TabsTrigger>
<TabsTrigger value="photos">Photos</TabsTrigger>
</TabsList>
<TabsContent value="overview" className="space-y-6">
{designer.description && (
<Card>
<CardContent className="p-6">
<h2 className="text-2xl font-bold mb-4">About</h2>
<p className="text-muted-foreground whitespace-pre-wrap">
{designer.description}
</p>
</CardContent>
</Card>
)}
</TabsContent>
<TabsContent value="rides">
<Card>
<CardContent className="p-6">
<p className="text-muted-foreground">Rides designed by {designer.name} will be displayed here.</p>
</CardContent>
</Card>
</TabsContent>
<TabsContent value="photos">
<DesignerPhotoGallery
designerId={designer.id}
designerName={designer.name}
/>
</TabsContent>
</Tabs>
</main>
{/* Edit Modal */}
<Dialog open={isEditModalOpen} onOpenChange={setIsEditModalOpen}>
<DialogContent className="max-w-4xl max-h-[90vh] overflow-y-auto">
<DesignerForm
initialData={{
name: designer.name,
slug: designer.slug,
description: designer.description,
person_type: designer.person_type as any,
website_url: designer.website_url,
founded_year: designer.founded_year,
headquarters_location: designer.headquarters_location
}}
onSubmit={handleEditSubmit}
onCancel={() => setIsEditModalOpen(false)}
/>
</DialogContent>
</Dialog>
</div>
);
}

View File

@@ -1,18 +1,48 @@
import { useState, useEffect } from 'react'; import { useState, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { Header } from '@/components/layout/Header'; import { Header } from '@/components/layout/Header';
import { Input } from '@/components/ui/input'; import { Input } from '@/components/ui/input';
import { Button } from '@/components/ui/button';
import { Dialog, DialogContent } from '@/components/ui/dialog';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
import { Badge } from '@/components/ui/badge'; import { Badge } from '@/components/ui/badge';
import { Search, SlidersHorizontal, Palette } from 'lucide-react'; import { Search, SlidersHorizontal, Ruler, Plus } from 'lucide-react';
import { Company } from '@/types/database'; import { Company } from '@/types/database';
import { supabase } from '@/integrations/supabase/client'; import { supabase } from '@/integrations/supabase/client';
import { DesignerCard } from '@/components/designers/DesignerCard'; import { DesignerCard } from '@/components/designers/DesignerCard';
import { DesignerForm } from '@/components/admin/DesignerForm';
import { useAuth } from '@/hooks/useAuth';
import { useUserRole } from '@/hooks/useUserRole';
import { toast } from '@/hooks/use-toast';
import { submitCompanyCreation } from '@/lib/companyHelpers';
export default function Designers() { export default function Designers() {
const navigate = useNavigate();
const { user } = useAuth();
const { isModerator } = useUserRole();
const [companies, setCompanies] = useState<Company[]>([]); const [companies, setCompanies] = useState<Company[]>([]);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [searchQuery, setSearchQuery] = useState(''); const [searchQuery, setSearchQuery] = useState('');
const [sortBy, setSortBy] = useState('name'); const [sortBy, setSortBy] = useState('name');
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
const handleCreateSubmit = async (data: any) => {
try {
if (!user) {
navigate('/auth');
return;
}
const result = await submitCompanyCreation(data, 'designer', user.id, isModerator());
toast({
title: result.submitted ? "Designer Submitted" : "Designer Created",
description: result.submitted ? "Your submission has been sent for review." : "The designer has been created successfully."
});
setIsCreateModalOpen(false);
if (!result.submitted) fetchCompanies();
} catch (error: any) {
toast({ title: "Error", description: error.message || "Failed to create designer.", variant: "destructive" });
}
};
useEffect(() => { useEffect(() => {
fetchCompanies(); fetchCompanies();
@@ -76,10 +106,17 @@ export default function Designers() {
<main className="container mx-auto px-4 py-8"> <main className="container mx-auto px-4 py-8">
{/* Page Header */} {/* Page Header */}
<div className="mb-8"> <div className="mb-8">
<div className="flex items-center gap-3 mb-4"> <div className="flex items-center justify-between mb-4">
<Palette className="w-10 h-10 text-primary" /> <div className="flex items-center gap-3">
<Ruler className="w-10 h-10 text-primary" />
<h1 className="text-4xl font-bold">Designers</h1> <h1 className="text-4xl font-bold">Designers</h1>
</div> </div>
{(user && isModerator()) && (
<Button onClick={() => setIsCreateModalOpen(true)}>
<Plus className="w-4 h-4 mr-2" />Create Designer
</Button>
)}
</div>
<p className="text-lg text-muted-foreground"> <p className="text-lg text-muted-foreground">
Explore the designers behind your favorite rides and attractions Explore the designers behind your favorite rides and attractions
</p> </p>
@@ -124,7 +161,7 @@ export default function Designers() {
</div> </div>
) : ( ) : (
<div className="text-center py-12"> <div className="text-center py-12">
<Palette className="w-16 h-16 mb-4 mx-auto text-muted-foreground" /> <Ruler className="w-16 h-16 mb-4 mx-auto text-muted-foreground" />
<h3 className="text-xl font-semibold mb-2">No designers found</h3> <h3 className="text-xl font-semibold mb-2">No designers found</h3>
<p className="text-muted-foreground"> <p className="text-muted-foreground">
Try adjusting your search criteria Try adjusting your search criteria
@@ -132,6 +169,11 @@ export default function Designers() {
</div> </div>
)} )}
</main> </main>
<Dialog open={isCreateModalOpen} onOpenChange={setIsCreateModalOpen}>
<DialogContent className="max-w-4xl max-h-[90vh] overflow-y-auto">
<DesignerForm onSubmit={handleCreateSubmit} onCancel={() => setIsCreateModalOpen(false)} />
</DialogContent>
</Dialog>
</div> </div>
); );
} }

View File

@@ -0,0 +1,277 @@
import { useState, useEffect } from 'react';
import { useParams, useNavigate } from 'react-router-dom';
import { Header } from '@/components/layout/Header';
import { Button } from '@/components/ui/button';
import { Badge } from '@/components/ui/badge';
import { Card, CardContent } from '@/components/ui/card';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
import { Dialog, DialogContent } from '@/components/ui/dialog';
import { ArrowLeft, MapPin, Star, Globe, Calendar, Edit, Factory, FerrisWheel } from 'lucide-react';
import { Company } from '@/types/database';
import { supabase } from '@/integrations/supabase/client';
import { ManufacturerForm } from '@/components/admin/ManufacturerForm';
import { ManufacturerPhotoGallery } from '@/components/companies/ManufacturerPhotoGallery';
import { useAuth } from '@/hooks/useAuth';
import { useUserRole } from '@/hooks/useUserRole';
import { toast } from '@/hooks/use-toast';
import { submitCompanyUpdate } from '@/lib/companyHelpers';
export default function ManufacturerDetail() {
const { slug } = useParams<{ slug: string }>();
const navigate = useNavigate();
const [manufacturer, setManufacturer] = useState<Company | null>(null);
const [loading, setLoading] = useState(true);
const [isEditModalOpen, setIsEditModalOpen] = useState(false);
const { user } = useAuth();
const { isModerator } = useUserRole();
useEffect(() => {
if (slug) {
fetchManufacturerData();
}
}, [slug]);
const fetchManufacturerData = async () => {
try {
const { data, error } = await supabase
.from('companies')
.select('*')
.eq('slug', slug)
.eq('company_type', 'manufacturer')
.maybeSingle();
if (error) throw error;
setManufacturer(data);
} catch (error) {
console.error('Error fetching manufacturer:', error);
} finally {
setLoading(false);
}
};
const handleEditSubmit = async (data: any) => {
try {
const result = await submitCompanyUpdate(
manufacturer!.id,
data,
user!.id,
isModerator()
);
toast({
title: result.submitted ? "Edit Submitted" : "Manufacturer Updated",
description: result.submitted
? "Your edit has been submitted for review."
: "The manufacturer has been updated successfully."
});
setIsEditModalOpen(false);
if (!result.submitted) {
fetchManufacturerData();
}
} catch (error: any) {
toast({
title: "Error",
description: error.message || "Failed to submit edit.",
variant: "destructive"
});
}
};
if (loading) {
return (
<div className="min-h-screen bg-background">
<Header />
<div className="container mx-auto px-4 py-8">
<div className="animate-pulse space-y-6">
<div className="h-64 bg-muted rounded-lg"></div>
<div className="h-8 bg-muted rounded w-1/2"></div>
</div>
</div>
</div>
);
}
if (!manufacturer) {
return (
<div className="min-h-screen bg-background">
<Header />
<div className="container mx-auto px-4 py-8">
<div className="text-center py-12">
<h1 className="text-2xl font-bold mb-4">Manufacturer Not Found</h1>
<Button onClick={() => navigate('/manufacturers')}>
<ArrowLeft className="w-4 h-4 mr-2" />
Back to Manufacturers
</Button>
</div>
</div>
</div>
);
}
return (
<div className="min-h-screen bg-background">
<Header />
<main className="container mx-auto px-4 py-8">
{/* Back Button and Edit Button */}
<div className="flex items-center justify-between mb-6">
<Button variant="ghost" onClick={() => navigate('/manufacturers')}>
<ArrowLeft className="w-4 h-4 mr-2" />
Back to Manufacturers
</Button>
<Button
variant="outline"
onClick={() => {
if (!user) {
navigate('/auth');
} else {
setIsEditModalOpen(true);
}
}}
>
<Edit className="w-4 h-4 mr-2" />
Edit Manufacturer
</Button>
</div>
{/* Hero Section */}
<div className="relative mb-8">
<div className="aspect-[21/9] bg-gradient-to-br from-primary/20 via-secondary/20 to-accent/20 rounded-lg overflow-hidden relative">
{manufacturer.logo_url ? (
<div className="flex items-center justify-center h-full bg-background/90">
<img
src={manufacturer.logo_url}
alt={manufacturer.name}
className="max-h-48 object-contain"
/>
</div>
) : (
<div className="flex items-center justify-center h-full">
<Factory className="w-24 h-24 opacity-50" />
</div>
)}
<div className="absolute bottom-0 left-0 right-0 p-8 bg-gradient-to-t from-black/60 to-transparent">
<div className="flex items-end justify-between">
<div>
<Badge variant="outline" className="bg-black/20 text-white border-white/20 mb-2">
Manufacturer
</Badge>
<h1 className="text-4xl md:text-6xl font-bold text-white mb-2">
{manufacturer.name}
</h1>
{manufacturer.headquarters_location && (
<div className="flex items-center text-white/90 text-lg">
<MapPin className="w-5 h-5 mr-2" />
{manufacturer.headquarters_location}
</div>
)}
</div>
{manufacturer.average_rating > 0 && (
<div className="bg-black/30 backdrop-blur-md rounded-lg p-6 text-center">
<div className="flex items-center gap-2 text-white mb-2">
<Star className="w-6 h-6 fill-yellow-400 text-yellow-400" />
<span className="text-3xl font-bold">
{manufacturer.average_rating.toFixed(1)}
</span>
</div>
<div className="text-white/90 text-sm">
{manufacturer.review_count} {manufacturer.review_count === 1 ? "review" : "reviews"}
</div>
</div>
)}
</div>
</div>
</div>
</div>
{/* Company Info */}
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 mb-8">
{manufacturer.founded_year && (
<Card>
<CardContent className="p-4 text-center">
<Calendar className="w-6 h-6 text-primary mx-auto mb-2" />
<div className="text-2xl font-bold">{manufacturer.founded_year}</div>
<div className="text-sm text-muted-foreground">Founded</div>
</CardContent>
</Card>
)}
{manufacturer.website_url && (
<Card>
<CardContent className="p-4 text-center">
<Globe className="w-6 h-6 text-primary mx-auto mb-2" />
<a
href={manufacturer.website_url}
target="_blank"
rel="noopener noreferrer"
className="text-sm text-primary hover:underline break-all"
>
Visit Website
</a>
</CardContent>
</Card>
)}
</div>
{/* Tabs */}
<Tabs defaultValue="overview" className="w-full">
<TabsList className="grid w-full grid-cols-3">
<TabsTrigger value="overview">Overview</TabsTrigger>
<TabsTrigger value="rides">Rides</TabsTrigger>
<TabsTrigger value="photos">Photos</TabsTrigger>
</TabsList>
<TabsContent value="overview" className="space-y-6">
{manufacturer.description && (
<Card>
<CardContent className="p-6">
<h2 className="text-2xl font-bold mb-4">About</h2>
<p className="text-muted-foreground whitespace-pre-wrap">
{manufacturer.description}
</p>
</CardContent>
</Card>
)}
</TabsContent>
<TabsContent value="rides">
<Card>
<CardContent className="p-6">
<p className="text-muted-foreground">Rides manufactured by {manufacturer.name} will be displayed here.</p>
</CardContent>
</Card>
</TabsContent>
<TabsContent value="photos">
<ManufacturerPhotoGallery
manufacturerId={manufacturer.id}
manufacturerName={manufacturer.name}
/>
</TabsContent>
</Tabs>
</main>
{/* Edit Modal */}
<Dialog open={isEditModalOpen} onOpenChange={setIsEditModalOpen}>
<DialogContent className="max-w-4xl max-h-[90vh] overflow-y-auto">
<ManufacturerForm
initialData={{
name: manufacturer.name,
slug: manufacturer.slug,
description: manufacturer.description,
person_type: manufacturer.person_type as any,
website_url: manufacturer.website_url,
founded_year: manufacturer.founded_year,
headquarters_location: manufacturer.headquarters_location
}}
onSubmit={handleEditSubmit}
onCancel={() => setIsEditModalOpen(false)}
/>
</DialogContent>
</Dialog>
</div>
);
}

View File

@@ -1,18 +1,30 @@
import { useState, useEffect } from 'react'; import { useState, useEffect } from 'react';
import { useNavigate } from 'react-router-dom';
import { Header } from '@/components/layout/Header'; import { Header } from '@/components/layout/Header';
import { Input } from '@/components/ui/input'; import { Input } from '@/components/ui/input';
import { Button } from '@/components/ui/button';
import { Dialog, DialogContent } from '@/components/ui/dialog';
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
import { Badge } from '@/components/ui/badge'; import { Badge } from '@/components/ui/badge';
import { Search, SlidersHorizontal, Factory } from 'lucide-react'; import { Search, SlidersHorizontal, Factory, Plus } from 'lucide-react';
import { Company } from '@/types/database'; import { Company } from '@/types/database';
import { supabase } from '@/integrations/supabase/client'; import { supabase } from '@/integrations/supabase/client';
import { ManufacturerCard } from '@/components/manufacturers/ManufacturerCard'; import { ManufacturerCard } from '@/components/manufacturers/ManufacturerCard';
import { ManufacturerForm } from '@/components/admin/ManufacturerForm';
import { useAuth } from '@/hooks/useAuth';
import { useUserRole } from '@/hooks/useUserRole';
import { toast } from '@/hooks/use-toast';
import { submitCompanyCreation } from '@/lib/companyHelpers';
export default function Manufacturers() { export default function Manufacturers() {
const navigate = useNavigate();
const { user } = useAuth();
const { isModerator } = useUserRole();
const [companies, setCompanies] = useState<Company[]>([]); const [companies, setCompanies] = useState<Company[]>([]);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [searchQuery, setSearchQuery] = useState(''); const [searchQuery, setSearchQuery] = useState('');
const [sortBy, setSortBy] = useState('name'); const [sortBy, setSortBy] = useState('name');
const [isCreateModalOpen, setIsCreateModalOpen] = useState(false);
useEffect(() => { useEffect(() => {
@@ -52,6 +64,40 @@ export default function Manufacturers() {
company.description?.toLowerCase().includes(searchQuery.toLowerCase()) company.description?.toLowerCase().includes(searchQuery.toLowerCase())
); );
const handleCreateSubmit = async (data: any) => {
try {
if (!user) {
navigate('/auth');
return;
}
const result = await submitCompanyCreation(
data,
'manufacturer',
user.id,
isModerator()
);
toast({
title: result.submitted ? "Manufacturer Submitted" : "Manufacturer Created",
description: result.submitted
? "Your submission has been sent for review."
: "The manufacturer has been created successfully."
});
setIsCreateModalOpen(false);
if (!result.submitted) {
fetchCompanies();
}
} catch (error: any) {
toast({
title: "Error",
description: error.message || "Failed to create manufacturer.",
variant: "destructive"
});
}
};
if (loading) { if (loading) {
@@ -79,10 +125,18 @@ export default function Manufacturers() {
<main className="container mx-auto px-4 py-8"> <main className="container mx-auto px-4 py-8">
{/* Page Header */} {/* Page Header */}
<div className="mb-8"> <div className="mb-8">
<div className="flex items-center gap-3 mb-4"> <div className="flex items-center justify-between mb-4">
<div className="flex items-center gap-3">
<Factory className="w-10 h-10 text-primary" /> <Factory className="w-10 h-10 text-primary" />
<h1 className="text-4xl font-bold">Manufacturers</h1> <h1 className="text-4xl font-bold">Manufacturers</h1>
</div> </div>
{(user && isModerator()) && (
<Button onClick={() => setIsCreateModalOpen(true)}>
<Plus className="w-4 h-4 mr-2" />
Create Manufacturer
</Button>
)}
</div>
<p className="text-lg text-muted-foreground"> <p className="text-lg text-muted-foreground">
Explore the manufacturers behind your favorite rides and attractions Explore the manufacturers behind your favorite rides and attractions
</p> </p>
@@ -136,6 +190,16 @@ export default function Manufacturers() {
</div> </div>
)} )}
</main> </main>
{/* Create Modal */}
<Dialog open={isCreateModalOpen} onOpenChange={setIsCreateModalOpen}>
<DialogContent className="max-w-4xl max-h-[90vh] overflow-y-auto">
<ManufacturerForm
onSubmit={handleCreateSubmit}
onCancel={() => setIsCreateModalOpen(false)}
/>
</DialogContent>
</Dialog>
</div> </div>
); );
} }

View File

@@ -0,0 +1,277 @@
import { useState, useEffect } from 'react';
import { useParams, useNavigate } from 'react-router-dom';
import { Header } from '@/components/layout/Header';
import { Button } from '@/components/ui/button';
import { Badge } from '@/components/ui/badge';
import { Card, CardContent } from '@/components/ui/card';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
import { Dialog, DialogContent } from '@/components/ui/dialog';
import { ArrowLeft, MapPin, Star, Globe, Calendar, Edit, FerrisWheel } from 'lucide-react';
import { Company } from '@/types/database';
import { supabase } from '@/integrations/supabase/client';
import { OperatorForm } from '@/components/admin/OperatorForm';
import { OperatorPhotoGallery } from '@/components/companies/OperatorPhotoGallery';
import { useAuth } from '@/hooks/useAuth';
import { useUserRole } from '@/hooks/useUserRole';
import { toast } from '@/hooks/use-toast';
import { submitCompanyUpdate } from '@/lib/companyHelpers';
export default function OperatorDetail() {
const { slug } = useParams<{ slug: string }>();
const navigate = useNavigate();
const [operator, setOperator] = useState<Company | null>(null);
const [loading, setLoading] = useState(true);
const [isEditModalOpen, setIsEditModalOpen] = useState(false);
const { user } = useAuth();
const { isModerator } = useUserRole();
useEffect(() => {
if (slug) {
fetchOperatorData();
}
}, [slug]);
const fetchOperatorData = async () => {
try {
const { data, error } = await supabase
.from('companies')
.select('*')
.eq('slug', slug)
.eq('company_type', 'operator')
.maybeSingle();
if (error) throw error;
setOperator(data);
} catch (error) {
console.error('Error fetching operator:', error);
} finally {
setLoading(false);
}
};
const handleEditSubmit = async (data: any) => {
try {
const result = await submitCompanyUpdate(
operator!.id,
data,
user!.id,
isModerator()
);
toast({
title: result.submitted ? "Edit Submitted" : "Operator Updated",
description: result.submitted
? "Your edit has been submitted for review."
: "The operator has been updated successfully."
});
setIsEditModalOpen(false);
if (!result.submitted) {
fetchOperatorData();
}
} catch (error: any) {
toast({
title: "Error",
description: error.message || "Failed to submit edit.",
variant: "destructive"
});
}
};
if (loading) {
return (
<div className="min-h-screen bg-background">
<Header />
<div className="container mx-auto px-4 py-8">
<div className="animate-pulse space-y-6">
<div className="h-64 bg-muted rounded-lg"></div>
<div className="h-8 bg-muted rounded w-1/2"></div>
</div>
</div>
</div>
);
}
if (!operator) {
return (
<div className="min-h-screen bg-background">
<Header />
<div className="container mx-auto px-4 py-8">
<div className="text-center py-12">
<h1 className="text-2xl font-bold mb-4">Operator Not Found</h1>
<Button onClick={() => navigate('/operators')}>
<ArrowLeft className="w-4 h-4 mr-2" />
Back to Operators
</Button>
</div>
</div>
</div>
);
}
return (
<div className="min-h-screen bg-background">
<Header />
<main className="container mx-auto px-4 py-8">
{/* Back Button and Edit Button */}
<div className="flex items-center justify-between mb-6">
<Button variant="ghost" onClick={() => navigate('/operators')}>
<ArrowLeft className="w-4 h-4 mr-2" />
Back to Operators
</Button>
<Button
variant="outline"
onClick={() => {
if (!user) {
navigate('/auth');
} else {
setIsEditModalOpen(true);
}
}}
>
<Edit className="w-4 h-4 mr-2" />
Edit Operator
</Button>
</div>
{/* Hero Section */}
<div className="relative mb-8">
<div className="aspect-[21/9] bg-gradient-to-br from-primary/20 via-secondary/20 to-accent/20 rounded-lg overflow-hidden relative">
{operator.logo_url ? (
<div className="flex items-center justify-center h-full bg-background/90">
<img
src={operator.logo_url}
alt={operator.name}
className="max-h-48 object-contain"
/>
</div>
) : (
<div className="flex items-center justify-center h-full">
<FerrisWheel className="w-24 h-24 opacity-50" />
</div>
)}
<div className="absolute bottom-0 left-0 right-0 p-8 bg-gradient-to-t from-black/60 to-transparent">
<div className="flex items-end justify-between">
<div>
<Badge variant="outline" className="bg-black/20 text-white border-white/20 mb-2">
Operator
</Badge>
<h1 className="text-4xl md:text-6xl font-bold text-white mb-2">
{operator.name}
</h1>
{operator.headquarters_location && (
<div className="flex items-center text-white/90 text-lg">
<MapPin className="w-5 h-5 mr-2" />
{operator.headquarters_location}
</div>
)}
</div>
{operator.average_rating > 0 && (
<div className="bg-black/30 backdrop-blur-md rounded-lg p-6 text-center">
<div className="flex items-center gap-2 text-white mb-2">
<Star className="w-6 h-6 fill-yellow-400 text-yellow-400" />
<span className="text-3xl font-bold">
{operator.average_rating.toFixed(1)}
</span>
</div>
<div className="text-white/90 text-sm">
{operator.review_count} {operator.review_count === 1 ? "review" : "reviews"}
</div>
</div>
)}
</div>
</div>
</div>
</div>
{/* Company Info */}
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 mb-8">
{operator.founded_year && (
<Card>
<CardContent className="p-4 text-center">
<Calendar className="w-6 h-6 text-primary mx-auto mb-2" />
<div className="text-2xl font-bold">{operator.founded_year}</div>
<div className="text-sm text-muted-foreground">Founded</div>
</CardContent>
</Card>
)}
{operator.website_url && (
<Card>
<CardContent className="p-4 text-center">
<Globe className="w-6 h-6 text-primary mx-auto mb-2" />
<a
href={operator.website_url}
target="_blank"
rel="noopener noreferrer"
className="text-sm text-primary hover:underline break-all"
>
Visit Website
</a>
</CardContent>
</Card>
)}
</div>
{/* Tabs */}
<Tabs defaultValue="overview" className="w-full">
<TabsList className="grid w-full grid-cols-3">
<TabsTrigger value="overview">Overview</TabsTrigger>
<TabsTrigger value="parks">Parks</TabsTrigger>
<TabsTrigger value="photos">Photos</TabsTrigger>
</TabsList>
<TabsContent value="overview" className="space-y-6">
{operator.description && (
<Card>
<CardContent className="p-6">
<h2 className="text-2xl font-bold mb-4">About</h2>
<p className="text-muted-foreground whitespace-pre-wrap">
{operator.description}
</p>
</CardContent>
</Card>
)}
</TabsContent>
<TabsContent value="parks">
<Card>
<CardContent className="p-6">
<p className="text-muted-foreground">Parks operated by {operator.name} will be displayed here.</p>
</CardContent>
</Card>
</TabsContent>
<TabsContent value="photos">
<OperatorPhotoGallery
operatorId={operator.id}
operatorName={operator.name}
/>
</TabsContent>
</Tabs>
</main>
{/* Edit Modal */}
<Dialog open={isEditModalOpen} onOpenChange={setIsEditModalOpen}>
<DialogContent className="max-w-4xl max-h-[90vh] overflow-y-auto">
<OperatorForm
initialData={{
name: operator.name,
slug: operator.slug,
description: operator.description,
person_type: operator.person_type as any,
website_url: operator.website_url,
founded_year: operator.founded_year,
headquarters_location: operator.headquarters_location
}}
onSubmit={handleEditSubmit}
onCancel={() => setIsEditModalOpen(false)}
/>
</DialogContent>
</Dialog>
</div>
);
}

View File

@@ -0,0 +1,277 @@
import { useState, useEffect } from 'react';
import { useParams, useNavigate } from 'react-router-dom';
import { Header } from '@/components/layout/Header';
import { Button } from '@/components/ui/button';
import { Badge } from '@/components/ui/badge';
import { Card, CardContent } from '@/components/ui/card';
import { Tabs, TabsContent, TabsList, TabsTrigger } from '@/components/ui/tabs';
import { Dialog, DialogContent } from '@/components/ui/dialog';
import { ArrowLeft, MapPin, Star, Globe, Calendar, Edit, Building2 } from 'lucide-react';
import { Company } from '@/types/database';
import { supabase } from '@/integrations/supabase/client';
import { PropertyOwnerForm } from '@/components/admin/PropertyOwnerForm';
import { PropertyOwnerPhotoGallery } from '@/components/companies/PropertyOwnerPhotoGallery';
import { useAuth } from '@/hooks/useAuth';
import { useUserRole } from '@/hooks/useUserRole';
import { toast } from '@/hooks/use-toast';
import { submitCompanyUpdate } from '@/lib/companyHelpers';
export default function PropertyOwnerDetail() {
const { slug } = useParams<{ slug: string }>();
const navigate = useNavigate();
const [owner, setOwner] = useState<Company | null>(null);
const [loading, setLoading] = useState(true);
const [isEditModalOpen, setIsEditModalOpen] = useState(false);
const { user } = useAuth();
const { isModerator } = useUserRole();
useEffect(() => {
if (slug) {
fetchOwnerData();
}
}, [slug]);
const fetchOwnerData = async () => {
try {
const { data, error } = await supabase
.from('companies')
.select('*')
.eq('slug', slug)
.eq('company_type', 'property_owner')
.maybeSingle();
if (error) throw error;
setOwner(data);
} catch (error) {
console.error('Error fetching property owner:', error);
} finally {
setLoading(false);
}
};
const handleEditSubmit = async (data: any) => {
try {
const result = await submitCompanyUpdate(
owner!.id,
data,
user!.id,
isModerator()
);
toast({
title: result.submitted ? "Edit Submitted" : "Property Owner Updated",
description: result.submitted
? "Your edit has been submitted for review."
: "The property owner has been updated successfully."
});
setIsEditModalOpen(false);
if (!result.submitted) {
fetchOwnerData();
}
} catch (error: any) {
toast({
title: "Error",
description: error.message || "Failed to submit edit.",
variant: "destructive"
});
}
};
if (loading) {
return (
<div className="min-h-screen bg-background">
<Header />
<div className="container mx-auto px-4 py-8">
<div className="animate-pulse space-y-6">
<div className="h-64 bg-muted rounded-lg"></div>
<div className="h-8 bg-muted rounded w-1/2"></div>
</div>
</div>
</div>
);
}
if (!owner) {
return (
<div className="min-h-screen bg-background">
<Header />
<div className="container mx-auto px-4 py-8">
<div className="text-center py-12">
<h1 className="text-2xl font-bold mb-4">Property Owner Not Found</h1>
<Button onClick={() => navigate('/owners')}>
<ArrowLeft className="w-4 h-4 mr-2" />
Back to Property Owners
</Button>
</div>
</div>
</div>
);
}
return (
<div className="min-h-screen bg-background">
<Header />
<main className="container mx-auto px-4 py-8">
{/* Back Button and Edit Button */}
<div className="flex items-center justify-between mb-6">
<Button variant="ghost" onClick={() => navigate('/owners')}>
<ArrowLeft className="w-4 h-4 mr-2" />
Back to Property Owners
</Button>
<Button
variant="outline"
onClick={() => {
if (!user) {
navigate('/auth');
} else {
setIsEditModalOpen(true);
}
}}
>
<Edit className="w-4 h-4 mr-2" />
Edit Property Owner
</Button>
</div>
{/* Hero Section */}
<div className="relative mb-8">
<div className="aspect-[21/9] bg-gradient-to-br from-primary/20 via-secondary/20 to-accent/20 rounded-lg overflow-hidden relative">
{owner.logo_url ? (
<div className="flex items-center justify-center h-full bg-background/90">
<img
src={owner.logo_url}
alt={owner.name}
className="max-h-48 object-contain"
/>
</div>
) : (
<div className="flex items-center justify-center h-full">
<Building2 className="w-24 h-24 opacity-50" />
</div>
)}
<div className="absolute bottom-0 left-0 right-0 p-8 bg-gradient-to-t from-black/60 to-transparent">
<div className="flex items-end justify-between">
<div>
<Badge variant="outline" className="bg-black/20 text-white border-white/20 mb-2">
Property Owner
</Badge>
<h1 className="text-4xl md:text-6xl font-bold text-white mb-2">
{owner.name}
</h1>
{owner.headquarters_location && (
<div className="flex items-center text-white/90 text-lg">
<MapPin className="w-5 h-5 mr-2" />
{owner.headquarters_location}
</div>
)}
</div>
{owner.average_rating > 0 && (
<div className="bg-black/30 backdrop-blur-md rounded-lg p-6 text-center">
<div className="flex items-center gap-2 text-white mb-2">
<Star className="w-6 h-6 fill-yellow-400 text-yellow-400" />
<span className="text-3xl font-bold">
{owner.average_rating.toFixed(1)}
</span>
</div>
<div className="text-white/90 text-sm">
{owner.review_count} {owner.review_count === 1 ? "review" : "reviews"}
</div>
</div>
)}
</div>
</div>
</div>
</div>
{/* Company Info */}
<div className="grid grid-cols-1 md:grid-cols-3 gap-4 mb-8">
{owner.founded_year && (
<Card>
<CardContent className="p-4 text-center">
<Calendar className="w-6 h-6 text-primary mx-auto mb-2" />
<div className="text-2xl font-bold">{owner.founded_year}</div>
<div className="text-sm text-muted-foreground">Founded</div>
</CardContent>
</Card>
)}
{owner.website_url && (
<Card>
<CardContent className="p-4 text-center">
<Globe className="w-6 h-6 text-primary mx-auto mb-2" />
<a
href={owner.website_url}
target="_blank"
rel="noopener noreferrer"
className="text-sm text-primary hover:underline break-all"
>
Visit Website
</a>
</CardContent>
</Card>
)}
</div>
{/* Tabs */}
<Tabs defaultValue="overview" className="w-full">
<TabsList className="grid w-full grid-cols-3">
<TabsTrigger value="overview">Overview</TabsTrigger>
<TabsTrigger value="parks">Parks</TabsTrigger>
<TabsTrigger value="photos">Photos</TabsTrigger>
</TabsList>
<TabsContent value="overview" className="space-y-6">
{owner.description && (
<Card>
<CardContent className="p-6">
<h2 className="text-2xl font-bold mb-4">About</h2>
<p className="text-muted-foreground whitespace-pre-wrap">
{owner.description}
</p>
</CardContent>
</Card>
)}
</TabsContent>
<TabsContent value="parks">
<Card>
<CardContent className="p-6">
<p className="text-muted-foreground">Parks owned by {owner.name} will be displayed here.</p>
</CardContent>
</Card>
</TabsContent>
<TabsContent value="photos">
<PropertyOwnerPhotoGallery
propertyOwnerId={owner.id}
propertyOwnerName={owner.name}
/>
</TabsContent>
</Tabs>
</main>
{/* Edit Modal */}
<Dialog open={isEditModalOpen} onOpenChange={setIsEditModalOpen}>
<DialogContent className="max-w-4xl max-h-[90vh] overflow-y-auto">
<PropertyOwnerForm
initialData={{
name: owner.name,
slug: owner.slug,
description: owner.description,
person_type: owner.person_type as any,
website_url: owner.website_url,
founded_year: owner.founded_year,
headquarters_location: owner.headquarters_location
}}
onSubmit={handleEditSubmit}
onCancel={() => setIsEditModalOpen(false)}
/>
</DialogContent>
</Dialog>
</div>
);
}