New module pages: POS (shift/receipt), Reviews (moderation+QR link), Room Service (live orders+menu), Rental (object CRUD+bookings)
- PosPage: shift timer, product catalog with categories, cart/receipt, cash/terminal payment, shift revenue summary - ReviewsPage: review moderation (approve/reject/reply), public review link + redirect config, NPS/avg rating stats - RoomServicePage: live orders with status pipeline (new→preparing→ready→delivered), menu tab with stop-list support - RentalPage: rental object management (create/edit/delete with icon+color picker), bookings table per object - BookingsPage: "Новая аренда" button in rental tab → 2-step flow (pick object+date → booking form) - App.tsx: routes for /pos, /reviews, /room-service, /rental Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
414
src/pages/PosPage.tsx
Normal file
414
src/pages/PosPage.tsx
Normal file
@@ -0,0 +1,414 @@
|
||||
import { useState, useEffect, useRef } from 'react'
|
||||
import {
|
||||
ShoppingCart, Plus, Minus, Trash2, CreditCard, Banknote, X,
|
||||
Clock, TrendingUp, Receipt, LogIn, LogOut, ChevronRight, CheckCircle2,
|
||||
} from 'lucide-react'
|
||||
import { format } from 'date-fns'
|
||||
import { ru } from 'date-fns/locale'
|
||||
import { cn, formatCurrency } from '../lib/utils'
|
||||
|
||||
// ── Types ─────────────────────────────────────────────────────────────────────
|
||||
|
||||
interface PosProduct {
|
||||
id: string
|
||||
name: string
|
||||
price: number
|
||||
category: string
|
||||
emoji: string
|
||||
}
|
||||
|
||||
interface CartItem {
|
||||
product: PosProduct
|
||||
qty: number
|
||||
}
|
||||
|
||||
interface PosReceipt {
|
||||
id: string
|
||||
items: CartItem[]
|
||||
total: number
|
||||
method: 'cash' | 'terminal'
|
||||
createdAt: Date
|
||||
shiftId: string
|
||||
}
|
||||
|
||||
// ── Mock data ─────────────────────────────────────────────────────────────────
|
||||
|
||||
const CATEGORIES = ['Еда', 'Напитки', 'Услуги', 'Прочее']
|
||||
|
||||
const PRODUCTS: PosProduct[] = [
|
||||
// Еда
|
||||
{ id: 'p1', name: 'Завтрак', price: 650, category: 'Еда', emoji: '🍳' },
|
||||
{ id: 'p2', name: 'Обед', price: 950, category: 'Еда', emoji: '🍽️' },
|
||||
{ id: 'p3', name: 'Ужин', price: 1100, category: 'Еда', emoji: '🍷' },
|
||||
{ id: 'p4', name: 'Бизнес-ланч', price: 750, category: 'Еда', emoji: '🥗' },
|
||||
// Напитки
|
||||
{ id: 'p5', name: 'Вода 0.5л', price: 120, category: 'Напитки', emoji: '💧' },
|
||||
{ id: 'p6', name: 'Кофе эспрессо', price: 180, category: 'Напитки', emoji: '☕' },
|
||||
{ id: 'p7', name: 'Чай', price: 150, category: 'Напитки', emoji: '🍵' },
|
||||
{ id: 'p8', name: 'Сок апельсиновый',price: 250, category: 'Напитки', emoji: '🍊' },
|
||||
{ id: 'p9', name: 'Мини-бар пиво', price: 350, category: 'Напитки', emoji: '🍺' },
|
||||
// Услуги
|
||||
{ id: 'p10', name: 'Трансфер в/из аэропорта', price: 2500, category: 'Услуги', emoji: '🚖' },
|
||||
{ id: 'p11', name: 'Прачечная', price: 800, category: 'Услуги', emoji: '👕' },
|
||||
{ id: 'p12', name: 'Экскурсия', price: 3500, category: 'Услуги', emoji: '🗺️' },
|
||||
{ id: 'p13', name: 'Парковка/день', price: 500, category: 'Услуги', emoji: '🅿️' },
|
||||
{ id: 'p14', name: 'Аренда велосипеда',price: 400, category: 'Услуги', emoji: '🚲' },
|
||||
// Прочее
|
||||
{ id: 'p15', name: 'Зубная щётка', price: 80, category: 'Прочее', emoji: '🪥' },
|
||||
{ id: 'p16', name: 'Тапочки', price: 150, category: 'Прочее', emoji: '🩴' },
|
||||
{ id: 'p17', name: 'Зарядное USB', price: 200, category: 'Прочее', emoji: '🔌' },
|
||||
{ id: 'p18', name: 'Сувенир', price: 450, category: 'Прочее', emoji: '🎁' },
|
||||
]
|
||||
|
||||
const SEED_RECEIPTS: PosReceipt[] = [
|
||||
{
|
||||
id: 'rc1',
|
||||
items: [
|
||||
{ product: PRODUCTS[0], qty: 2 },
|
||||
{ product: PRODUCTS[5], qty: 2 },
|
||||
],
|
||||
total: 1660,
|
||||
method: 'terminal',
|
||||
createdAt: new Date(Date.now() - 3600000 * 2),
|
||||
shiftId: 'shift-today',
|
||||
},
|
||||
{
|
||||
id: 'rc2',
|
||||
items: [{ product: PRODUCTS[9], qty: 1 }],
|
||||
total: 2500,
|
||||
method: 'cash',
|
||||
createdAt: new Date(Date.now() - 3600000),
|
||||
shiftId: 'shift-today',
|
||||
},
|
||||
{
|
||||
id: 'rc3',
|
||||
items: [
|
||||
{ product: PRODUCTS[1], qty: 1 },
|
||||
{ product: PRODUCTS[4], qty: 2 },
|
||||
],
|
||||
total: 1190,
|
||||
method: 'terminal',
|
||||
createdAt: new Date(Date.now() - 1800000),
|
||||
shiftId: 'shift-today',
|
||||
},
|
||||
]
|
||||
|
||||
// ── Component ─────────────────────────────────────────────────────────────────
|
||||
|
||||
export function PosPage() {
|
||||
const [shiftOpen, setShiftOpen] = useState(true)
|
||||
const [shiftStartTime] = useState<Date>(new Date(Date.now() - 3600000 * 3))
|
||||
const [shiftTimer, setShiftTimer] = useState('')
|
||||
const [category, setCategory] = useState('Еда')
|
||||
const [cart, setCart] = useState<CartItem[]>([])
|
||||
const [receipts, setReceipts] = useState<PosReceipt[]>(SEED_RECEIPTS)
|
||||
const [payMethod, setPayMethod] = useState<'cash' | 'terminal'>('terminal')
|
||||
const [lastReceipt, setLastReceipt] = useState<PosReceipt | null>(null)
|
||||
const shiftId = 'shift-today'
|
||||
|
||||
// Shift timer
|
||||
useEffect(() => {
|
||||
if (!shiftOpen) return
|
||||
const tick = () => {
|
||||
const diff = Math.floor((Date.now() - shiftStartTime.getTime()) / 1000)
|
||||
const h = Math.floor(diff / 3600)
|
||||
const m = Math.floor((diff % 3600) / 60)
|
||||
const s = diff % 60
|
||||
setShiftTimer(`${String(h).padStart(2, '0')}:${String(m).padStart(2, '0')}:${String(s).padStart(2, '0')}`)
|
||||
}
|
||||
tick()
|
||||
const id = setInterval(tick, 1000)
|
||||
return () => clearInterval(id)
|
||||
}, [shiftOpen, shiftStartTime])
|
||||
|
||||
const cartTotal = cart.reduce((s, i) => s + i.product.price * i.qty, 0)
|
||||
const shiftReceipts = receipts.filter(r => r.shiftId === shiftId)
|
||||
const shiftRevenue = shiftReceipts.reduce((s, r) => s + r.total, 0)
|
||||
const cashRevenue = shiftReceipts.filter(r => r.method === 'cash').reduce((s, r) => s + r.total, 0)
|
||||
const termRevenue = shiftReceipts.filter(r => r.method === 'terminal').reduce((s, r) => s + r.total, 0)
|
||||
|
||||
const addToCart = (p: PosProduct) => {
|
||||
setCart(prev => {
|
||||
const ex = prev.find(i => i.product.id === p.id)
|
||||
if (ex) return prev.map(i => i.product.id === p.id ? { ...i, qty: i.qty + 1 } : i)
|
||||
return [...prev, { product: p, qty: 1 }]
|
||||
})
|
||||
}
|
||||
|
||||
const changeQty = (id: string, delta: number) => {
|
||||
setCart(prev =>
|
||||
prev.map(i => i.product.id === id ? { ...i, qty: Math.max(1, i.qty + delta) } : i),
|
||||
)
|
||||
}
|
||||
|
||||
const removeItem = (id: string) => setCart(prev => prev.filter(i => i.product.id !== id))
|
||||
|
||||
const handlePay = () => {
|
||||
if (cart.length === 0 || !shiftOpen) return
|
||||
const receipt: PosReceipt = {
|
||||
id: `rc-${Date.now()}`,
|
||||
items: cart,
|
||||
total: cartTotal,
|
||||
method: payMethod,
|
||||
createdAt: new Date(),
|
||||
shiftId,
|
||||
}
|
||||
setReceipts(prev => [receipt, ...prev])
|
||||
setLastReceipt(receipt)
|
||||
setCart([])
|
||||
}
|
||||
|
||||
const filteredProducts = PRODUCTS.filter(p => p.category === category)
|
||||
|
||||
return (
|
||||
<div className="flex h-full flex-col">
|
||||
{/* Top bar */}
|
||||
<div className="shrink-0 px-4 py-3 border-b border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-800">
|
||||
<div className="flex items-center justify-between flex-wrap gap-2">
|
||||
<div>
|
||||
<h1 className="text-lg font-bold text-slate-900 dark:text-slate-100">Касса</h1>
|
||||
<p className="text-xs text-slate-500 dark:text-slate-400">
|
||||
{format(new Date(), 'd MMMM yyyy', { locale: ru })} · Елена Смирнова
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-3">
|
||||
{/* Shift timer */}
|
||||
{shiftOpen && (
|
||||
<div className="flex items-center gap-2 px-3 py-1.5 rounded-xl bg-emerald-50 dark:bg-emerald-900/20 border border-emerald-200 dark:border-emerald-700">
|
||||
<Clock size={13} className="text-emerald-600" />
|
||||
<span className="text-xs font-mono font-semibold text-emerald-700 dark:text-emerald-300">
|
||||
{shiftTimer}
|
||||
</span>
|
||||
</div>
|
||||
)}
|
||||
<button
|
||||
onClick={() => setShiftOpen(v => !v)}
|
||||
className={cn(
|
||||
'flex items-center gap-1.5 px-3 py-1.5 rounded-xl text-sm font-medium border-2 transition-colors',
|
||||
shiftOpen
|
||||
? 'bg-red-50 border-red-300 text-red-700 dark:bg-red-900/20 dark:border-red-700 dark:text-red-300'
|
||||
: 'bg-emerald-50 border-emerald-300 text-emerald-700 dark:bg-emerald-900/20 dark:border-emerald-700 dark:text-emerald-300',
|
||||
)}
|
||||
>
|
||||
{shiftOpen ? <><LogOut size={14} />Закрыть смену</> : <><LogIn size={14} />Открыть смену</>}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Shift stats */}
|
||||
{shiftOpen && (
|
||||
<div className="grid grid-cols-4 gap-2 mt-3">
|
||||
{[
|
||||
{ label: 'Выручка за смену', value: formatCurrency(shiftRevenue), color: 'text-slate-900 dark:text-slate-100' },
|
||||
{ label: 'Наличные', value: formatCurrency(cashRevenue), color: 'text-emerald-600 dark:text-emerald-400' },
|
||||
{ label: 'Терминал', value: formatCurrency(termRevenue), color: 'text-blue-600 dark:text-blue-400' },
|
||||
{ label: 'Чеков', value: shiftReceipts.length, color: 'text-slate-900 dark:text-slate-100' },
|
||||
].map(s => (
|
||||
<div key={s.label} className="rounded-xl bg-slate-50 dark:bg-slate-700/50 px-3 py-2">
|
||||
<p className={cn('text-base font-bold', s.color)}>{s.value}</p>
|
||||
<p className="text-[10px] text-slate-500 dark:text-slate-400">{s.label}</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{!shiftOpen ? (
|
||||
<div className="flex-1 flex items-center justify-center flex-col gap-4 text-slate-400">
|
||||
<ShoppingCart size={56} className="opacity-20" />
|
||||
<div className="text-center">
|
||||
<p className="text-lg font-semibold text-slate-600 dark:text-slate-300">Смена закрыта</p>
|
||||
<p className="text-sm">Откройте смену для начала работы</p>
|
||||
</div>
|
||||
<button
|
||||
onClick={() => setShiftOpen(true)}
|
||||
className="btn-primary"
|
||||
>
|
||||
<LogIn size={15} />
|
||||
Открыть смену
|
||||
</button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex flex-1 overflow-hidden">
|
||||
{/* Left — product catalog */}
|
||||
<div className="flex flex-col flex-1 overflow-hidden border-r border-slate-200 dark:border-slate-700">
|
||||
{/* Category tabs */}
|
||||
<div className="shrink-0 flex gap-1 px-4 py-2.5 border-b border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-800">
|
||||
{CATEGORIES.map(cat => (
|
||||
<button
|
||||
key={cat}
|
||||
onClick={() => setCategory(cat)}
|
||||
className={cn(
|
||||
'px-3 py-1.5 rounded-lg text-sm font-medium transition-colors',
|
||||
category === cat
|
||||
? 'bg-brand-600 text-white'
|
||||
: 'text-slate-600 dark:text-slate-400 hover:bg-slate-100 dark:hover:bg-slate-700',
|
||||
)}
|
||||
>
|
||||
{cat}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
|
||||
{/* Products grid */}
|
||||
<div className="flex-1 overflow-y-auto p-4">
|
||||
<div className="grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-4 gap-3">
|
||||
{filteredProducts.map(p => (
|
||||
<button
|
||||
key={p.id}
|
||||
onClick={() => addToCart(p)}
|
||||
className="card p-3 text-left hover:shadow-md hover:border-brand-300 dark:hover:border-brand-600 transition-all active:scale-95 group"
|
||||
>
|
||||
<span className="text-2xl block mb-1.5">{p.emoji}</span>
|
||||
<p className="text-sm font-medium text-slate-800 dark:text-slate-200 leading-tight">{p.name}</p>
|
||||
<p className="text-sm font-bold text-brand-600 dark:text-brand-400 mt-1">{formatCurrency(p.price)}</p>
|
||||
<div className="mt-1.5 w-full h-7 rounded-lg bg-brand-50 dark:bg-brand-900/20 flex items-center justify-center opacity-0 group-hover:opacity-100 transition-opacity">
|
||||
<Plus size={14} className="text-brand-600" />
|
||||
</div>
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Recent receipts */}
|
||||
<div className="shrink-0 border-t border-slate-200 dark:border-slate-700 bg-slate-50 dark:bg-slate-800/50">
|
||||
<div className="px-4 py-2 flex items-center justify-between">
|
||||
<p className="text-xs font-semibold text-slate-500 uppercase tracking-wide">Последние чеки</p>
|
||||
<span className="text-xs text-slate-400">{shiftReceipts.length} за смену</span>
|
||||
</div>
|
||||
<div className="overflow-x-auto">
|
||||
<div className="flex gap-2 px-4 pb-3" style={{ minWidth: 'max-content' }}>
|
||||
{shiftReceipts.slice(0, 6).map(r => (
|
||||
<div key={r.id} className="flex-shrink-0 w-40 rounded-xl border border-slate-200 dark:border-slate-700 bg-white dark:bg-slate-800 p-2.5">
|
||||
<div className="flex items-center justify-between mb-1">
|
||||
<span className="text-[10px] text-slate-400">{format(r.createdAt, 'HH:mm')}</span>
|
||||
{r.method === 'cash' ? <Banknote size={11} className="text-emerald-600" /> : <CreditCard size={11} className="text-blue-600" />}
|
||||
</div>
|
||||
<p className="text-sm font-bold text-slate-900 dark:text-slate-100">{formatCurrency(r.total)}</p>
|
||||
<p className="text-[10px] text-slate-400">{r.items.length} поз.</p>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Right — cart */}
|
||||
<div className="w-80 flex flex-col bg-white dark:bg-slate-800 shrink-0">
|
||||
<div className="px-4 py-3 border-b border-slate-200 dark:border-slate-700 flex items-center justify-between">
|
||||
<p className="font-semibold text-slate-900 dark:text-slate-100 flex items-center gap-2">
|
||||
<Receipt size={16} />
|
||||
Текущий чек
|
||||
</p>
|
||||
{cart.length > 0 && (
|
||||
<button onClick={() => setCart([])} className="text-xs text-red-500 hover:text-red-700">
|
||||
Очистить
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Cart items */}
|
||||
<div className="flex-1 overflow-y-auto px-4 py-3 space-y-2">
|
||||
{cart.length === 0 ? (
|
||||
<div className="flex flex-col items-center justify-center h-40 text-slate-400 gap-2">
|
||||
<ShoppingCart size={32} className="opacity-20" />
|
||||
<p className="text-sm">Добавьте товары из каталога</p>
|
||||
</div>
|
||||
) : (
|
||||
cart.map(item => (
|
||||
<div key={item.product.id} className="flex items-center gap-2 p-2 rounded-xl bg-slate-50 dark:bg-slate-700/50">
|
||||
<span className="text-lg shrink-0">{item.product.emoji}</span>
|
||||
<div className="flex-1 min-w-0">
|
||||
<p className="text-xs font-medium text-slate-800 dark:text-slate-200 truncate">{item.product.name}</p>
|
||||
<p className="text-xs text-slate-500">{formatCurrency(item.product.price * item.qty)}</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-1 shrink-0">
|
||||
<button onClick={() => changeQty(item.product.id, -1)} className="w-5 h-5 rounded-full bg-slate-200 dark:bg-slate-600 flex items-center justify-center hover:bg-slate-300">
|
||||
<Minus size={10} />
|
||||
</button>
|
||||
<span className="w-5 text-center text-xs font-semibold">{item.qty}</span>
|
||||
<button onClick={() => changeQty(item.product.id, 1)} className="w-5 h-5 rounded-full bg-slate-200 dark:bg-slate-600 flex items-center justify-center hover:bg-slate-300">
|
||||
<Plus size={10} />
|
||||
</button>
|
||||
<button onClick={() => removeItem(item.product.id)} className="w-5 h-5 rounded-full bg-red-100 dark:bg-red-900/30 flex items-center justify-center hover:bg-red-200 ml-1">
|
||||
<Trash2 size={10} className="text-red-600" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Payment */}
|
||||
{cart.length > 0 && (
|
||||
<div className="shrink-0 border-t border-slate-200 dark:border-slate-700 p-4 space-y-3">
|
||||
<div className="flex items-center justify-between">
|
||||
<span className="text-sm text-slate-600 dark:text-slate-400">Итого</span>
|
||||
<span className="text-xl font-bold text-slate-900 dark:text-slate-100">{formatCurrency(cartTotal)}</span>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<button
|
||||
onClick={() => setPayMethod('cash')}
|
||||
className={cn(
|
||||
'flex-1 flex items-center justify-center gap-1.5 py-2 rounded-xl text-sm font-medium border-2 transition-colors',
|
||||
payMethod === 'cash'
|
||||
? 'bg-emerald-600 border-emerald-600 text-white'
|
||||
: 'border-slate-200 dark:border-slate-600 text-slate-700 dark:text-slate-300',
|
||||
)}
|
||||
>
|
||||
<Banknote size={14} />
|
||||
Наличные
|
||||
</button>
|
||||
<button
|
||||
onClick={() => setPayMethod('terminal')}
|
||||
className={cn(
|
||||
'flex-1 flex items-center justify-center gap-1.5 py-2 rounded-xl text-sm font-medium border-2 transition-colors',
|
||||
payMethod === 'terminal'
|
||||
? 'bg-blue-600 border-blue-600 text-white'
|
||||
: 'border-slate-200 dark:border-slate-600 text-slate-700 dark:text-slate-300',
|
||||
)}
|
||||
>
|
||||
<CreditCard size={14} />
|
||||
Терминал
|
||||
</button>
|
||||
</div>
|
||||
<button onClick={handlePay} className="btn-primary w-full justify-center py-3 text-base">
|
||||
<ChevronRight size={18} />
|
||||
Провести оплату
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Receipt success overlay */}
|
||||
{lastReceipt && (
|
||||
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black/50">
|
||||
<div className="bg-white dark:bg-slate-800 rounded-2xl shadow-2xl p-8 w-80 text-center space-y-4">
|
||||
<CheckCircle2 size={56} className="text-emerald-500 mx-auto" />
|
||||
<div>
|
||||
<p className="text-xl font-bold text-slate-900 dark:text-slate-100">Оплата принята</p>
|
||||
<p className="text-3xl font-bold text-emerald-600 mt-1">{formatCurrency(lastReceipt.total)}</p>
|
||||
<p className="text-sm text-slate-500 mt-1">
|
||||
{lastReceipt.method === 'cash' ? 'Наличными' : 'Терминал'} · {format(lastReceipt.createdAt, 'HH:mm')}
|
||||
</p>
|
||||
</div>
|
||||
<div className="text-left bg-slate-50 dark:bg-slate-700/50 rounded-xl p-3 space-y-1">
|
||||
{lastReceipt.items.map(i => (
|
||||
<div key={i.product.id} className="flex justify-between text-sm">
|
||||
<span className="text-slate-600 dark:text-slate-400">{i.product.emoji} {i.product.name} ×{i.qty}</span>
|
||||
<span className="font-medium">{formatCurrency(i.product.price * i.qty)}</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
<button onClick={() => setLastReceipt(null)} className="btn-primary w-full justify-center">
|
||||
Готово
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user