fix business hours

This commit is contained in:
goro 2026-06-27 18:42:17 +03:00
parent 2bc0a29a0a
commit f1bf0ca0b5
4 changed files with 44 additions and 33 deletions

View File

@ -1,7 +1,7 @@
interface DaySchedule {
day: 'Sunday' | 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday';
open: string; // e.g. "7.00 AM"
close: string; // e.g. "21.00 PM"
open?: string;
close?: string;
closed?: boolean;
}
@ -21,7 +21,7 @@ function getCurrentDay(): DaySchedule['day'] {
function isOpenNow(schedules: DaySchedule[]): boolean {
const today = getCurrentDay();
const todaySchedule = schedules.find((s) => s.day === today);
if (!todaySchedule || todaySchedule.closed) return false;
if (!todaySchedule || todaySchedule.closed || !todaySchedule.open || !todaySchedule.close) return false;
const now = new Date();
const [openHour, openMin] = todaySchedule.open.replace(/[^0-9.]/g, '').split('.').map(Number);
@ -55,6 +55,9 @@ export function ScheduleCard({ schedules, onSuggestEdit }: ScheduleCardProps) {
{/* <hr className="border-[#38444d] mb-4 mt-2" /> */}
{schedules.length === 0 ? (
<p className="text-sm text-tertiary italic">No data yet</p>
) : (
<div className="flex flex-col gap-1">
{DAYS.map((day) => {
const schedule = schedules.find((s) => s.day === day);
@ -75,6 +78,7 @@ export function ScheduleCard({ schedules, onSuggestEdit }: ScheduleCardProps) {
);
})}
</div>
)}
</div>
);
}

View File

@ -4,6 +4,7 @@
"id": 1,
"name": "Warung Sate Kambing",
"thumbnail": "https://fatahilaharis.files.wordpress.com/2017/07/wp-1499292117215.jpeg",
"location_type": "culinary",
"location": "Bandung",
"critic_rating": 78,
"visited": 48,
@ -15,6 +16,7 @@
"id": 2,
"name": "Pantai Balekambang",
"thumbnail": "https://www.nativeindonesia.com/foto/pantai-balekambang/Lokasi-Pura-Yang-Berada-Di-Atas-Pulau-Karang.jpg",
"location_type": "culinary",
"location": "Malang",
"critic_rating": 82,
"visited": 48,
@ -26,6 +28,7 @@
"id": 3,
"name": "Bebek Sinjay",
"thumbnail": "https://i0.wp.com/harga.web.id/wp-content/uploads/bebek-sinjay-surabaya-1.jpg?resize=680%2C300&ssl=1",
"location_type": "culinary",
"location": "Surabaya",
"critic_rating": 70,
"visited": 48,
@ -37,6 +40,7 @@
"id": 4,
"name": "Taman Pelangi",
"thumbnail": "https://tempat.org/wp-content/uploads/2016/11/57488321_255018015317182_1189210435487115990_n.jpg",
"location_type": "culinary",
"location": "Surabaya",
"critic_rating": 75,
"visited": 48,
@ -47,6 +51,7 @@
{
"id": 5,
"thumbnail": "https://ak-d.tripcdn.com/images/1i61t22348mz2uz9cB9FF.jpg?proc=source/trip",
"location_type": "culinary",
"name": "Ragunan Zoo",
"location": "Jakarta",
"critic_rating": 88,
@ -59,6 +64,7 @@
"id": 6,
"name": "Sate Lilit Bali",
"thumbnail": "https://lh3.googleusercontent.com/p/AF1QipNX3DCZxF8MOuyptvxPGfTT4-KNw0BTEqYqeled=s680-w680-h510",
"location_type": "culinary",
"location": "Denpasar",
"critic_rating": 83,
"visited": 48,

View File

@ -451,15 +451,7 @@ function LocationDetail() {
</div>
<div className="w-full md:w-[320px] flex-shrink-0">
<ScheduleCard
schedules={[
{ day: 'Sunday', open: '7.00 AM', close: '21.00 PM' },
{ day: 'Monday', open: '7.00 AM', close: '21.00 PM' },
{ day: 'Tuesday', open: '7.00 AM', close: '21.00 PM' },
{ day: 'Wednesday', open: '7.00 AM', close: '21.00 PM' },
{ day: 'Thursday', open: '7.00 AM', close: '21.00 PM' },
{ day: 'Friday', open: '7.00 AM', close: '21.00 PM' },
{ day: 'Saturday', open: '7.00 AM', close: '21.00 PM' },
]}
schedules={locationDetail.detail.business_hours ?? []}
onSuggestEdit={() => console.log('suggest edit')}
/>
</div>

View File

@ -1,6 +1,13 @@
import { NullValueRes } from "../../types/common"
import { SlideImage } from "yet-another-react-lightbox"
export interface BusinessHourEntry {
day: 'Sunday' | 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday';
open?: string;
close?: string;
closed?: boolean;
}
export interface ILocationDetail {
id: number,
name: string,
@ -15,7 +22,8 @@ export interface ILocationDetail {
critic_score: number,
critic_count: number,
user_score: number,
user_count: number
user_count: number,
business_hours: BusinessHourEntry[] | null,
}
export function emptyLocationDetail(): ILocationDetail {
@ -34,6 +42,7 @@ export function emptyLocationDetail(): ILocationDetail {
critic_count: 0,
user_score: 0,
user_count: 0,
business_hours: null,
}
}