mirror of
https://github.com/pacnpal/thrilltrack-explorer.git
synced 2025-12-23 17:51:13 -05:00
feat: Create reusable ManufacturerCard component
This commit is contained in:
115
src/components/manufacturers/ManufacturerCard.tsx
Normal file
115
src/components/manufacturers/ManufacturerCard.tsx
Normal file
@@ -0,0 +1,115 @@
|
||||
import { Factory, MapPin, Star, Globe, FerrisWheel, Ruler, Hammer, Building2 } from 'lucide-react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Company } from '@/types/database';
|
||||
|
||||
interface ManufacturerCardProps {
|
||||
company: Company;
|
||||
}
|
||||
|
||||
export function ManufacturerCard({ company }: ManufacturerCardProps) {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const handleClick = () => {
|
||||
navigate(`/manufacturers/${company.slug}/`);
|
||||
};
|
||||
|
||||
const getCompanyIcon = (type: string) => {
|
||||
switch (type) {
|
||||
case 'manufacturer': return <Factory className="w-5 h-5" />;
|
||||
case 'operator': return <FerrisWheel className="w-5 h-5" />;
|
||||
case 'designer': return <Ruler className="w-5 h-5" />;
|
||||
case 'contractor': return <Hammer className="w-5 h-5" />;
|
||||
default: return <Building2 className="w-5 h-5" />;
|
||||
}
|
||||
};
|
||||
|
||||
const formatCompanyType = (type: string) => {
|
||||
return type.split('_').map(word =>
|
||||
word.charAt(0).toUpperCase() + word.slice(1)
|
||||
).join(' ');
|
||||
};
|
||||
|
||||
return (
|
||||
<Card
|
||||
className="group overflow-hidden border-border/50 bg-gradient-to-br from-card via-card to-card/80 hover:shadow-2xl hover:shadow-primary/20 transition-all duration-300 cursor-pointer hover:scale-[1.02]"
|
||||
onClick={handleClick}
|
||||
>
|
||||
<CardHeader className="pb-3">
|
||||
<div className="flex items-start justify-between">
|
||||
<div className="flex-1">
|
||||
<div className="flex items-center gap-2 mb-2">
|
||||
<Badge variant="outline" className="text-xs">
|
||||
{formatCompanyType(company.company_type)}
|
||||
</Badge>
|
||||
</div>
|
||||
<CardTitle className="text-lg group-hover:text-primary transition-colors line-clamp-2">
|
||||
{company.name}
|
||||
</CardTitle>
|
||||
</div>
|
||||
{company.logo_url && (
|
||||
<div className="w-12 h-12 bg-muted rounded-lg overflow-hidden flex-shrink-0">
|
||||
<img
|
||||
src={company.logo_url}
|
||||
alt={`${company.name} logo`}
|
||||
className="w-full h-full object-cover"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</CardHeader>
|
||||
|
||||
<CardContent className="space-y-3">
|
||||
{company.description && (
|
||||
<p className="text-sm text-muted-foreground line-clamp-3">
|
||||
{company.description}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div className="space-y-2 text-sm">
|
||||
{company.founded_year && (
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-muted-foreground">Founded:</span>
|
||||
<span className="font-medium">{company.founded_year}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{company.headquarters_location && (
|
||||
<div className="flex items-center gap-2">
|
||||
<MapPin className="w-3 h-3 text-muted-foreground" />
|
||||
<span className="text-muted-foreground text-xs">
|
||||
{company.headquarters_location}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Ratings Display */}
|
||||
{company.average_rating > 0 && (
|
||||
<div className="flex items-center gap-1">
|
||||
<Star className="w-3 h-3 fill-yellow-400 text-yellow-400" />
|
||||
<span className="text-sm font-medium">{company.average_rating.toFixed(1)}</span>
|
||||
<span className="text-xs text-muted-foreground">({company.review_count})</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{company.website_url && (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="w-full"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
window.open(company.website_url, '_blank');
|
||||
}}
|
||||
>
|
||||
<Globe className="w-4 h-4 mr-2" />
|
||||
Visit Website
|
||||
</Button>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
}
|
||||
@@ -1,14 +1,12 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { Header } from '@/components/layout/Header';
|
||||
import { Card, CardContent, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Search, Filter, SlidersHorizontal, Globe, MapPin, Factory, FerrisWheel, Ruler, Hammer, Building2 } from 'lucide-react';
|
||||
import { Search, Filter, SlidersHorizontal, Factory } from 'lucide-react';
|
||||
import { Company } from '@/types/database';
|
||||
import { supabase } from '@/integrations/supabase/client';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { ManufacturerCard } from '@/components/manufacturers/ManufacturerCard';
|
||||
|
||||
export default function Manufacturers() {
|
||||
const [companies, setCompanies] = useState<Company[]>([]);
|
||||
@@ -16,7 +14,6 @@ export default function Manufacturers() {
|
||||
const [searchQuery, setSearchQuery] = useState('');
|
||||
const [sortBy, setSortBy] = useState('name');
|
||||
const [filterType, setFilterType] = useState('all');
|
||||
const navigate = useNavigate();
|
||||
|
||||
useEffect(() => {
|
||||
fetchCompanies();
|
||||
@@ -57,21 +54,6 @@ export default function Manufacturers() {
|
||||
company.description?.toLowerCase().includes(searchQuery.toLowerCase())
|
||||
);
|
||||
|
||||
const getCompanyIcon = (type: string) => {
|
||||
switch (type) {
|
||||
case 'manufacturer': return <Factory className="w-5 h-5" />;
|
||||
case 'operator': return <FerrisWheel className="w-5 h-5" />;
|
||||
case 'designer': return <Ruler className="w-5 h-5" />;
|
||||
case 'contractor': return <Hammer className="w-5 h-5" />;
|
||||
default: return <Building2 className="w-5 h-5" />;
|
||||
}
|
||||
};
|
||||
|
||||
const formatCompanyType = (type: string) => {
|
||||
return type.split('_').map(word =>
|
||||
word.charAt(0).toUpperCase() + word.slice(1)
|
||||
).join(' ');
|
||||
};
|
||||
|
||||
const companyTypes = [
|
||||
{ value: 'all', label: 'All Types' },
|
||||
@@ -164,76 +146,7 @@ export default function Manufacturers() {
|
||||
{filteredCompanies.length > 0 ? (
|
||||
<div className="grid md:grid-cols-2 lg:grid-cols-3 xl:grid-cols-4 gap-6">
|
||||
{filteredCompanies.map((company) => (
|
||||
<Card
|
||||
key={company.id}
|
||||
className="group overflow-hidden border-border/50 bg-gradient-to-br from-card via-card to-card/80 hover:shadow-2xl hover:shadow-primary/20 transition-all duration-300 cursor-pointer hover:scale-[1.02]"
|
||||
>
|
||||
<CardHeader className="pb-3">
|
||||
<div className="flex items-start justify-between">
|
||||
<div className="flex-1">
|
||||
<div className="flex items-center gap-2 mb-2">
|
||||
<span className="flex items-center">{getCompanyIcon(company.company_type)}</span>
|
||||
<Badge variant="outline" className="text-xs">
|
||||
{formatCompanyType(company.company_type)}
|
||||
</Badge>
|
||||
</div>
|
||||
<CardTitle className="text-lg group-hover:text-primary transition-colors line-clamp-2">
|
||||
{company.name}
|
||||
</CardTitle>
|
||||
</div>
|
||||
{company.logo_url && (
|
||||
<div className="w-12 h-12 bg-muted rounded-lg overflow-hidden flex-shrink-0">
|
||||
<img
|
||||
src={company.logo_url}
|
||||
alt={`${company.name} logo`}
|
||||
className="w-full h-full object-cover"
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</CardHeader>
|
||||
|
||||
<CardContent className="space-y-3">
|
||||
{company.description && (
|
||||
<p className="text-sm text-muted-foreground line-clamp-3">
|
||||
{company.description}
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div className="space-y-2 text-sm">
|
||||
{company.founded_year && (
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="text-muted-foreground">Founded:</span>
|
||||
<span className="font-medium">{company.founded_year}</span>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{company.headquarters_location && (
|
||||
<div className="flex items-center gap-2">
|
||||
<MapPin className="w-3 h-3 text-muted-foreground" />
|
||||
<span className="text-muted-foreground text-xs">
|
||||
{company.headquarters_location}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{company.website_url && (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
className="w-full"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
window.open(company.website_url, '_blank');
|
||||
}}
|
||||
>
|
||||
<Globe className="w-4 h-4 mr-2" />
|
||||
Visit Website
|
||||
</Button>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
<ManufacturerCard key={company.id} company={company} />
|
||||
))}
|
||||
</div>
|
||||
) : (
|
||||
|
||||
Reference in New Issue
Block a user