Spaces:
Build error
Build error
File size: 14,768 Bytes
a1a9b91 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 |
import { useEffect, useState } from 'react';
import { useParams, Link } from 'react-router-dom';
import { getVehicleById, Vehicle } from '@/data/vehicles';
import { ArrowLeft, Battery, Clock, Users, Zap, Check, Calendar, CreditCard } from 'lucide-react';
const VehicleDetailPage = () => {
const { id } = useParams<{ id: string }>();
const [vehicle, setVehicle] = useState<Vehicle | null>(null);
const [activeTab, setActiveTab] = useState<'overview' | 'specs' | 'features'>('overview');
const [rentalDuration, setRentalDuration] = useState(1); // days
const [isLoading, setIsLoading] = useState(true);
useEffect(() => {
if (id) {
const foundVehicle = getVehicleById(id);
setVehicle(foundVehicle || null);
setIsLoading(false);
}
}, [id]);
if (isLoading) {
return (
<div className="bg-[#0a0a0a] text-white min-h-screen flex items-center justify-center">
<div className="animate-spin rounded-full h-12 w-12 border-t-2 border-b-2 border-blue-500"></div>
</div>
);
}
if (!vehicle) {
return (
<div className="bg-[#0a0a0a] text-white min-h-screen">
<div className="container mx-auto px-4 py-12 text-center">
<h2 className="text-2xl font-bold mb-4">Vehicle Not Found</h2>
<p className="text-gray-400 mb-6">Sorry, we couldn't find the vehicle you're looking for.</p>
<Link
to="/vehicles"
className="bg-blue-600 hover:bg-blue-700 px-5 py-2.5 rounded-md inline-flex items-center gap-2"
>
<ArrowLeft size={16} />
Back to Vehicles
</Link>
</div>
</div>
);
}
const totalRentalPrice = vehicle.price * rentalDuration;
return (
<div className="bg-[#0a0a0a] text-white min-h-screen">
<div className="container mx-auto px-4 py-12">
{/* Back navigation */}
<Link
to="/vehicles"
className="inline-flex items-center gap-2 text-gray-300 hover:text-white mb-8"
>
<ArrowLeft size={16} />
Back to Vehicles
</Link>
<div className="grid grid-cols-1 lg:grid-cols-2 gap-10">
{/* Left Column - Image */}
<div>
<div className="bg-gradient-to-br from-[#15151a] to-[#0c0c10] p-8 rounded-lg h-full flex items-center justify-center">
<img
src={vehicle.image}
alt={`${vehicle.name} ${vehicle.model}`}
className="w-full h-auto max-h-[400px] object-contain"
/>
</div>
</div>
{/* Right Column - Info */}
<div>
<div className="mb-6">
<div className="flex items-start justify-between">
<div>
<h1 className="text-3xl md:text-4xl font-bold">
{vehicle.name} {vehicle.model}
</h1>
<div className="flex items-center gap-2 mt-2">
<span className="inline-block px-2.5 py-1 bg-blue-600 text-xs font-semibold rounded-full">
{vehicle.category}
</span>
<span className="text-gray-400">Electric</span>
</div>
</div>
<div className="text-right">
<div className="text-3xl font-bold">${vehicle.price}</div>
<div className="text-gray-400 text-sm">per day</div>
</div>
</div>
<p className="text-gray-300 mt-4">{vehicle.description}</p>
</div>
{/* Tabs */}
<div className="border-b border-gray-800 mb-6">
<nav className="flex gap-6">
<button
onClick={() => setActiveTab('overview')}
className={`pb-3 px-1 relative ${
activeTab === 'overview'
? 'text-blue-500 font-medium after:absolute after:h-0.5 after:w-full after:bg-blue-500 after:bottom-0 after:left-0'
: 'text-gray-400 hover:text-white'
}`}
>
Overview
</button>
<button
onClick={() => setActiveTab('specs')}
className={`pb-3 px-1 relative ${
activeTab === 'specs'
? 'text-blue-500 font-medium after:absolute after:h-0.5 after:w-full after:bg-blue-500 after:bottom-0 after:left-0'
: 'text-gray-400 hover:text-white'
}`}
>
Specifications
</button>
<button
onClick={() => setActiveTab('features')}
className={`pb-3 px-1 relative ${
activeTab === 'features'
? 'text-blue-500 font-medium after:absolute after:h-0.5 after:w-full after:bg-blue-500 after:bottom-0 after:left-0'
: 'text-gray-400 hover:text-white'
}`}
>
Features
</button>
</nav>
</div>
{/* Tab Content */}
<div className="mb-8">
{activeTab === 'overview' && (
<div>
<div className="grid grid-cols-2 gap-4 mb-6">
<div className="bg-[#15151a] p-4 rounded-lg flex items-center gap-3">
<div className="bg-blue-600/20 p-2 rounded">
<Battery className="text-blue-500 w-5 h-5" />
</div>
<div>
<div className="text-sm text-gray-400">Range</div>
<div className="font-medium">{vehicle.specs.range}</div>
</div>
</div>
<div className="bg-[#15151a] p-4 rounded-lg flex items-center gap-3">
<div className="bg-blue-600/20 p-2 rounded">
<Zap className="text-blue-500 w-5 h-5" />
</div>
<div>
<div className="text-sm text-gray-400">Acceleration</div>
<div className="font-medium">{vehicle.specs.acceleration}</div>
</div>
</div>
<div className="bg-[#15151a] p-4 rounded-lg flex items-center gap-3">
<div className="bg-blue-600/20 p-2 rounded">
<Clock className="text-blue-500 w-5 h-5" />
</div>
<div>
<div className="text-sm text-gray-400">Top Speed</div>
<div className="font-medium">{vehicle.specs.topSpeed}</div>
</div>
</div>
<div className="bg-[#15151a] p-4 rounded-lg flex items-center gap-3">
<div className="bg-blue-600/20 p-2 rounded">
<Users className="text-blue-500 w-5 h-5" />
</div>
<div>
<div className="text-sm text-gray-400">Capacity</div>
<div className="font-medium">{vehicle.specs.capacity}</div>
</div>
</div>
</div>
<div className="mb-6">
<h3 className="text-lg font-medium mb-2">Rental Options</h3>
<div className="flex gap-4 mb-4">
<button
onClick={() => setRentalDuration(1)}
className={`flex-1 py-3 rounded-md transition-colors ${
rentalDuration === 1
? 'bg-blue-600 text-white'
: 'bg-[#15151a] text-gray-300 hover:bg-gray-800'
}`}
>
1 Day
</button>
<button
onClick={() => setRentalDuration(3)}
className={`flex-1 py-3 rounded-md transition-colors ${
rentalDuration === 3
? 'bg-blue-600 text-white'
: 'bg-[#15151a] text-gray-300 hover:bg-gray-800'
}`}
>
3 Days
</button>
<button
onClick={() => setRentalDuration(7)}
className={`flex-1 py-3 rounded-md transition-colors ${
rentalDuration === 7
? 'bg-blue-600 text-white'
: 'bg-[#15151a] text-gray-300 hover:bg-gray-800'
}`}
>
7 Days
</button>
</div>
</div>
<div className="bg-[#15151a] p-5 rounded-lg mb-6">
<div className="flex justify-between mb-3">
<span className="text-gray-300">${vehicle.price} × {rentalDuration} day{rentalDuration > 1 ? 's' : ''}</span>
<span>${totalRentalPrice}</span>
</div>
<div className="flex justify-between mb-3">
<span className="text-gray-300">Insurance</span>
<span>Included</span>
</div>
<div className="flex justify-between mb-3">
<span className="text-gray-300">Charging</span>
<span>Included</span>
</div>
<div className="border-t border-gray-800 pt-3 mt-3 flex justify-between font-bold">
<span>Total</span>
<span>${totalRentalPrice}</span>
</div>
</div>
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
<button className="bg-blue-600 hover:bg-blue-700 p-4 rounded-md font-medium transition-colors flex items-center justify-center gap-2">
<Calendar size={18} />
Rent Now
</button>
<button className="bg-gray-800 hover:bg-gray-700 p-4 rounded-md font-medium transition-colors flex items-center justify-center gap-2">
<CreditCard size={18} />
Subscribe for ${vehicle.pricePerMonth}/mo
</button>
</div>
</div>
)}
{activeTab === 'specs' && (
<div>
<div className="bg-[#15151a] rounded-lg overflow-hidden">
<div className="grid grid-cols-1 md:grid-cols-2">
<div className="p-4 border-b md:border-b-0 md:border-r border-gray-800">
<h3 className="font-medium mb-3">Performance</h3>
<div className="space-y-3">
<div className="flex justify-between">
<span className="text-gray-400">Range</span>
<span>{vehicle.specs.range}</span>
</div>
<div className="flex justify-between">
<span className="text-gray-400">Top Speed</span>
<span>{vehicle.specs.topSpeed}</span>
</div>
<div className="flex justify-between">
<span className="text-gray-400">Acceleration</span>
<span>{vehicle.specs.acceleration}</span>
</div>
</div>
</div>
<div className="p-4">
<h3 className="font-medium mb-3">Interior</h3>
<div className="space-y-3">
<div className="flex justify-between">
<span className="text-gray-400">Seating</span>
<span>{vehicle.specs.capacity}</span>
</div>
<div className="flex justify-between">
<span className="text-gray-400">Touchscreen</span>
<span>15" Center Display</span>
</div>
<div className="flex justify-between">
<span className="text-gray-400">Sound System</span>
<span>Premium Audio</span>
</div>
</div>
</div>
</div>
<div className="border-t border-gray-800">
<div className="p-4">
<h3 className="font-medium mb-3">Technology</h3>
<div className="space-y-3">
<div className="flex justify-between">
<span className="text-gray-400">Autopilot</span>
<span>Included</span>
</div>
<div className="flex justify-between">
<span className="text-gray-400">Over-the-air Updates</span>
<span>Yes</span>
</div>
<div className="flex justify-between">
<span className="text-gray-400">Connectivity</span>
<span>Premium Connectivity</span>
</div>
</div>
</div>
</div>
</div>
</div>
)}
{activeTab === 'features' && (
<div>
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
{vehicle.features.map((feature, index) => (
<div key={index} className="flex items-center gap-2">
<div className="flex-shrink-0 w-5 h-5 rounded-full bg-green-600/20 flex items-center justify-center">
<Check className="text-green-500 w-3 h-3" />
</div>
<span>{feature}</span>
</div>
))}
</div>
</div>
)}
</div>
</div>
</div>
</div>
</div>
);
};
export default VehicleDetailPage;
|