From 0f2df7fd609efa43b29a4ef5dabe507d336a6b07 Mon Sep 17 00:00:00 2001 From: Vula Builder Date: Sun, 26 Jul 2026 16:56:19 +0000 Subject: [PATCH] Deploy --- src/app/rooms/page.tsx | 80 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 src/app/rooms/page.tsx diff --git a/src/app/rooms/page.tsx b/src/app/rooms/page.tsx new file mode 100644 index 0000000..fe18348 --- /dev/null +++ b/src/app/rooms/page.tsx @@ -0,0 +1,80 @@ +'use client' +import { useState, useEffect } from 'react' +import { useMedusaProducts } from '@/hooks/useMedusaProducts' +import Image from 'next/image' +import Link from 'next/link' +import { BedDouble } from 'lucide-react' + +const CURRENCY_SYMBOLS: Record = { zar: 'R', usd: '$', eur: '€', gbp: '£', kes: 'KSh', ngn: '₦', ghs: '₵' } +const formatPrice = (amount: number, code?: string) => { + const sym = CURRENCY_SYMBOLS[(code ?? '').toLowerCase()] ?? (code?.toUpperCase() ?? '') + return `${sym}${(amount / 100).toFixed(0)}` +} + +interface Category { id: string; name: string } + +export default function RoomsPage() { + const { products: rooms, loading, error } = useMedusaProducts(50) + const [categories, setCategories] = useState([]) + const [activeCategory, setActiveCategory] = useState(null) + + useEffect(() => { + fetch('/api/medusa/store/product-categories?limit=20', { + headers: { 'x-publishable-api-key': process.env.NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY || '' }, + }) + .then(r => r.json()) + .then(d => setCategories(d.product_categories || [])) + .catch(() => {}) + }, []) + + const filtered = activeCategory + ? rooms.filter(r => (r as any).categories?.some((c: any) => c.id === activeCategory)) + : rooms + + if (loading) return
+ if (error) return

Failed to load rooms.

+ + return ( +
+
+

Our Rooms

+ {categories.length > 0 && ( +
+ + {categories.map(cat => ( + + ))} +
+ )} + {filtered.length === 0 ? ( +
+ +

No rooms available.

+
+ ) : ( +
+ {filtered.map((room) => { + const variant = room.variants?.[0] + const price = variant?.prices?.[0] + return ( +
+ {room.thumbnail && ( +
+ {room.title} +
+ )} +
+

{room.title}

+ {room.description &&

{room.description}

} + {price &&

{formatPrice(price.amount, price.currency_code)}/night

} + Book This Room +
+
+ ) + })} +
+ )} +
+
+ ) +}