From 7c5e698bf8dd401fbe5b921270dab37d31aaae83 Mon Sep 17 00:00:00 2001 From: Vula Builder Date: Mon, 3 Aug 2026 11:42:10 +0000 Subject: [PATCH] Deploy --- .../sections/BusinessHoursSection.tsx | 76 +++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 src/components/sections/BusinessHoursSection.tsx diff --git a/src/components/sections/BusinessHoursSection.tsx b/src/components/sections/BusinessHoursSection.tsx new file mode 100644 index 0000000..f80931b --- /dev/null +++ b/src/components/sections/BusinessHoursSection.tsx @@ -0,0 +1,76 @@ +'use client' +import { useVulaContent } from '@/hooks/useVulaContent' +import Badge from '@/components/ui/Badge' + +const DAYS = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] + +function parseTime(value?: string): number | null { + if (!value) return null + const parts = value.split(':') + const hours = Number(parts[0]) + const minutes = parts[1] ? Number(parts[1]) : 0 + if (Number.isNaN(hours) || Number.isNaN(minutes)) return null + return hours * 60 + minutes +} + +function isOpenNow(d: { day_of_week?: string; open_time?: string; close_time?: string; is_closed?: boolean }) { + if (String(d.is_closed).toLowerCase() === 'true') return false + const now = new Date() + if (String(d.day_of_week ?? '').toLowerCase() !== DAYS[now.getDay()].toLowerCase()) return false + const current = now.getHours() * 60 + now.getMinutes() + const open = parseTime(d.open_time) + const close = parseTime(d.close_time) + if (open === null || close === null) return false + return current >= open && current < close +} + +export default function BusinessHoursSection() { + const { items = [], loading } = useVulaContent('business_hours') + + if (loading) return
+ if (items.length === 0) return null + + const weekOrder = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] + const sortedItems = [...items].sort((a, b) => { + const da = (a.data as { day_of_week?: string }).day_of_week ?? '' + const db = (b.data as { day_of_week?: string }).day_of_week ?? '' + return weekOrder.indexOf(da) - weekOrder.indexOf(db) + }) + + return ( +
+
+
+

Fourways, Johannesburg

+

Our week at Zama Salon

+

Walk-ins welcome, but booking ahead saves your chair.

+
+
+ {sortedItems.map((item) => { + const d = item.data as { day_of_week?: string; open_time?: string; close_time?: string; is_closed?: boolean; note?: string } + const closed = String(d.is_closed).toLowerCase() === 'true' + const open = isOpenNow(d) + const hours = closed ? 'Closed' : `${d.open_time} – ${d.close_time}` + + return ( +
+
+ {d.day_of_week} + {hours} +
+ {open && ( + Open now + )} +
+ ) + })} +
+
+
+ ) +} \ No newline at end of file