mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 06:51:13 -05:00
Fix operator parks list
This commit is contained in:
@@ -11,6 +11,7 @@ import { Company } from '@/types/database';
|
|||||||
import { supabase } from '@/integrations/supabase/client';
|
import { supabase } from '@/integrations/supabase/client';
|
||||||
import { OperatorForm } from '@/components/admin/OperatorForm';
|
import { OperatorForm } from '@/components/admin/OperatorForm';
|
||||||
import { OperatorPhotoGallery } from '@/components/companies/OperatorPhotoGallery';
|
import { OperatorPhotoGallery } from '@/components/companies/OperatorPhotoGallery';
|
||||||
|
import { ParkCard } from '@/components/parks/ParkCard';
|
||||||
import { useAuth } from '@/hooks/useAuth';
|
import { useAuth } from '@/hooks/useAuth';
|
||||||
import { useUserRole } from '@/hooks/useUserRole';
|
import { useUserRole } from '@/hooks/useUserRole';
|
||||||
import { toast } from '@/hooks/use-toast';
|
import { toast } from '@/hooks/use-toast';
|
||||||
@@ -20,7 +21,9 @@ export default function OperatorDetail() {
|
|||||||
const { slug } = useParams<{ slug: string }>();
|
const { slug } = useParams<{ slug: string }>();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [operator, setOperator] = useState<Company | null>(null);
|
const [operator, setOperator] = useState<Company | null>(null);
|
||||||
|
const [parks, setParks] = useState<any[]>([]);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
const [parksLoading, setParksLoading] = useState(true);
|
||||||
const [isEditModalOpen, setIsEditModalOpen] = useState(false);
|
const [isEditModalOpen, setIsEditModalOpen] = useState(false);
|
||||||
const { user } = useAuth();
|
const { user } = useAuth();
|
||||||
const { isModerator } = useUserRole();
|
const { isModerator } = useUserRole();
|
||||||
@@ -42,6 +45,11 @@ export default function OperatorDetail() {
|
|||||||
|
|
||||||
if (error) throw error;
|
if (error) throw error;
|
||||||
setOperator(data);
|
setOperator(data);
|
||||||
|
|
||||||
|
// Fetch parks operated by this operator
|
||||||
|
if (data) {
|
||||||
|
fetchParks(data.id);
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching operator:', error);
|
console.error('Error fetching operator:', error);
|
||||||
} finally {
|
} finally {
|
||||||
@@ -49,6 +57,27 @@ export default function OperatorDetail() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const fetchParks = async (operatorId: string) => {
|
||||||
|
try {
|
||||||
|
const { data, error } = await supabase
|
||||||
|
.from('parks')
|
||||||
|
.select(`
|
||||||
|
*,
|
||||||
|
location:locations(*)
|
||||||
|
`)
|
||||||
|
.eq('operator_id', operatorId)
|
||||||
|
.order('name')
|
||||||
|
.limit(6);
|
||||||
|
|
||||||
|
if (error) throw error;
|
||||||
|
setParks(data || []);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Error fetching parks:', error);
|
||||||
|
} finally {
|
||||||
|
setParksLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
const handleEditSubmit = async (data: any) => {
|
const handleEditSubmit = async (data: any) => {
|
||||||
try {
|
try {
|
||||||
await submitCompanyUpdate(
|
await submitCompanyUpdate(
|
||||||
@@ -240,8 +269,8 @@ export default function OperatorDetail() {
|
|||||||
<TabsContent value="parks">
|
<TabsContent value="parks">
|
||||||
<Card>
|
<Card>
|
||||||
<CardContent className="p-6">
|
<CardContent className="p-6">
|
||||||
<div className="flex items-center justify-between mb-4">
|
<div className="flex items-center justify-between mb-6">
|
||||||
<h2 className="text-2xl font-bold">Parks</h2>
|
<h2 className="text-2xl font-bold">Parks Operated</h2>
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
onClick={() => navigate(`/operators/${operator.slug}/parks`)}
|
onClick={() => navigate(`/operators/${operator.slug}/parks`)}
|
||||||
@@ -249,9 +278,25 @@ export default function OperatorDetail() {
|
|||||||
View All Parks
|
View All Parks
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
<p className="text-muted-foreground">
|
|
||||||
View all parks operated by {operator.name}
|
{parksLoading ? (
|
||||||
</p>
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||||
|
{[1, 2, 3].map((i) => (
|
||||||
|
<div key={i} className="h-64 bg-muted rounded-lg animate-pulse" />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : parks.length > 0 ? (
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||||
|
{parks.map((park) => (
|
||||||
|
<ParkCard key={park.id} park={park} />
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="text-center py-12 text-muted-foreground">
|
||||||
|
<FerrisWheel className="w-12 h-12 mx-auto mb-4 opacity-50" />
|
||||||
|
<p>No parks found for {operator.name}</p>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</TabsContent>
|
</TabsContent>
|
||||||
|
|||||||
Reference in New Issue
Block a user