fix business hours
This commit is contained in:
parent
2bc0a29a0a
commit
f1bf0ca0b5
@ -1,7 +1,7 @@
|
|||||||
interface DaySchedule {
|
interface DaySchedule {
|
||||||
day: 'Sunday' | 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday';
|
day: 'Sunday' | 'Monday' | 'Tuesday' | 'Wednesday' | 'Thursday' | 'Friday' | 'Saturday';
|
||||||
open: string; // e.g. "7.00 AM"
|
open?: string;
|
||||||
close: string; // e.g. "21.00 PM"
|
close?: string;
|
||||||
closed?: boolean;
|
closed?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -21,7 +21,7 @@ function getCurrentDay(): DaySchedule['day'] {
|
|||||||
function isOpenNow(schedules: DaySchedule[]): boolean {
|
function isOpenNow(schedules: DaySchedule[]): boolean {
|
||||||
const today = getCurrentDay();
|
const today = getCurrentDay();
|
||||||
const todaySchedule = schedules.find((s) => s.day === today);
|
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 now = new Date();
|
||||||
const [openHour, openMin] = todaySchedule.open.replace(/[^0-9.]/g, '').split('.').map(Number);
|
const [openHour, openMin] = todaySchedule.open.replace(/[^0-9.]/g, '').split('.').map(Number);
|
||||||
@ -55,26 +55,30 @@ export function ScheduleCard({ schedules, onSuggestEdit }: ScheduleCardProps) {
|
|||||||
|
|
||||||
{/* <hr className="border-[#38444d] mb-4 mt-2" /> */}
|
{/* <hr className="border-[#38444d] mb-4 mt-2" /> */}
|
||||||
|
|
||||||
<div className="flex flex-col gap-1">
|
{schedules.length === 0 ? (
|
||||||
{DAYS.map((day) => {
|
<p className="text-sm text-tertiary italic">No data yet</p>
|
||||||
const schedule = schedules.find((s) => s.day === day);
|
) : (
|
||||||
const isToday = day === today;
|
<div className="flex flex-col gap-1">
|
||||||
|
{DAYS.map((day) => {
|
||||||
|
const schedule = schedules.find((s) => s.day === day);
|
||||||
|
const isToday = day === today;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
key={day}
|
key={day}
|
||||||
className={`flex items-center justify-between text-sm ${isToday ? 'font-bold text-white' : 'text-tertiary'}`}
|
className={`flex items-center justify-between text-sm ${isToday ? 'font-bold text-white' : 'text-tertiary'}`}
|
||||||
>
|
>
|
||||||
<span>{day}</span>
|
<span>{day}</span>
|
||||||
<span>
|
<span>
|
||||||
{!schedule || schedule.closed
|
{!schedule || schedule.closed
|
||||||
? 'Closed'
|
? 'Closed'
|
||||||
: `${schedule.open} - ${schedule.close}`}
|
: `${schedule.open} - ${schedule.close}`}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
</div>
|
</div>
|
||||||
|
)}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
"id": 1,
|
"id": 1,
|
||||||
"name": "Warung Sate Kambing",
|
"name": "Warung Sate Kambing",
|
||||||
"thumbnail": "https://fatahilaharis.files.wordpress.com/2017/07/wp-1499292117215.jpeg",
|
"thumbnail": "https://fatahilaharis.files.wordpress.com/2017/07/wp-1499292117215.jpeg",
|
||||||
|
"location_type": "culinary",
|
||||||
"location": "Bandung",
|
"location": "Bandung",
|
||||||
"critic_rating": 78,
|
"critic_rating": 78,
|
||||||
"visited": 48,
|
"visited": 48,
|
||||||
@ -15,6 +16,7 @@
|
|||||||
"id": 2,
|
"id": 2,
|
||||||
"name": "Pantai Balekambang",
|
"name": "Pantai Balekambang",
|
||||||
"thumbnail": "https://www.nativeindonesia.com/foto/pantai-balekambang/Lokasi-Pura-Yang-Berada-Di-Atas-Pulau-Karang.jpg",
|
"thumbnail": "https://www.nativeindonesia.com/foto/pantai-balekambang/Lokasi-Pura-Yang-Berada-Di-Atas-Pulau-Karang.jpg",
|
||||||
|
"location_type": "culinary",
|
||||||
"location": "Malang",
|
"location": "Malang",
|
||||||
"critic_rating": 82,
|
"critic_rating": 82,
|
||||||
"visited": 48,
|
"visited": 48,
|
||||||
@ -26,6 +28,7 @@
|
|||||||
"id": 3,
|
"id": 3,
|
||||||
"name": "Bebek Sinjay",
|
"name": "Bebek Sinjay",
|
||||||
"thumbnail": "https://i0.wp.com/harga.web.id/wp-content/uploads/bebek-sinjay-surabaya-1.jpg?resize=680%2C300&ssl=1",
|
"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",
|
"location": "Surabaya",
|
||||||
"critic_rating": 70,
|
"critic_rating": 70,
|
||||||
"visited": 48,
|
"visited": 48,
|
||||||
@ -37,6 +40,7 @@
|
|||||||
"id": 4,
|
"id": 4,
|
||||||
"name": "Taman Pelangi",
|
"name": "Taman Pelangi",
|
||||||
"thumbnail": "https://tempat.org/wp-content/uploads/2016/11/57488321_255018015317182_1189210435487115990_n.jpg",
|
"thumbnail": "https://tempat.org/wp-content/uploads/2016/11/57488321_255018015317182_1189210435487115990_n.jpg",
|
||||||
|
"location_type": "culinary",
|
||||||
"location": "Surabaya",
|
"location": "Surabaya",
|
||||||
"critic_rating": 75,
|
"critic_rating": 75,
|
||||||
"visited": 48,
|
"visited": 48,
|
||||||
@ -47,6 +51,7 @@
|
|||||||
{
|
{
|
||||||
"id": 5,
|
"id": 5,
|
||||||
"thumbnail": "https://ak-d.tripcdn.com/images/1i61t22348mz2uz9cB9FF.jpg?proc=source/trip",
|
"thumbnail": "https://ak-d.tripcdn.com/images/1i61t22348mz2uz9cB9FF.jpg?proc=source/trip",
|
||||||
|
"location_type": "culinary",
|
||||||
"name": "Ragunan Zoo",
|
"name": "Ragunan Zoo",
|
||||||
"location": "Jakarta",
|
"location": "Jakarta",
|
||||||
"critic_rating": 88,
|
"critic_rating": 88,
|
||||||
@ -59,6 +64,7 @@
|
|||||||
"id": 6,
|
"id": 6,
|
||||||
"name": "Sate Lilit Bali",
|
"name": "Sate Lilit Bali",
|
||||||
"thumbnail": "https://lh3.googleusercontent.com/p/AF1QipNX3DCZxF8MOuyptvxPGfTT4-KNw0BTEqYqeled=s680-w680-h510",
|
"thumbnail": "https://lh3.googleusercontent.com/p/AF1QipNX3DCZxF8MOuyptvxPGfTT4-KNw0BTEqYqeled=s680-w680-h510",
|
||||||
|
"location_type": "culinary",
|
||||||
"location": "Denpasar",
|
"location": "Denpasar",
|
||||||
"critic_rating": 83,
|
"critic_rating": 83,
|
||||||
"visited": 48,
|
"visited": 48,
|
||||||
|
|||||||
@ -451,15 +451,7 @@ function LocationDetail() {
|
|||||||
</div>
|
</div>
|
||||||
<div className="w-full md:w-[320px] flex-shrink-0">
|
<div className="w-full md:w-[320px] flex-shrink-0">
|
||||||
<ScheduleCard
|
<ScheduleCard
|
||||||
schedules={[
|
schedules={locationDetail.detail.business_hours ?? []}
|
||||||
{ 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' },
|
|
||||||
]}
|
|
||||||
onSuggestEdit={() => console.log('suggest edit')}
|
onSuggestEdit={() => console.log('suggest edit')}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -1,6 +1,13 @@
|
|||||||
import { NullValueRes } from "../../types/common"
|
import { NullValueRes } from "../../types/common"
|
||||||
import { SlideImage } from "yet-another-react-lightbox"
|
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 {
|
export interface ILocationDetail {
|
||||||
id: number,
|
id: number,
|
||||||
name: string,
|
name: string,
|
||||||
@ -15,7 +22,8 @@ export interface ILocationDetail {
|
|||||||
critic_score: number,
|
critic_score: number,
|
||||||
critic_count: number,
|
critic_count: number,
|
||||||
user_score: number,
|
user_score: number,
|
||||||
user_count: number
|
user_count: number,
|
||||||
|
business_hours: BusinessHourEntry[] | null,
|
||||||
}
|
}
|
||||||
|
|
||||||
export function emptyLocationDetail(): ILocationDetail {
|
export function emptyLocationDetail(): ILocationDetail {
|
||||||
@ -34,6 +42,7 @@ export function emptyLocationDetail(): ILocationDetail {
|
|||||||
critic_count: 0,
|
critic_count: 0,
|
||||||
user_score: 0,
|
user_score: 0,
|
||||||
user_count: 0,
|
user_count: 0,
|
||||||
|
business_hours: null,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user