Spaces:
Running
Running
axeronis commited on
Commit ·
c90f5cc
1
Parent(s): bcc0b3b
feat: add Bookings feature (backend API + frontend Calendar/List)
Browse files- backend/app/api/bookings.py +111 -0
- backend/app/main.py +3 -2
- frontend/app/appointments/page.tsx +126 -0
- frontend/components/Sidebar.tsx +11 -1
- frontend/components/bookings/AppointmentsList.tsx +115 -0
- frontend/components/bookings/BookingCalendar.tsx +102 -0
- frontend/lib/api.ts +23 -0
backend/app/api/bookings.py
ADDED
|
@@ -0,0 +1,111 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import APIRouter, Depends, HTTPException, status
|
| 2 |
+
from sqlalchemy.ext.asyncio import AsyncSession
|
| 3 |
+
from typing import List, Optional
|
| 4 |
+
from datetime import datetime, date
|
| 5 |
+
from uuid import UUID
|
| 6 |
+
from sqlmodel import select, col
|
| 7 |
+
|
| 8 |
+
from app.core.database import get_session
|
| 9 |
+
from app.core.logging import get_logger
|
| 10 |
+
from app.api.deps import get_current_user
|
| 11 |
+
from app.models import User
|
| 12 |
+
from app.models.tenant import Tenant
|
| 13 |
+
from app.models.booking import Appointment, AppointmentStatus, Service
|
| 14 |
+
|
| 15 |
+
logger = get_logger(__name__)
|
| 16 |
+
|
| 17 |
+
router = APIRouter(prefix="/bookings", tags=["Bookings"])
|
| 18 |
+
|
| 19 |
+
# -----------------------------------------------------------------------------
|
| 20 |
+
# APPOINTMENTS
|
| 21 |
+
# -----------------------------------------------------------------------------
|
| 22 |
+
|
| 23 |
+
@router.get("/", response_model=List[Appointment])
|
| 24 |
+
async def list_appointments(
|
| 25 |
+
start_date: Optional[date] = None,
|
| 26 |
+
end_date: Optional[date] = None,
|
| 27 |
+
status: Optional[str] = None,
|
| 28 |
+
session: AsyncSession = Depends(get_session),
|
| 29 |
+
current_user: User = Depends(get_current_user)
|
| 30 |
+
):
|
| 31 |
+
"""List appointments for the tenant, optionally filtered by date range."""
|
| 32 |
+
query = select(Appointment).where(Appointment.tenant_id == current_user.tenant_id)
|
| 33 |
+
|
| 34 |
+
if start_date:
|
| 35 |
+
query = query.where(Appointment.start_time >= datetime.combine(start_date, datetime.min.time()))
|
| 36 |
+
if end_date:
|
| 37 |
+
query = query.where(Appointment.start_time <= datetime.combine(end_date, datetime.max.time()))
|
| 38 |
+
if status:
|
| 39 |
+
query = query.where(Appointment.status == status)
|
| 40 |
+
|
| 41 |
+
# Order by start time desc
|
| 42 |
+
query = query.order_by(col(Appointment.start_time).desc())
|
| 43 |
+
|
| 44 |
+
result = await session.exec(query)
|
| 45 |
+
return result.all()
|
| 46 |
+
|
| 47 |
+
@router.post("/", response_model=Appointment)
|
| 48 |
+
async def create_appointment(
|
| 49 |
+
appointment: Appointment,
|
| 50 |
+
session: AsyncSession = Depends(get_session),
|
| 51 |
+
current_user: User = Depends(get_current_user)
|
| 52 |
+
):
|
| 53 |
+
"""Manually create an appointment."""
|
| 54 |
+
# Ensure tenant_id is set
|
| 55 |
+
appointment.tenant_id = current_user.tenant_id
|
| 56 |
+
|
| 57 |
+
# Check if service exists
|
| 58 |
+
service = await session.get(Service, appointment.service_id)
|
| 59 |
+
if not service or service.tenant_id != current_user.tenant_id:
|
| 60 |
+
raise HTTPException(status_code=404, detail="Service not found")
|
| 61 |
+
|
| 62 |
+
session.add(appointment)
|
| 63 |
+
await session.commit()
|
| 64 |
+
await session.refresh(appointment)
|
| 65 |
+
return appointment
|
| 66 |
+
|
| 67 |
+
@router.delete("/{appointment_id}")
|
| 68 |
+
async def cancel_appointment(
|
| 69 |
+
appointment_id: UUID,
|
| 70 |
+
session: AsyncSession = Depends(get_session),
|
| 71 |
+
current_user: User = Depends(get_current_user)
|
| 72 |
+
):
|
| 73 |
+
"""Cancel (delete) an appointment or mark as cancelled."""
|
| 74 |
+
appointment = await session.get(Appointment, appointment_id)
|
| 75 |
+
if not appointment or appointment.tenant_id != current_user.tenant_id:
|
| 76 |
+
raise HTTPException(status_code=404, detail="Appointment not found")
|
| 77 |
+
|
| 78 |
+
# Instead of hard delete, maybe just set status?
|
| 79 |
+
# For now, let's allow soft cancel
|
| 80 |
+
appointment.status = AppointmentStatus.CANCELLED
|
| 81 |
+
session.add(appointment)
|
| 82 |
+
await session.commit()
|
| 83 |
+
return {"ok": True}
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
# -----------------------------------------------------------------------------
|
| 87 |
+
# SERVICES
|
| 88 |
+
# -----------------------------------------------------------------------------
|
| 89 |
+
|
| 90 |
+
@router.get("/services", response_model=List[Service])
|
| 91 |
+
async def list_services(
|
| 92 |
+
session: AsyncSession = Depends(get_session),
|
| 93 |
+
current_user: User = Depends(get_current_user)
|
| 94 |
+
):
|
| 95 |
+
"""List available booking services."""
|
| 96 |
+
query = select(Service).where(Service.tenant_id == current_user.tenant_id)
|
| 97 |
+
result = await session.exec(query)
|
| 98 |
+
return result.all()
|
| 99 |
+
|
| 100 |
+
@router.post("/services", response_model=Service)
|
| 101 |
+
async def create_service(
|
| 102 |
+
service: Service,
|
| 103 |
+
session: AsyncSession = Depends(get_session),
|
| 104 |
+
current_user: User = Depends(get_current_user)
|
| 105 |
+
):
|
| 106 |
+
"""Create or update a booking service."""
|
| 107 |
+
service.tenant_id = current_user.tenant_id
|
| 108 |
+
session.add(service)
|
| 109 |
+
await session.commit()
|
| 110 |
+
await session.refresh(service)
|
| 111 |
+
return service
|
backend/app/main.py
CHANGED
|
@@ -7,7 +7,7 @@ from app.core.config import settings
|
|
| 7 |
from app.core.database import init_pgvector
|
| 8 |
from app.core.logging import configure_logging, get_logger
|
| 9 |
from app.middleware.request_id import RequestIDMiddleware
|
| 10 |
-
from app.api import webhook, leads, knowledge, channels, auth, tenants, analytics, chats, playbook, billing, ai_training, crm, admin, team, evolution_webhook, telegram_webhook, partners, notifications, products
|
| 11 |
import asyncio
|
| 12 |
import sys
|
| 13 |
from slowapi import Limiter, _rate_limit_exceeded_handler
|
|
@@ -182,7 +182,8 @@ app.include_router(admin.router, prefix="/api/v1") # Admin Panel (superuser onl
|
|
| 182 |
app.include_router(partners.router, prefix="/api/v1") # Partner Dashboard
|
| 183 |
app.include_router(team.router, prefix="/api/v1") # Team Management (owner only)
|
| 184 |
app.include_router(notifications.router, prefix="/api/v1") # HOT Lead Notifications
|
| 185 |
-
app.include_router(products.router, prefix="/api/v1")
|
|
|
|
| 186 |
# app.include_router(oauth.router, prefix="/api/v1") # OAuth removed
|
| 187 |
|
| 188 |
|
|
|
|
| 7 |
from app.core.database import init_pgvector
|
| 8 |
from app.core.logging import configure_logging, get_logger
|
| 9 |
from app.middleware.request_id import RequestIDMiddleware
|
| 10 |
+
from app.api import webhook, leads, knowledge, channels, auth, tenants, analytics, chats, playbook, billing, ai_training, crm, admin, team, evolution_webhook, telegram_webhook, partners, notifications, products, bookings
|
| 11 |
import asyncio
|
| 12 |
import sys
|
| 13 |
from slowapi import Limiter, _rate_limit_exceeded_handler
|
|
|
|
| 182 |
app.include_router(partners.router, prefix="/api/v1") # Partner Dashboard
|
| 183 |
app.include_router(team.router, prefix="/api/v1") # Team Management (owner only)
|
| 184 |
app.include_router(notifications.router, prefix="/api/v1") # HOT Lead Notifications
|
| 185 |
+
app.include_router(products.router, prefix="/api/v1")
|
| 186 |
+
app.include_router(bookings.router, prefix="/api/v1") # Products & Catalog Management
|
| 187 |
# app.include_router(oauth.router, prefix="/api/v1") # OAuth removed
|
| 188 |
|
| 189 |
|
frontend/app/appointments/page.tsx
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use client'
|
| 2 |
+
|
| 3 |
+
import { useState, useEffect } from 'react'
|
| 4 |
+
import { bookingsApi } from '@/lib/api'
|
| 5 |
+
import { BookingCalendar } from '@/components/bookings/BookingCalendar'
|
| 6 |
+
import { AppointmentsList } from '@/components/bookings/AppointmentsList'
|
| 7 |
+
import { Plus, Settings } from 'lucide-react'
|
| 8 |
+
import Link from 'next/link'
|
| 9 |
+
|
| 10 |
+
export default function AppointmentsPage() {
|
| 11 |
+
const [selectedDate, setSelectedDate] = useState<Date>(new Date())
|
| 12 |
+
const [appointments, setAppointments] = useState<any[]>([])
|
| 13 |
+
const [isLoading, setIsLoading] = useState(true)
|
| 14 |
+
|
| 15 |
+
const fetchAppointments = async () => {
|
| 16 |
+
setIsLoading(true)
|
| 17 |
+
try {
|
| 18 |
+
const data = await bookingsApi.getAppointments()
|
| 19 |
+
setAppointments(data)
|
| 20 |
+
} catch (error) {
|
| 21 |
+
console.error('Failed to fetch appointments:', error)
|
| 22 |
+
} finally {
|
| 23 |
+
setIsLoading(false)
|
| 24 |
+
}
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
const handleCancel = async (id: string) => {
|
| 28 |
+
if (!confirm('Вы уверены, что хотите отменить эту встречу?')) return
|
| 29 |
+
try {
|
| 30 |
+
await bookingsApi.cancelAppointment(id)
|
| 31 |
+
fetchAppointments()
|
| 32 |
+
} catch (error) {
|
| 33 |
+
console.error('Failed to cancel appointment:', error)
|
| 34 |
+
alert('Ошибка отмены встречи')
|
| 35 |
+
}
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
useEffect(() => {
|
| 39 |
+
fetchAppointments()
|
| 40 |
+
}, [])
|
| 41 |
+
|
| 42 |
+
// Filter appointments for selected date
|
| 43 |
+
const selectedDateAppointments = appointments.filter(apt => {
|
| 44 |
+
const aptDate = new Date(apt.start_time)
|
| 45 |
+
return (
|
| 46 |
+
aptDate.getDate() === selectedDate.getDate() &&
|
| 47 |
+
aptDate.getMonth() === selectedDate.getMonth() &&
|
| 48 |
+
aptDate.getFullYear() === selectedDate.getFullYear()
|
| 49 |
+
)
|
| 50 |
+
})
|
| 51 |
+
|
| 52 |
+
return (
|
| 53 |
+
<div className="min-h-screen bg-slate-50 p-8 font-['Inter']">
|
| 54 |
+
<div className="max-w-7xl mx-auto">
|
| 55 |
+
<div className="flex items-center justify-between mb-8">
|
| 56 |
+
<div>
|
| 57 |
+
<h1 className="text-3xl font-bold text-slate-900">Записи и Встречи</h1>
|
| 58 |
+
<p className="text-slate-500 mt-1">Управляйте расписанием и предстоящими звонками</p>
|
| 59 |
+
</div>
|
| 60 |
+
<div className="flex gap-3">
|
| 61 |
+
<Link
|
| 62 |
+
href="/settings/brain"
|
| 63 |
+
className="px-4 py-2.5 bg-white border border-slate-200 text-slate-700 font-medium rounded-xl hover:bg-slate-50 transition-colors flex items-center gap-2"
|
| 64 |
+
>
|
| 65 |
+
<Settings className="w-4 h-4" />
|
| 66 |
+
Настройки
|
| 67 |
+
</Link>
|
| 68 |
+
<button className="px-4 py-2.5 bg-indigo-600 text-white font-bold rounded-xl hover:bg-indigo-700 shadow-lg shadow-indigo-200 transition-all flex items-center gap-2">
|
| 69 |
+
<Plus className="w-5 h-5" />
|
| 70 |
+
Создать запись
|
| 71 |
+
</button>
|
| 72 |
+
</div>
|
| 73 |
+
</div>
|
| 74 |
+
|
| 75 |
+
<div className="grid grid-cols-1 lg:grid-cols-12 gap-8">
|
| 76 |
+
{/* Left: Calendar */}
|
| 77 |
+
<div className="lg:col-span-4">
|
| 78 |
+
<div className="sticky top-8">
|
| 79 |
+
<BookingCalendar
|
| 80 |
+
appointments={appointments}
|
| 81 |
+
selectedDate={selectedDate}
|
| 82 |
+
onSelectDate={setSelectedDate}
|
| 83 |
+
/>
|
| 84 |
+
|
| 85 |
+
{/* Summary Card */}
|
| 86 |
+
<div className="mt-6 bg-indigo-600 rounded-2xl p-6 text-white shadow-xl shadow-indigo-200">
|
| 87 |
+
<h3 className="font-bold text-lg mb-4 opacity-90">Сводка на {selectedDate.toLocaleDateString()}</h3>
|
| 88 |
+
<div className="space-y-4">
|
| 89 |
+
<div className="flex items-center justify-between">
|
| 90 |
+
<span className="text-indigo-100">Всего встреч</span>
|
| 91 |
+
<span className="font-bold text-2xl">{selectedDateAppointments.length}</span>
|
| 92 |
+
</div>
|
| 93 |
+
<div className="w-full h-px bg-indigo-500/50" />
|
| 94 |
+
<div className="text-sm text-indigo-100 leading-relaxed">
|
| 95 |
+
У вас запланировано {selectedDateAppointments.length} встреч на этот день.
|
| 96 |
+
AI ассистент автоматически отправит напоминания за час до начала.
|
| 97 |
+
</div>
|
| 98 |
+
</div>
|
| 99 |
+
</div>
|
| 100 |
+
</div>
|
| 101 |
+
</div>
|
| 102 |
+
|
| 103 |
+
{/* Right: List */}
|
| 104 |
+
<div className="lg:col-span-8">
|
| 105 |
+
<div className="bg-white rounded-2xl border border-slate-200 p-6 min-h-[600px]">
|
| 106 |
+
<div className="flex items-center justify-between mb-6">
|
| 107 |
+
<h2 className="text-lg font-bold text-slate-900">
|
| 108 |
+
Встречи на {selectedDate.toLocaleDateString()}
|
| 109 |
+
</h2>
|
| 110 |
+
<span className="text-sm text-slate-400">
|
| 111 |
+
{selectedDateAppointments.length} записей
|
| 112 |
+
</span>
|
| 113 |
+
</div>
|
| 114 |
+
|
| 115 |
+
<AppointmentsList
|
| 116 |
+
appointments={selectedDateAppointments}
|
| 117 |
+
onCancel={handleCancel}
|
| 118 |
+
isLoading={isLoading}
|
| 119 |
+
/>
|
| 120 |
+
</div>
|
| 121 |
+
</div>
|
| 122 |
+
</div>
|
| 123 |
+
</div>
|
| 124 |
+
</div>
|
| 125 |
+
)
|
| 126 |
+
}
|
frontend/components/Sidebar.tsx
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
|
| 3 |
import Link from 'next/link'
|
| 4 |
import { usePathname } from 'next/navigation'
|
| 5 |
-
import { LayoutDashboard, MessageSquare, Database, DollarSign, Send, LogOut, Brain, Target, Plug, Zap, Users, ChevronRight, Sparkles, Command, User, Building, Bell } from 'lucide-react'
|
| 6 |
import { useAuth } from '@/contexts/AuthContext'
|
| 7 |
import { motion, AnimatePresence } from 'framer-motion'
|
| 8 |
import { cn } from '@/lib/utils'
|
|
@@ -158,6 +158,16 @@ export function Sidebar() {
|
|
| 158 |
{/* Badge for unread messages could go here */}
|
| 159 |
</Link>
|
| 160 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 161 |
|
| 162 |
</div>
|
| 163 |
</motion.div>
|
|
|
|
| 2 |
|
| 3 |
import Link from 'next/link'
|
| 4 |
import { usePathname } from 'next/navigation'
|
| 5 |
+
import { LayoutDashboard, MessageSquare, Database, DollarSign, Send, LogOut, Brain, Target, Plug, Zap, Users, ChevronRight, Sparkles, Command, User, Building, Bell, Calendar } from 'lucide-react'
|
| 6 |
import { useAuth } from '@/contexts/AuthContext'
|
| 7 |
import { motion, AnimatePresence } from 'framer-motion'
|
| 8 |
import { cn } from '@/lib/utils'
|
|
|
|
| 158 |
{/* Badge for unread messages could go here */}
|
| 159 |
</Link>
|
| 160 |
|
| 161 |
+
<Link href="/appointments" className={cn(
|
| 162 |
+
"flex items-center gap-3 px-4 py-2.5 rounded-xl text-sm font-medium transition-all duration-200 group relative",
|
| 163 |
+
isActive('/appointments')
|
| 164 |
+
? "text-white bg-indigo-600 shadow-lg shadow-indigo-900/20"
|
| 165 |
+
: "text-white/80 hover:text-white hover:bg-white/5"
|
| 166 |
+
)}>
|
| 167 |
+
<Calendar className={cn("w-5 h-5 transition-colors", isActive('/appointments') ? "text-white" : "text-white/70 group-hover:text-indigo-400")} />
|
| 168 |
+
<span>Записи</span>
|
| 169 |
+
</Link>
|
| 170 |
+
|
| 171 |
|
| 172 |
</div>
|
| 173 |
</motion.div>
|
frontend/components/bookings/AppointmentsList.tsx
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use client'
|
| 2 |
+
|
| 3 |
+
import { format } from 'date-fns'
|
| 4 |
+
import { ru } from 'date-fns/locale'
|
| 5 |
+
import { Calendar, User, Clock, MoreVertical, X, CheckCircle2 } from 'lucide-react'
|
| 6 |
+
import { cn } from '@/lib/utils'
|
| 7 |
+
|
| 8 |
+
interface Appointment {
|
| 9 |
+
id: string
|
| 10 |
+
start_time: string
|
| 11 |
+
end_time: string
|
| 12 |
+
status: string
|
| 13 |
+
lead?: {
|
| 14 |
+
name: string
|
| 15 |
+
email?: string
|
| 16 |
+
phone?: string
|
| 17 |
+
}
|
| 18 |
+
service?: {
|
| 19 |
+
name: string
|
| 20 |
+
duration_minutes: number
|
| 21 |
+
}
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
interface AppointmentsListProps {
|
| 25 |
+
appointments: Appointment[]
|
| 26 |
+
onCancel?: (id: string) => void
|
| 27 |
+
isLoading?: boolean
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
export function AppointmentsList({ appointments, onCancel, isLoading }: AppointmentsListProps) {
|
| 31 |
+
if (isLoading) {
|
| 32 |
+
return (
|
| 33 |
+
<div className="space-y-4">
|
| 34 |
+
{[1, 2, 3].map((i) => (
|
| 35 |
+
<div key={i} className="h-24 bg-slate-50 rounded-xl animate-pulse" />
|
| 36 |
+
))}
|
| 37 |
+
</div>
|
| 38 |
+
)
|
| 39 |
+
}
|
| 40 |
+
|
| 41 |
+
if (appointments.length === 0) {
|
| 42 |
+
return (
|
| 43 |
+
<div className="flex flex-col items-center justify-center py-12 text-slate-400 bg-slate-50 rounded-xl border border-dashed border-slate-200">
|
| 44 |
+
<Calendar className="w-12 h-12 mb-3 text-slate-300" />
|
| 45 |
+
<p className="font-medium">Нет запланированных встреч</p>
|
| 46 |
+
<p className="text-sm">Здесь появятся записи клиентов</p>
|
| 47 |
+
</div>
|
| 48 |
+
)
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
return (
|
| 52 |
+
<div className="space-y-3">
|
| 53 |
+
{appointments.map((apt) => (
|
| 54 |
+
<div
|
| 55 |
+
key={apt.id}
|
| 56 |
+
className="bg-white p-4 rounded-xl border border-slate-100 shadow-sm hover:shadow-md transition-shadow flex items-center justify-between group"
|
| 57 |
+
>
|
| 58 |
+
<div className="flex items-center gap-4">
|
| 59 |
+
{/* Time Box */}
|
| 60 |
+
<div className="flex flex-col items-center justify-center w-16 h-16 bg-indigo-50 text-indigo-700 rounded-lg border border-indigo-100">
|
| 61 |
+
<span className="text-lg font-bold">
|
| 62 |
+
{format(new Date(apt.start_time), 'HH:mm')}
|
| 63 |
+
</span>
|
| 64 |
+
<span className="text-xs font-medium uppercase text-indigo-400">
|
| 65 |
+
{format(new Date(apt.start_time), 'd MMM', { locale: ru })}
|
| 66 |
+
</span>
|
| 67 |
+
</div>
|
| 68 |
+
|
| 69 |
+
{/* Info */}
|
| 70 |
+
<div>
|
| 71 |
+
<h3 className="font-bold text-slate-900 flex items-center gap-2">
|
| 72 |
+
{apt.lead?.name || 'Неизвестный клиент'}
|
| 73 |
+
<span className={cn(
|
| 74 |
+
"px-2 py-0.5 rounded-full text-[10px] uppercase font-bold tracking-wider",
|
| 75 |
+
apt.status === 'scheduled' ? "bg-green-100 text-green-700" :
|
| 76 |
+
apt.status === 'cancelled' ? "bg-red-100 text-red-700" :
|
| 77 |
+
"bg-slate-100 text-slate-600"
|
| 78 |
+
)}>
|
| 79 |
+
{apt.status === 'scheduled' ? 'Активно' :
|
| 80 |
+
apt.status === 'cancelled' ? 'Отмена' : apt.status}
|
| 81 |
+
</span>
|
| 82 |
+
</h3>
|
| 83 |
+
<div className="flex items-center gap-4 mt-1 text-sm text-slate-500">
|
| 84 |
+
<span className="flex items-center gap-1">
|
| 85 |
+
<Clock className="w-3.5 h-3.5" />
|
| 86 |
+
{apt.service?.duration_minutes || 30} мин
|
| 87 |
+
</span>
|
| 88 |
+
<span className="flex items-center gap-1">
|
| 89 |
+
<User className="w-3.5 h-3.5" />
|
| 90 |
+
{apt.service?.name || 'Встреча'}
|
| 91 |
+
</span>
|
| 92 |
+
</div>
|
| 93 |
+
</div>
|
| 94 |
+
</div>
|
| 95 |
+
|
| 96 |
+
{/* Actions */}
|
| 97 |
+
<div className="flex items-center gap-2">
|
| 98 |
+
{apt.status === 'scheduled' && onCancel && (
|
| 99 |
+
<button
|
| 100 |
+
onClick={() => onCancel(apt.id)}
|
| 101 |
+
className="p-2 text-slate-400 hover:text-red-500 hover:bg-red-50 rounded-lg transition-colors opacity-0 group-hover:opacity-100"
|
| 102 |
+
title="Отменить встречу"
|
| 103 |
+
>
|
| 104 |
+
<X className="w-5 h-5" />
|
| 105 |
+
</button>
|
| 106 |
+
)}
|
| 107 |
+
<button className="p-2 text-slate-400 hover:text-indigo-600 hover:bg-slate-50 rounded-lg transition-colors">
|
| 108 |
+
<MoreVertical className="w-5 h-5" />
|
| 109 |
+
</button>
|
| 110 |
+
</div>
|
| 111 |
+
</div>
|
| 112 |
+
))}
|
| 113 |
+
</div>
|
| 114 |
+
)
|
| 115 |
+
}
|
frontend/components/bookings/BookingCalendar.tsx
ADDED
|
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use client'
|
| 2 |
+
|
| 3 |
+
import { useState } from 'react'
|
| 4 |
+
import { Calendar as CalendarIcon, ChevronLeft, ChevronRight } from 'lucide-react'
|
| 5 |
+
import { format, addMonths, subMonths, startOfMonth, endOfMonth, eachDayOfInterval, isSameMonth, isSameDay, isToday } from 'date-fns'
|
| 6 |
+
import { ru } from 'date-fns/locale'
|
| 7 |
+
import { cn } from '@/lib/utils'
|
| 8 |
+
|
| 9 |
+
interface BookingCalendarProps {
|
| 10 |
+
appointments: any[]
|
| 11 |
+
selectedDate: Date | null
|
| 12 |
+
onSelectDate: (date: Date) => void
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
export function BookingCalendar({ appointments, selectedDate, onSelectDate }: BookingCalendarProps) {
|
| 16 |
+
const [currentMonth, setCurrentMonth] = useState(new Date())
|
| 17 |
+
|
| 18 |
+
const days = eachDayOfInterval({
|
| 19 |
+
start: startOfMonth(currentMonth),
|
| 20 |
+
end: endOfMonth(currentMonth)
|
| 21 |
+
})
|
| 22 |
+
|
| 23 |
+
const nextMonth = () => setCurrentMonth(addMonths(currentMonth, 1))
|
| 24 |
+
const prevMonth = () => setCurrentMonth(subMonths(currentMonth, 1))
|
| 25 |
+
|
| 26 |
+
return (
|
| 27 |
+
<div className="bg-white p-6 rounded-2xl border border-slate-200 shadow-sm">
|
| 28 |
+
{/* Header */}
|
| 29 |
+
<div className="flex items-center justify-between mb-6">
|
| 30 |
+
<h2 className="font-bold text-slate-900 capitalize flex items-center gap-2">
|
| 31 |
+
<CalendarIcon className="w-5 h-5 text-indigo-600" />
|
| 32 |
+
{format(currentMonth, 'LLLL yyyy', { locale: ru })}
|
| 33 |
+
</h2>
|
| 34 |
+
<div className="flex gap-1">
|
| 35 |
+
<button onClick={prevMonth} className="p-1.5 hover:bg-slate-100 rounded-lg text-slate-500">
|
| 36 |
+
<ChevronLeft className="w-5 h-5" />
|
| 37 |
+
</button>
|
| 38 |
+
<button onClick={nextMonth} className="p-1.5 hover:bg-slate-100 rounded-lg text-slate-500">
|
| 39 |
+
<ChevronRight className="w-5 h-5" />
|
| 40 |
+
</button>
|
| 41 |
+
</div>
|
| 42 |
+
</div>
|
| 43 |
+
|
| 44 |
+
{/* Grid */}
|
| 45 |
+
<div className="grid grid-cols-7 gap-1 mb-2">
|
| 46 |
+
{['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'].map(day => (
|
| 47 |
+
<div key={day} className="text-center text-xs font-bold text-slate-400 uppercase py-2">
|
| 48 |
+
{day}
|
| 49 |
+
</div>
|
| 50 |
+
))}
|
| 51 |
+
</div>
|
| 52 |
+
|
| 53 |
+
<div className="grid grid-cols-7 gap-1">
|
| 54 |
+
{days.map((day, dayIdx) => {
|
| 55 |
+
// Check if day has appointments
|
| 56 |
+
const dayAppointments = appointments.filter(apt =>
|
| 57 |
+
isSameDay(new Date(apt.start_time), day)
|
| 58 |
+
)
|
| 59 |
+
const hasAppointments = dayAppointments.length > 0
|
| 60 |
+
|
| 61 |
+
return (
|
| 62 |
+
<button
|
| 63 |
+
key={day.toString()}
|
| 64 |
+
onClick={() => onSelectDate(day)}
|
| 65 |
+
className={cn(
|
| 66 |
+
"h-10 rounded-lg text-sm font-medium flex items-center justify-center relative transition-all",
|
| 67 |
+
!isSameMonth(day, currentMonth) && "text-slate-300",
|
| 68 |
+
isToday(day) && "text-indigo-600 font-bold bg-indigo-50",
|
| 69 |
+
isSameDay(day, selectedDate || new Date(0)) && "bg-indigo-600 text-white shadow-md shadow-indigo-200 hover:bg-indigo-700",
|
| 70 |
+
!isSameDay(day, selectedDate || new Date(0)) && !isToday(day) && "hover:bg-slate-50 text-slate-700"
|
| 71 |
+
)}
|
| 72 |
+
>
|
| 73 |
+
{format(day, 'd')}
|
| 74 |
+
{hasAppointments && (
|
| 75 |
+
<div className={cn(
|
| 76 |
+
"absolute bottom-1.5 w-1 h-1 rounded-full",
|
| 77 |
+
isSameDay(day, selectedDate || new Date(0)) ? "bg-white" : "bg-indigo-500"
|
| 78 |
+
)} />
|
| 79 |
+
)}
|
| 80 |
+
</button>
|
| 81 |
+
)
|
| 82 |
+
})}
|
| 83 |
+
</div>
|
| 84 |
+
|
| 85 |
+
<div className="mt-4 pt-4 border-t border-slate-100 flex items-center justify-between text-xs text-slate-400">
|
| 86 |
+
<span className="flex items-center gap-1.5">
|
| 87 |
+
<span className="w-2 h-2 rounded-full bg-indigo-500"></span>
|
| 88 |
+
Есть записи
|
| 89 |
+
</span>
|
| 90 |
+
<button
|
| 91 |
+
onClick={() => {
|
| 92 |
+
setCurrentMonth(new Date())
|
| 93 |
+
onSelectDate(new Date())
|
| 94 |
+
}}
|
| 95 |
+
className="text-indigo-600 font-medium hover:underline"
|
| 96 |
+
>
|
| 97 |
+
Сегодня
|
| 98 |
+
</button>
|
| 99 |
+
</div>
|
| 100 |
+
</div>
|
| 101 |
+
)
|
| 102 |
+
}
|
frontend/lib/api.ts
CHANGED
|
@@ -477,3 +477,26 @@ export const adminApi = {
|
|
| 477 |
return response.data
|
| 478 |
}
|
| 479 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 477 |
return response.data
|
| 478 |
}
|
| 479 |
}
|
| 480 |
+
|
| 481 |
+
// Bookings API
|
| 482 |
+
export const bookingsApi = {
|
| 483 |
+
getAppointments: async (params?: { start_date?: string, end_date?: string, status?: string }) => {
|
| 484 |
+
const response = await api.get('/api/v1/bookings/', { params })
|
| 485 |
+
return response.data
|
| 486 |
+
},
|
| 487 |
+
|
| 488 |
+
createAppointment: async (data: any) => {
|
| 489 |
+
const response = await api.post('/api/v1/bookings/', data)
|
| 490 |
+
return response.data
|
| 491 |
+
},
|
| 492 |
+
|
| 493 |
+
cancelAppointment: async (appointmentId: string) => {
|
| 494 |
+
const response = await api.delete(`/api/v1/bookings/${appointmentId}`)
|
| 495 |
+
return response.data
|
| 496 |
+
},
|
| 497 |
+
|
| 498 |
+
getServices: async () => {
|
| 499 |
+
const response = await api.get('/api/v1/bookings/services')
|
| 500 |
+
return response.data
|
| 501 |
+
}
|
| 502 |
+
}
|