841faca34a
- 新增项目规范文档,包含语言设置和 Git 提交规范 - 更新 .gitignore 文件,添加环境文件和数据目录 - 新增 Prettier 配置文件和忽略文件 - 更新 package.json,添加 prettier 和 prisma 相关依赖 - 新增 API 路由处理佣金和消费数据 这些更改为项目提供了更好的结构和代码风格规范。
60 lines
1.9 KiB
TypeScript
60 lines
1.9 KiB
TypeScript
'use client'
|
|
|
|
import { useEffect, useState } from 'react'
|
|
import { ContextMenu, ContextMenuContent, ContextMenuItem, ContextMenuTrigger } from '@/components/ui/context-menu'
|
|
import type { Reservation } from '@/lib/types'
|
|
|
|
interface ReservationCardProps {
|
|
reservation: Reservation
|
|
onClick: (reservation: Reservation) => void
|
|
onEdit?: (reservation: Reservation) => void
|
|
onDelete?: (reservation: Reservation) => void
|
|
}
|
|
|
|
export function ReservationCard({ reservation, onClick, onEdit, onDelete }: ReservationCardProps) {
|
|
const [waiterName, setWaiterName] = useState('')
|
|
|
|
useEffect(() => {
|
|
fetch(`/api/waiter/${reservation.waiterId}`)
|
|
.then((r) => r.json())
|
|
.then((w) => setWaiterName(w.name || ''))
|
|
.catch(() => {})
|
|
}, [reservation.waiterId])
|
|
|
|
return (
|
|
<ContextMenu>
|
|
<ContextMenuTrigger asChild>
|
|
<button
|
|
onClick={(e) => {
|
|
e.stopPropagation()
|
|
onClick(reservation)
|
|
}}
|
|
className="w-full text-left text-[11px] leading-tight px-1 py-0.5 rounded-sm bg-primary/10 text-primary hover:bg-primary/20 truncate border-l-2 border-primary mb-0.5 cursor-pointer"
|
|
title={`${reservation.customerName} - ${reservation.time}${waiterName ? ` (${waiterName})` : ''}${reservation.package ? ` [${reservation.package}]` : ''}`}
|
|
>
|
|
{reservation.time} {reservation.customerName}
|
|
</button>
|
|
</ContextMenuTrigger>
|
|
<ContextMenuContent className="w-32">
|
|
<ContextMenuItem
|
|
onClick={(e) => {
|
|
e.stopPropagation()
|
|
onEdit?.(reservation)
|
|
}}
|
|
>
|
|
编辑
|
|
</ContextMenuItem>
|
|
<ContextMenuItem
|
|
onClick={(e) => {
|
|
e.stopPropagation()
|
|
onDelete?.(reservation)
|
|
}}
|
|
className="text-destructive focus:text-destructive"
|
|
>
|
|
删除
|
|
</ContextMenuItem>
|
|
</ContextMenuContent>
|
|
</ContextMenu>
|
|
)
|
|
}
|