Spaces:
Running
Running
axeronis commited on
Commit ·
c6ce293
1
Parent(s): 4fb5cd6
feat: unified knowledge base (products + booking + persona) and db migration
Browse files- backend/app/api/tenants.py +13 -0
- backend/app/models/tenant.py +3 -0
- backend/apply_tenant_booking_schema.py +25 -0
- frontend/app/settings/brain/page.tsx +390 -304
- frontend/components/BookingSettings.tsx +174 -0
backend/app/api/tenants.py
CHANGED
|
@@ -28,6 +28,8 @@ class TenantResponse(BaseModel):
|
|
| 28 |
sales_methodology: Optional[str]
|
| 29 |
custom_instructions: Optional[str]
|
| 30 |
banned_words: Optional[list]
|
|
|
|
|
|
|
| 31 |
manager_monthly_salary: int = 1000
|
| 32 |
tokens_balance: int
|
| 33 |
is_active: bool
|
|
@@ -41,6 +43,8 @@ class UpdateTenantRequest(BaseModel):
|
|
| 41 |
sales_methodology: Optional[str] = None
|
| 42 |
custom_instructions: Optional[str] = None
|
| 43 |
banned_words: Optional[list] = None
|
|
|
|
|
|
|
| 44 |
manager_monthly_salary: Optional[int] = None
|
| 45 |
|
| 46 |
|
|
@@ -99,7 +103,9 @@ async def get_tenant(
|
|
| 99 |
tone_of_voice=getattr(tenant, 'tone_of_voice', 'Professional'),
|
| 100 |
sales_methodology=getattr(tenant, 'sales_methodology', 'Consultative'),
|
| 101 |
custom_instructions=getattr(tenant, 'custom_instructions', ''),
|
|
|
|
| 102 |
banned_words=getattr(tenant, 'banned_words', []),
|
|
|
|
| 103 |
tokens_balance=tenant.tokens_balance,
|
| 104 |
is_active=tenant.is_active,
|
| 105 |
referred_by=referred_by
|
|
@@ -167,6 +173,9 @@ async def update_tenant(
|
|
| 167 |
|
| 168 |
if request.manager_monthly_salary is not None:
|
| 169 |
tenant.manager_monthly_salary = request.manager_monthly_salary
|
|
|
|
|
|
|
|
|
|
| 170 |
|
| 171 |
# 5. CRITICAL: Explicitly commit changes
|
| 172 |
session.add(tenant)
|
|
@@ -181,7 +190,9 @@ async def update_tenant(
|
|
| 181 |
tone_of_voice=getattr(tenant, 'tone_of_voice', 'Professional'),
|
| 182 |
sales_methodology=getattr(tenant, 'sales_methodology', 'Consultative'),
|
| 183 |
custom_instructions=getattr(tenant, 'custom_instructions', ''),
|
|
|
|
| 184 |
banned_words=getattr(tenant, 'banned_words', []),
|
|
|
|
| 185 |
tokens_balance=tenant.tokens_balance,
|
| 186 |
is_active=tenant.is_active,
|
| 187 |
manager_monthly_salary=tenant.manager_monthly_salary,
|
|
@@ -234,7 +245,9 @@ async def get_my_tenant(
|
|
| 234 |
tone_of_voice=getattr(tenant, 'tone_of_voice', 'Professional'),
|
| 235 |
sales_methodology=getattr(tenant, 'sales_methodology', 'Consultative'),
|
| 236 |
custom_instructions=getattr(tenant, 'custom_instructions', ''),
|
|
|
|
| 237 |
banned_words=getattr(tenant, 'banned_words', []),
|
|
|
|
| 238 |
tokens_balance=tenant.tokens_balance,
|
| 239 |
is_active=tenant.is_active,
|
| 240 |
referred_by=referred_by
|
|
|
|
| 28 |
sales_methodology: Optional[str]
|
| 29 |
custom_instructions: Optional[str]
|
| 30 |
banned_words: Optional[list]
|
| 31 |
+
banned_words: Optional[list]
|
| 32 |
+
booking_settings: Optional[Dict[str, Any]]
|
| 33 |
manager_monthly_salary: int = 1000
|
| 34 |
tokens_balance: int
|
| 35 |
is_active: bool
|
|
|
|
| 43 |
sales_methodology: Optional[str] = None
|
| 44 |
custom_instructions: Optional[str] = None
|
| 45 |
banned_words: Optional[list] = None
|
| 46 |
+
banned_words: Optional[list] = None
|
| 47 |
+
booking_settings: Optional[Dict[str, Any]] = None
|
| 48 |
manager_monthly_salary: Optional[int] = None
|
| 49 |
|
| 50 |
|
|
|
|
| 103 |
tone_of_voice=getattr(tenant, 'tone_of_voice', 'Professional'),
|
| 104 |
sales_methodology=getattr(tenant, 'sales_methodology', 'Consultative'),
|
| 105 |
custom_instructions=getattr(tenant, 'custom_instructions', ''),
|
| 106 |
+
custom_instructions=getattr(tenant, 'custom_instructions', ''),
|
| 107 |
banned_words=getattr(tenant, 'banned_words', []),
|
| 108 |
+
booking_settings=tenant.booking_settings,
|
| 109 |
tokens_balance=tenant.tokens_balance,
|
| 110 |
is_active=tenant.is_active,
|
| 111 |
referred_by=referred_by
|
|
|
|
| 173 |
|
| 174 |
if request.manager_monthly_salary is not None:
|
| 175 |
tenant.manager_monthly_salary = request.manager_monthly_salary
|
| 176 |
+
|
| 177 |
+
if request.booking_settings is not None:
|
| 178 |
+
tenant.booking_settings = request.booking_settings
|
| 179 |
|
| 180 |
# 5. CRITICAL: Explicitly commit changes
|
| 181 |
session.add(tenant)
|
|
|
|
| 190 |
tone_of_voice=getattr(tenant, 'tone_of_voice', 'Professional'),
|
| 191 |
sales_methodology=getattr(tenant, 'sales_methodology', 'Consultative'),
|
| 192 |
custom_instructions=getattr(tenant, 'custom_instructions', ''),
|
| 193 |
+
custom_instructions=getattr(tenant, 'custom_instructions', ''),
|
| 194 |
banned_words=getattr(tenant, 'banned_words', []),
|
| 195 |
+
booking_settings=tenant.booking_settings,
|
| 196 |
tokens_balance=tenant.tokens_balance,
|
| 197 |
is_active=tenant.is_active,
|
| 198 |
manager_monthly_salary=tenant.manager_monthly_salary,
|
|
|
|
| 245 |
tone_of_voice=getattr(tenant, 'tone_of_voice', 'Professional'),
|
| 246 |
sales_methodology=getattr(tenant, 'sales_methodology', 'Consultative'),
|
| 247 |
custom_instructions=getattr(tenant, 'custom_instructions', ''),
|
| 248 |
+
custom_instructions=getattr(tenant, 'custom_instructions', ''),
|
| 249 |
banned_words=getattr(tenant, 'banned_words', []),
|
| 250 |
+
booking_settings=tenant.booking_settings,
|
| 251 |
tokens_balance=tenant.tokens_balance,
|
| 252 |
is_active=tenant.is_active,
|
| 253 |
referred_by=referred_by
|
backend/app/models/tenant.py
CHANGED
|
@@ -75,6 +75,9 @@ class Tenant(SQLModel, table=True):
|
|
| 75 |
# ROI Calculation Settings
|
| 76 |
manager_monthly_salary: int = Field(default=1000) # USD per month, default $1000
|
| 77 |
|
|
|
|
|
|
|
|
|
|
| 78 |
# Status
|
| 79 |
is_active: bool = Field(default=True)
|
| 80 |
created_at: datetime = Field(default_factory=datetime.utcnow)
|
|
|
|
| 75 |
# ROI Calculation Settings
|
| 76 |
manager_monthly_salary: int = Field(default=1000) # USD per month, default $1000
|
| 77 |
|
| 78 |
+
# Booking System Settings
|
| 79 |
+
booking_settings: Optional[Dict[str, Any]] = Field(default=None, sa_column=Column(JSON))
|
| 80 |
+
|
| 81 |
# Status
|
| 82 |
is_active: bool = Field(default=True)
|
| 83 |
created_at: datetime = Field(default_factory=datetime.utcnow)
|
backend/apply_tenant_booking_schema.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
from sqlalchemy import text
|
| 3 |
+
from dotenv import load_dotenv
|
| 4 |
+
import os
|
| 5 |
+
|
| 6 |
+
load_dotenv()
|
| 7 |
+
|
| 8 |
+
from app.core.database import async_engine as engine
|
| 9 |
+
|
| 10 |
+
async def apply_migration():
|
| 11 |
+
async with engine.begin() as conn:
|
| 12 |
+
print("Checking if column 'booking_settings' exists in 'tenants' table...")
|
| 13 |
+
# Check if column exists
|
| 14 |
+
result = await conn.execute(text(
|
| 15 |
+
"SELECT column_name FROM information_schema.columns WHERE table_name='tenants' AND column_name='booking_settings'"
|
| 16 |
+
))
|
| 17 |
+
if result.first():
|
| 18 |
+
print("Column 'booking_settings' already exists.")
|
| 19 |
+
else:
|
| 20 |
+
print("Adding column 'booking_settings' to 'tenants' table...")
|
| 21 |
+
await conn.execute(text("ALTER TABLE tenants ADD COLUMN booking_settings JSONB DEFAULT NULL"))
|
| 22 |
+
print("Column added successfully.")
|
| 23 |
+
|
| 24 |
+
if __name__ == "__main__":
|
| 25 |
+
asyncio.run(apply_migration())
|
frontend/app/settings/brain/page.tsx
CHANGED
|
@@ -2,10 +2,16 @@
|
|
| 2 |
|
| 3 |
import { useState, useEffect } from 'react'
|
| 4 |
import { useAuth } from '@/contexts/AuthContext'
|
| 5 |
-
import {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
import { motion, AnimatePresence } from 'framer-motion'
|
| 7 |
import { cn } from '@/lib/utils'
|
| 8 |
-
import { api } from '@/lib/api'
|
|
|
|
|
|
|
| 9 |
|
| 10 |
interface AISettings {
|
| 11 |
business_description: string
|
|
@@ -22,6 +28,11 @@ interface AIPersona {
|
|
| 22 |
manager_monthly_salary: number
|
| 23 |
}
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
const TONE_OPTIONS = [
|
| 26 |
{ value: 'Professional', label: 'Профессиональный', icon: Shield, description: 'Деловой, формальный тон' },
|
| 27 |
{ value: 'Friendly', label: 'Дружелюбный', icon: Users, description: 'Теплый, неформальный' },
|
|
@@ -66,6 +77,8 @@ export default function BrainSettingsPage() {
|
|
| 66 |
const { user } = useAuth()
|
| 67 |
const [loading, setLoading] = useState(true)
|
| 68 |
const [saving, setSaving] = useState(false)
|
|
|
|
|
|
|
| 69 |
const [newField, setNewField] = useState('')
|
| 70 |
const [newBannedWord, setNewBannedWord] = useState('')
|
| 71 |
|
|
@@ -84,6 +97,7 @@ export default function BrainSettingsPage() {
|
|
| 84 |
manager_monthly_salary: 1000
|
| 85 |
})
|
| 86 |
|
|
|
|
| 87 |
useEffect(() => {
|
| 88 |
if (user) {
|
| 89 |
fetchSettings()
|
|
@@ -106,6 +120,7 @@ export default function BrainSettingsPage() {
|
|
| 106 |
banned_words: data.banned_words || [],
|
| 107 |
manager_monthly_salary: data.manager_monthly_salary || 1000
|
| 108 |
})
|
|
|
|
| 109 |
} catch (error) {
|
| 110 |
console.error('Failed to fetch AI settings:', error)
|
| 111 |
} finally {
|
|
@@ -131,6 +146,21 @@ export default function BrainSettingsPage() {
|
|
| 131 |
}
|
| 132 |
}
|
| 133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
const addCustomField = () => {
|
| 135 |
if (!newField.trim()) return
|
| 136 |
if (settings.custom_fields.includes(newField.trim())) {
|
|
@@ -199,351 +229,407 @@ export default function BrainSettingsPage() {
|
|
| 199 |
return (
|
| 200 |
<div className="min-h-screen bg-slate-100 p-8">
|
| 201 |
<div className="max-w-5xl mx-auto">
|
| 202 |
-
{/* Header */}
|
| 203 |
<motion.div
|
| 204 |
initial={{ opacity: 0, y: -20 }}
|
| 205 |
animate={{ opacity: 1, y: 0 }}
|
| 206 |
-
className="
|
| 207 |
>
|
| 208 |
-
<div className="
|
| 209 |
-
<
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 210 |
</div>
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
<
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
</div>
|
| 219 |
</motion.div>
|
| 220 |
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
<
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
| 232 |
-
|
| 233 |
-
|
| 234 |
-
|
| 235 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 236 |
</div>
|
| 237 |
-
</div>
|
| 238 |
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
|
| 247 |
-
|
| 248 |
-
|
| 249 |
-
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
)}
|
| 253 |
-
>
|
| 254 |
-
<div className="flex items-center gap-3 mb-2 relative z-10">
|
| 255 |
-
<div className={cn(
|
| 256 |
-
"p-2 rounded-lg transition-colors",
|
| 257 |
-
isSelected ? "bg-indigo-100 text-indigo-600" : "bg-slate-100 text-slate-500 group-hover:bg-indigo-50 group-hover:text-indigo-600"
|
| 258 |
-
)}>
|
| 259 |
-
<Icon className="w-5 h-5" />
|
| 260 |
-
</div>
|
| 261 |
-
<h3 className={cn(
|
| 262 |
-
"font-bold text-lg",
|
| 263 |
-
isSelected ? "text-indigo-900" : "text-slate-900"
|
| 264 |
-
)}>
|
| 265 |
-
{tone.label}
|
| 266 |
-
</h3>
|
| 267 |
-
{isSelected && (
|
| 268 |
-
<CheckCircle2 className="w-5 h-5 text-indigo-600 ml-auto" />
|
| 269 |
)}
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
</div>
|
| 284 |
-
|
| 285 |
-
|
| 286 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 287 |
</div>
|
| 288 |
-
</div>
|
| 289 |
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
-
|
| 297 |
-
|
| 298 |
-
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
-
|
| 309 |
-
|
| 310 |
-
|
| 311 |
-
|
| 312 |
-
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
|
| 322 |
-
|
|
|
|
|
|
|
| 323 |
</div>
|
| 324 |
-
<p className="text-sm text-slate-600">{method.description}</p>
|
| 325 |
</div>
|
| 326 |
-
</
|
| 327 |
-
|
| 328 |
-
)
|
| 329 |
-
})}
|
| 330 |
-
</div>
|
| 331 |
-
</motion.div>
|
| 332 |
-
|
| 333 |
-
{/* Business Description */}
|
| 334 |
-
<motion.div variants={item} className="bg-white rounded-2xl shadow-sm border border-slate-200 p-8">
|
| 335 |
-
<div className="flex items-center gap-3 mb-6">
|
| 336 |
-
<div className="p-2 bg-indigo-50 rounded-xl text-indigo-600">
|
| 337 |
-
<Target className="w-6 h-6" />
|
| 338 |
</div>
|
| 339 |
-
|
| 340 |
-
|
| 341 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 342 |
</div>
|
| 343 |
-
</div>
|
| 344 |
|
| 345 |
-
|
| 346 |
-
|
| 347 |
-
|
| 348 |
-
|
| 349 |
-
|
| 350 |
-
|
| 351 |
-
|
| 352 |
|
| 353 |
-
|
| 354 |
-
|
| 355 |
-
|
| 356 |
-
|
| 357 |
-
|
| 358 |
-
|
| 359 |
-
|
| 360 |
-
|
| 361 |
-
|
|
|
|
| 362 |
</div>
|
| 363 |
-
</div>
|
| 364 |
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
| 371 |
-
|
| 372 |
|
| 373 |
-
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
|
| 377 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 378 |
</div>
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 382 |
</div>
|
| 383 |
-
</div>
|
| 384 |
|
| 385 |
-
|
| 386 |
-
|
| 387 |
-
|
| 388 |
-
|
| 389 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 390 |
>
|
| 391 |
-
<
|
| 392 |
-
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
| 397 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 398 |
</div>
|
| 399 |
-
|
| 400 |
-
|
|
|
|
|
|
|
|
|
|
| 401 |
|
| 402 |
-
|
| 403 |
-
|
| 404 |
-
|
| 405 |
-
|
| 406 |
-
|
| 407 |
-
onKeyDown={(e) => e.key === 'Enter' && addCustomField()}
|
| 408 |
-
placeholder="Нап��имер: Регион, Количество сотрудников..."
|
| 409 |
-
className="flex-1 px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-indigo-500/20 focus:border-indigo-500 transition-all outline-none"
|
| 410 |
/>
|
| 411 |
-
|
| 412 |
-
onClick={addCustomField}
|
| 413 |
-
className="px-6 py-3 bg-indigo-600 hover:bg-indigo-700 text-white rounded-xl font-bold shadow-lg hover:shadow-indigo-500/25 transition-all flex items-center gap-2"
|
| 414 |
-
>
|
| 415 |
-
<Plus className="w-5 h-5" />
|
| 416 |
-
Добавить
|
| 417 |
-
</button>
|
| 418 |
-
</div>
|
| 419 |
-
</motion.div>
|
| 420 |
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
|
| 425 |
-
|
| 426 |
-
|
| 427 |
-
|
| 428 |
-
|
| 429 |
-
|
|
|
|
| 430 |
</div>
|
| 431 |
-
</div>
|
| 432 |
-
|
| 433 |
-
<textarea
|
| 434 |
-
value={persona.custom_instructions}
|
| 435 |
-
onChange={(e) => setPersona({ ...persona, custom_instructions: e.target.value })}
|
| 436 |
-
placeholder="Например: - Никогда не говори цену до выяснения бюджета - Всегда упоминай наше УТП: внедрение за 1 день - Если клиент сравнивает с конкурентами, подчеркни скорость"
|
| 437 |
-
className="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-emerald-500/20 focus:border-emerald-500 transition-all outline-none resize-none min-h-[150px] font-mono text-sm"
|
| 438 |
-
/>
|
| 439 |
-
</motion.div>
|
| 440 |
|
| 441 |
-
|
| 442 |
-
|
| 443 |
-
|
| 444 |
-
|
| 445 |
-
|
| 446 |
-
|
| 447 |
-
|
| 448 |
-
|
| 449 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 450 |
</div>
|
| 451 |
-
</div>
|
| 452 |
|
| 453 |
-
|
| 454 |
-
|
| 455 |
-
|
| 456 |
-
|
| 457 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 458 |
>
|
| 459 |
-
<
|
| 460 |
-
|
| 461 |
-
|
| 462 |
-
className="hover:bg-red-200 rounded-md p-0.5 transition-colors"
|
| 463 |
-
>
|
| 464 |
-
<X className="w-3.5 h-3.5" />
|
| 465 |
-
</button>
|
| 466 |
-
</div>
|
| 467 |
-
))}
|
| 468 |
-
</div>
|
| 469 |
-
|
| 470 |
-
<div className="flex gap-3">
|
| 471 |
-
<input
|
| 472 |
-
type="text"
|
| 473 |
-
value={newBannedWord}
|
| 474 |
-
onChange={(e) => setNewBannedWord(e.target.value)}
|
| 475 |
-
onKeyDown={(e) => e.key === 'Enter' && addBannedWord()}
|
| 476 |
-
placeholder="Например: дешево, бесплатно, скидка..."
|
| 477 |
-
className="flex-1 px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-red-500/20 focus:border-red-500 transition-all outline-none"
|
| 478 |
-
/>
|
| 479 |
-
<button
|
| 480 |
-
onClick={addBannedWord}
|
| 481 |
-
className="px-6 py-3 bg-red-600 hover:bg-red-700 text-white rounded-xl font-bold shadow-lg hover:shadow-red-500/25 transition-all flex items-center gap-2"
|
| 482 |
-
>
|
| 483 |
-
<Plus className="w-5 h-5" />
|
| 484 |
-
Добавить
|
| 485 |
-
</button>
|
| 486 |
-
</div>
|
| 487 |
-
</motion.div>
|
| 488 |
-
|
| 489 |
-
{/* ROI Calculator Settings */}
|
| 490 |
-
<motion.div variants={item} className="bg-gradient-to-br from-emerald-50 to-teal-50 rounded-2xl border border-emerald-100 p-8 shadow-sm">
|
| 491 |
-
<div className="flex items-center gap-3 mb-6">
|
| 492 |
-
<div className="p-2 bg-emerald-100 rounded-xl text-emerald-600">
|
| 493 |
-
<Calculator className="w-6 h-6" />
|
| 494 |
</div>
|
| 495 |
-
|
| 496 |
-
|
| 497 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 498 |
</div>
|
| 499 |
-
</div>
|
| 500 |
|
| 501 |
-
|
| 502 |
-
|
| 503 |
-
|
| 504 |
-
|
| 505 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 506 |
</div>
|
| 507 |
-
</label>
|
| 508 |
-
<input
|
| 509 |
-
type="number"
|
| 510 |
-
min="0"
|
| 511 |
-
step="100"
|
| 512 |
-
value={persona.manager_monthly_salary}
|
| 513 |
-
onChange={(e) => setPersona({ ...persona, manager_monthly_salary: parseInt(e.target.value) || 1000 })}
|
| 514 |
-
className="w-full md:w-64 px-4 py-3 bg-white border border-emerald-200 rounded-xl focus:ring-2 focus:ring-emerald-500/20 focus:border-emerald-500 transition-all outline-none font-semibold text-emerald-900"
|
| 515 |
-
placeholder="1000"
|
| 516 |
-
/>
|
| 517 |
-
<div className="mt-3 flex items-start gap-2 text-xs text-emerald-700 bg-emerald-100/50 p-3 rounded-lg border border-emerald-100">
|
| 518 |
-
<AlertCircle className="w-4 h-4 mt-0.5 flex-shrink-0" />
|
| 519 |
-
<p>
|
| 520 |
-
Мы рассчитываем почасовую ставку (зарплата / 160 часов) и экономию времени AI (3 мин на сообщение).
|
| 521 |
-
</p>
|
| 522 |
</div>
|
| 523 |
-
</div>
|
| 524 |
-
</motion.div>
|
| 525 |
|
| 526 |
-
|
| 527 |
-
|
| 528 |
-
|
| 529 |
-
|
| 530 |
-
|
| 531 |
-
|
| 532 |
-
|
| 533 |
-
|
| 534 |
-
|
| 535 |
-
|
| 536 |
-
|
| 537 |
-
|
| 538 |
-
|
| 539 |
-
|
| 540 |
-
|
| 541 |
-
|
| 542 |
-
|
| 543 |
-
|
| 544 |
-
|
|
|
|
| 545 |
</motion.div>
|
| 546 |
-
|
| 547 |
</div>
|
| 548 |
</div>
|
| 549 |
)
|
|
|
|
| 2 |
|
| 3 |
import { useState, useEffect } from 'react'
|
| 4 |
import { useAuth } from '@/contexts/AuthContext'
|
| 5 |
+
import {
|
| 6 |
+
Brain, Plus, X, Save, Loader2, Sparkles, Target, TrendingUp, Zap, Shield, Users,
|
| 7 |
+
BookOpen, Award, Ban, Calculator, DollarSign, CheckCircle2, AlertCircle,
|
| 8 |
+
LayoutGrid, Calendar, ShoppingBag
|
| 9 |
+
} from 'lucide-react'
|
| 10 |
import { motion, AnimatePresence } from 'framer-motion'
|
| 11 |
import { cn } from '@/lib/utils'
|
| 12 |
+
import { api } from '@/lib/api'
|
| 13 |
+
import BookingSettings from '@/components/BookingSettings'
|
| 14 |
+
import ProductsPage from '../products/page' // Importing ProductsPage to embed it
|
| 15 |
|
| 16 |
interface AISettings {
|
| 17 |
business_description: string
|
|
|
|
| 28 |
manager_monthly_salary: number
|
| 29 |
}
|
| 30 |
|
| 31 |
+
type TabType = 'persona' | 'products' | 'booking'
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
|
| 36 |
const TONE_OPTIONS = [
|
| 37 |
{ value: 'Professional', label: 'Профессиональный', icon: Shield, description: 'Деловой, формальный тон' },
|
| 38 |
{ value: 'Friendly', label: 'Дружелюбный', icon: Users, description: 'Теплый, неформальный' },
|
|
|
|
| 77 |
const { user } = useAuth()
|
| 78 |
const [loading, setLoading] = useState(true)
|
| 79 |
const [saving, setSaving] = useState(false)
|
| 80 |
+
const [activeTab, setActiveTab] = useState<TabType>('persona')
|
| 81 |
+
const [bookingSettings, setBookingSettings] = useState<any>(null)
|
| 82 |
const [newField, setNewField] = useState('')
|
| 83 |
const [newBannedWord, setNewBannedWord] = useState('')
|
| 84 |
|
|
|
|
| 97 |
manager_monthly_salary: 1000
|
| 98 |
})
|
| 99 |
|
| 100 |
+
|
| 101 |
useEffect(() => {
|
| 102 |
if (user) {
|
| 103 |
fetchSettings()
|
|
|
|
| 120 |
banned_words: data.banned_words || [],
|
| 121 |
manager_monthly_salary: data.manager_monthly_salary || 1000
|
| 122 |
})
|
| 123 |
+
setBookingSettings(data.booking_settings)
|
| 124 |
} catch (error) {
|
| 125 |
console.error('Failed to fetch AI settings:', error)
|
| 126 |
} finally {
|
|
|
|
| 146 |
}
|
| 147 |
}
|
| 148 |
|
| 149 |
+
const handleBookingSave = async (newSettings: any) => {
|
| 150 |
+
if (!user?.tenant_id) return
|
| 151 |
+
try {
|
| 152 |
+
await api.patch(`/api/v1/tenants/${user.tenant_id}`, {
|
| 153 |
+
booking_settings: newSettings
|
| 154 |
+
})
|
| 155 |
+
alert('✅ Настройки записи сохранены!')
|
| 156 |
+
setBookingSettings(newSettings)
|
| 157 |
+
} catch (error) {
|
| 158 |
+
console.error('Failed to save booking settings:', error)
|
| 159 |
+
alert('❌ Ошибка сохранения настроек записи')
|
| 160 |
+
}
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
|
| 164 |
const addCustomField = () => {
|
| 165 |
if (!newField.trim()) return
|
| 166 |
if (settings.custom_fields.includes(newField.trim())) {
|
|
|
|
| 229 |
return (
|
| 230 |
<div className="min-h-screen bg-slate-100 p-8">
|
| 231 |
<div className="max-w-5xl mx-auto">
|
|
|
|
| 232 |
<motion.div
|
| 233 |
initial={{ opacity: 0, y: -20 }}
|
| 234 |
animate={{ opacity: 1, y: 0 }}
|
| 235 |
+
className="mb-8"
|
| 236 |
>
|
| 237 |
+
<div className="flex items-center gap-4 mb-6">
|
| 238 |
+
<div className="p-3 bg-gradient-to-br from-indigo-600 to-purple-600 rounded-2xl shadow-lg shadow-indigo-200">
|
| 239 |
+
<Brain className="w-8 h-8 text-white" />
|
| 240 |
+
</div>
|
| 241 |
+
<div>
|
| 242 |
+
<h1 className="text-3xl font-bold text-slate-900 mb-1 tracking-tight">
|
| 243 |
+
База Знаний (Brain)
|
| 244 |
+
</h1>
|
| 245 |
+
<p className="text-slate-600">
|
| 246 |
+
Управление интеллектом, знаниями и навыками вашего цифрового сотрудника
|
| 247 |
+
</p>
|
| 248 |
+
</div>
|
| 249 |
</div>
|
| 250 |
+
|
| 251 |
+
{/* Navigation Tabs */}
|
| 252 |
+
<div className="flex gap-2 p-1 bg-white rounded-xl border border-slate-200 w-fit">
|
| 253 |
+
<button
|
| 254 |
+
onClick={() => setActiveTab('persona')}
|
| 255 |
+
className={cn(
|
| 256 |
+
"px-6 py-2.5 rounded-lg text-sm font-bold flex items-center gap-2 transition-all",
|
| 257 |
+
activeTab === 'persona'
|
| 258 |
+
? "bg-slate-100 text-slate-900 shadow-sm"
|
| 259 |
+
: "text-slate-500 hover:text-slate-700 hover:bg-slate-50"
|
| 260 |
+
)}
|
| 261 |
+
>
|
| 262 |
+
<Sparkles className="w-4 h-4" />
|
| 263 |
+
Личность & Правила
|
| 264 |
+
</button>
|
| 265 |
+
<button
|
| 266 |
+
onClick={() => setActiveTab('products')}
|
| 267 |
+
className={cn(
|
| 268 |
+
"px-6 py-2.5 rounded-lg text-sm font-bold flex items-center gap-2 transition-all",
|
| 269 |
+
activeTab === 'products'
|
| 270 |
+
? "bg-slate-100 text-slate-900 shadow-sm"
|
| 271 |
+
: "text-slate-500 hover:text-slate-700 hover:bg-slate-50"
|
| 272 |
+
)}
|
| 273 |
+
>
|
| 274 |
+
<ShoppingBag className="w-4 h-4" />
|
| 275 |
+
Товары (Catalog)
|
| 276 |
+
</button>
|
| 277 |
+
<button
|
| 278 |
+
onClick={() => setActiveTab('booking')}
|
| 279 |
+
className={cn(
|
| 280 |
+
"px-6 py-2.5 rounded-lg text-sm font-bold flex items-center gap-2 transition-all",
|
| 281 |
+
activeTab === 'booking'
|
| 282 |
+
? "bg-slate-100 text-slate-900 shadow-sm"
|
| 283 |
+
: "text-slate-500 hover:text-slate-700 hover:bg-slate-50"
|
| 284 |
+
)}
|
| 285 |
+
>
|
| 286 |
+
<Calendar className="w-4 h-4" />
|
| 287 |
+
Запись (Booking)
|
| 288 |
+
</button>
|
| 289 |
</div>
|
| 290 |
</motion.div>
|
| 291 |
|
| 292 |
+
{activeTab === 'products' && (
|
| 293 |
+
<div className="bg-white rounded-2xl shadow-sm border border-slate-200 overflow-hidden">
|
| 294 |
+
<ProductsPage />
|
| 295 |
+
</div>
|
| 296 |
+
)}
|
| 297 |
+
|
| 298 |
+
{activeTab === 'booking' && (
|
| 299 |
+
<BookingSettings
|
| 300 |
+
settings={bookingSettings}
|
| 301 |
+
onSave={handleBookingSave}
|
| 302 |
+
/>
|
| 303 |
+
)}
|
| 304 |
+
|
| 305 |
+
{activeTab === 'persona' && (
|
| 306 |
+
<motion.div
|
| 307 |
+
variants={container}
|
| 308 |
+
initial="hidden"
|
| 309 |
+
animate="show"
|
| 310 |
+
className="space-y-6"
|
| 311 |
+
>
|
| 312 |
+
{/* Tone of Voice */}
|
| 313 |
+
<motion.div variants={item} className="bg-white rounded-2xl shadow-sm border border-slate-200 p-8">
|
| 314 |
+
<div className="flex items-center gap-3 mb-6">
|
| 315 |
+
<div className="p-2 bg-indigo-50 rounded-xl text-indigo-600">
|
| 316 |
+
<Sparkles className="w-6 h-6" />
|
| 317 |
+
</div>
|
| 318 |
+
<div>
|
| 319 |
+
<h2 className="text-xl font-bold text-slate-900">Тон голоса</h2>
|
| 320 |
+
<p className="text-sm text-slate-500">Выберите стиль общения AI с клиентами</p>
|
| 321 |
+
</div>
|
| 322 |
</div>
|
|
|
|
| 323 |
|
| 324 |
+
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
|
| 325 |
+
{TONE_OPTIONS.map((tone) => {
|
| 326 |
+
const Icon = tone.icon
|
| 327 |
+
const isSelected = persona.tone_of_voice === tone.value
|
| 328 |
+
return (
|
| 329 |
+
<button
|
| 330 |
+
key={tone.value}
|
| 331 |
+
onClick={() => setPersona({ ...persona, tone_of_voice: tone.value as any })}
|
| 332 |
+
className={cn(
|
| 333 |
+
"p-4 rounded-xl border-2 transition-all duration-200 text-left relative overflow-hidden group",
|
| 334 |
+
isSelected
|
| 335 |
+
? "border-indigo-600 bg-indigo-50/50 shadow-md"
|
| 336 |
+
: "border-slate-200 hover:border-indigo-300 bg-white hover:shadow-sm"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 337 |
)}
|
| 338 |
+
>
|
| 339 |
+
<div className="flex items-center gap-3 mb-2 relative z-10">
|
| 340 |
+
<div className={cn(
|
| 341 |
+
"p-2 rounded-lg transition-colors",
|
| 342 |
+
isSelected ? "bg-indigo-100 text-indigo-600" : "bg-slate-100 text-slate-500 group-hover:bg-indigo-50 group-hover:text-indigo-600"
|
| 343 |
+
)}>
|
| 344 |
+
<Icon className="w-5 h-5" />
|
| 345 |
+
</div>
|
| 346 |
+
<h3 className={cn(
|
| 347 |
+
"font-bold text-lg",
|
| 348 |
+
isSelected ? "text-indigo-900" : "text-slate-900"
|
| 349 |
+
)}>
|
| 350 |
+
{tone.label}
|
| 351 |
+
</h3>
|
| 352 |
+
{isSelected && (
|
| 353 |
+
<CheckCircle2 className="w-5 h-5 text-indigo-600 ml-auto" />
|
| 354 |
+
)}
|
| 355 |
+
</div>
|
| 356 |
+
<p className="text-sm text-slate-600 pl-[52px] relative z-10">{tone.description}</p>
|
| 357 |
+
</button>
|
| 358 |
+
)
|
| 359 |
+
})}
|
| 360 |
</div>
|
| 361 |
+
</motion.div>
|
| 362 |
+
|
| 363 |
+
{/* Sales Methodology */}
|
| 364 |
+
<motion.div variants={item} className="bg-white rounded-2xl shadow-sm border border-slate-200 p-8">
|
| 365 |
+
<div className="flex items-center gap-3 mb-6">
|
| 366 |
+
<div className="p-2 bg-purple-50 rounded-xl text-purple-600">
|
| 367 |
+
<BookOpen className="w-6 h-6" />
|
| 368 |
+
</div>
|
| 369 |
+
<div>
|
| 370 |
+
<h2 className="text-xl font-bold text-slate-900">Методология продаж</h2>
|
| 371 |
+
<p className="text-sm text-slate-500">Выберите фреймворк, который AI будет использовать в диалогах</p>
|
| 372 |
+
</div>
|
| 373 |
</div>
|
|
|
|
| 374 |
|
| 375 |
+
<div className="space-y-3">
|
| 376 |
+
{METHODOLOGY_OPTIONS.map((method) => {
|
| 377 |
+
const Icon = method.icon
|
| 378 |
+
const isSelected = persona.sales_methodology === method.value
|
| 379 |
+
return (
|
| 380 |
+
<button
|
| 381 |
+
key={method.value}
|
| 382 |
+
onClick={() => setPersona({ ...persona, sales_methodology: method.value as any })}
|
| 383 |
+
className={cn(
|
| 384 |
+
"w-full p-4 rounded-xl border-2 transition-all duration-200 text-left group",
|
| 385 |
+
isSelected
|
| 386 |
+
? "border-purple-600 bg-purple-50/30 shadow-md"
|
| 387 |
+
: "border-slate-200 hover:border-purple-300 bg-white hover:shadow-sm"
|
| 388 |
+
)}
|
| 389 |
+
>
|
| 390 |
+
<div className="flex items-start gap-4">
|
| 391 |
+
<div className={cn(
|
| 392 |
+
"p-2 rounded-lg mt-0.5 transition-colors",
|
| 393 |
+
isSelected ? "bg-purple-100 text-purple-600" : "bg-slate-100 text-slate-500 group-hover:bg-purple-50 group-hover:text-purple-600"
|
| 394 |
+
)}>
|
| 395 |
+
<Icon className="w-5 h-5" />
|
| 396 |
+
</div>
|
| 397 |
+
<div className="flex-1">
|
| 398 |
+
<div className="flex items-center justify-between mb-1">
|
| 399 |
+
<h3 className={cn(
|
| 400 |
+
"font-bold text-lg",
|
| 401 |
+
isSelected ? "text-purple-900" : "text-slate-900"
|
| 402 |
+
)}>
|
| 403 |
+
{method.label}
|
| 404 |
+
</h3>
|
| 405 |
+
{isSelected && (
|
| 406 |
+
<CheckCircle2 className="w-5 h-5 text-purple-600" />
|
| 407 |
+
)}
|
| 408 |
+
</div>
|
| 409 |
+
<p className="text-sm text-slate-600">{method.description}</p>
|
| 410 |
</div>
|
|
|
|
| 411 |
</div>
|
| 412 |
+
</button>
|
| 413 |
+
)
|
| 414 |
+
})}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 415 |
</div>
|
| 416 |
+
</motion.div>
|
| 417 |
+
|
| 418 |
+
{/* Business Description */}
|
| 419 |
+
<motion.div variants={item} className="bg-white rounded-2xl shadow-sm border border-slate-200 p-8">
|
| 420 |
+
<div className="flex items-center gap-3 mb-6">
|
| 421 |
+
<div className="p-2 bg-indigo-50 rounded-xl text-indigo-600">
|
| 422 |
+
<Target className="w-6 h-6" />
|
| 423 |
+
</div>
|
| 424 |
+
<div>
|
| 425 |
+
<h2 className="text-xl font-bold text-slate-900">Описание бизнеса</h2>
|
| 426 |
+
<p className="text-sm text-slate-500">Опишите ваш бизнес, что вы продаете, ключевые преимущества</p>
|
| 427 |
+
</div>
|
| 428 |
</div>
|
|
|
|
| 429 |
|
| 430 |
+
<textarea
|
| 431 |
+
value={settings.business_description}
|
| 432 |
+
onChange={(e) => setSettings({ ...settings, business_description: e.target.value })}
|
| 433 |
+
placeholder="Например: Мы продаём премиум CRM-системы для малого бизнеса. Наше главное преимущество — простота настройки и внедрения за 1 день."
|
| 434 |
+
className="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-indigo-500/20 focus:border-indigo-500 transition-all outline-none resize-none min-h-[120px]"
|
| 435 |
+
/>
|
| 436 |
+
</motion.div>
|
| 437 |
|
| 438 |
+
{/* Ideal Customer Profile */}
|
| 439 |
+
<motion.div variants={item} className="bg-white rounded-2xl shadow-sm border border-slate-200 p-8">
|
| 440 |
+
<div className="flex items-center gap-3 mb-6">
|
| 441 |
+
<div className="p-2 bg-purple-50 rounded-xl text-purple-600">
|
| 442 |
+
<Users className="w-6 h-6" />
|
| 443 |
+
</div>
|
| 444 |
+
<div>
|
| 445 |
+
<h2 className="text-xl font-bold text-slate-900">Идеальный клиент (ICP)</h2>
|
| 446 |
+
<p className="text-sm text-slate-500">Портрет вашего идеального клиента для квалификации</p>
|
| 447 |
+
</div>
|
| 448 |
</div>
|
|
|
|
| 449 |
|
| 450 |
+
<textarea
|
| 451 |
+
value={settings.ideal_customer_profile}
|
| 452 |
+
onChange={(e) => setSettings({ ...settings, ideal_customer_profile: e.target.value })}
|
| 453 |
+
placeholder="Например: Владелец бизнеса с 5-50 сотрудниками, доход от 10 млн руб/год, ищет решение для автоматизации продаж."
|
| 454 |
+
className="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-indigo-500/20 focus:border-indigo-500 transition-all outline-none resize-none min-h-[100px]"
|
| 455 |
+
/>
|
| 456 |
+
</motion.div>
|
| 457 |
|
| 458 |
+
{/* Custom Qualification Fields */}
|
| 459 |
+
<motion.div variants={item} className="bg-white rounded-2xl shadow-sm border border-slate-200 p-8">
|
| 460 |
+
<div className="flex items-center gap-3 mb-6">
|
| 461 |
+
<div className="p-2 bg-indigo-50 rounded-xl text-indigo-600">
|
| 462 |
+
<Brain className="w-6 h-6" />
|
| 463 |
+
</div>
|
| 464 |
+
<div>
|
| 465 |
+
<h2 className="text-xl font-bold text-slate-900">Поля квалификации</h2>
|
| 466 |
+
<p className="text-sm text-slate-500">Какую информацию AI должен собирать о клиентах</p>
|
| 467 |
+
</div>
|
| 468 |
</div>
|
| 469 |
+
|
| 470 |
+
<div className="flex flex-wrap gap-2 mb-6">
|
| 471 |
+
{settings.custom_fields.map((field) => (
|
| 472 |
+
<div
|
| 473 |
+
key={field}
|
| 474 |
+
className="inline-flex items-center gap-2 px-3 py-1.5 bg-indigo-50 text-indigo-700 border border-indigo-100 rounded-lg text-sm font-medium"
|
| 475 |
+
>
|
| 476 |
+
<span>{field}</span>
|
| 477 |
+
<button
|
| 478 |
+
onClick={() => removeCustomField(field)}
|
| 479 |
+
className="hover:bg-indigo-200 rounded-md p-0.5 transition-colors"
|
| 480 |
+
>
|
| 481 |
+
<X className="w-3.5 h-3.5" />
|
| 482 |
+
</button>
|
| 483 |
+
</div>
|
| 484 |
+
))}
|
| 485 |
</div>
|
|
|
|
| 486 |
|
| 487 |
+
<div className="flex gap-3">
|
| 488 |
+
<input
|
| 489 |
+
type="text"
|
| 490 |
+
value={newField}
|
| 491 |
+
onChange={(e) => setNewField(e.target.value)}
|
| 492 |
+
onKeyDown={(e) => e.key === 'Enter' && addCustomField()}
|
| 493 |
+
placeholder="Например: Регион, Количество сотрудников..."
|
| 494 |
+
className="flex-1 px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-indigo-500/20 focus:border-indigo-500 transition-all outline-none"
|
| 495 |
+
/>
|
| 496 |
+
<button
|
| 497 |
+
onClick={addCustomField}
|
| 498 |
+
className="px-6 py-3 bg-indigo-600 hover:bg-indigo-700 text-white rounded-xl font-bold shadow-lg hover:shadow-indigo-500/25 transition-all flex items-center gap-2"
|
| 499 |
>
|
| 500 |
+
<Plus className="w-5 h-5" />
|
| 501 |
+
Добавить
|
| 502 |
+
</button>
|
| 503 |
+
</div>
|
| 504 |
+
</motion.div>
|
| 505 |
+
|
| 506 |
+
{/* Custom Instructions */}
|
| 507 |
+
<motion.div variants={item} className="bg-white rounded-2xl shadow-sm border border-slate-200 p-8">
|
| 508 |
+
<div className="flex items-center gap-3 mb-6">
|
| 509 |
+
<div className="p-2 bg-emerald-50 rounded-xl text-emerald-600">
|
| 510 |
+
<Award className="w-6 h-6" />
|
| 511 |
</div>
|
| 512 |
+
<div>
|
| 513 |
+
<h2 className="text-xl font-bold text-slate-900">Правила поведения (Global Prompt)</h2>
|
| 514 |
+
<p className="text-sm text-slate-500">Специальные инструкции для AI</p>
|
| 515 |
+
</div>
|
| 516 |
+
</div>
|
| 517 |
|
| 518 |
+
<textarea
|
| 519 |
+
value={persona.custom_instructions}
|
| 520 |
+
onChange={(e) => setPersona({ ...persona, custom_instructions: e.target.value })}
|
| 521 |
+
placeholder="Например: - Никогда не говори цену до выяснения бюджета - Всегда упоминай наше УТП: внедрение за 1 день - Если клиент сравнивает с конкурентами, подчеркни скорость"
|
| 522 |
+
className="w-full px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-emerald-500/20 focus:border-emerald-500 transition-all outline-none resize-none min-h-[150px] font-mono text-sm"
|
|
|
|
|
|
|
|
|
|
| 523 |
/>
|
| 524 |
+
</motion.div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 525 |
|
| 526 |
+
{/* Banned Words */}
|
| 527 |
+
<motion.div variants={item} className="bg-white rounded-2xl shadow-sm border border-slate-200 p-8">
|
| 528 |
+
<div className="flex items-center gap-3 mb-6">
|
| 529 |
+
<div className="p-2 bg-red-50 rounded-xl text-red-600">
|
| 530 |
+
<Ban className="w-6 h-6" />
|
| 531 |
+
</div>
|
| 532 |
+
<div>
|
| 533 |
+
<h2 className="text-xl font-bold text-slate-900">Запрещенные слова</h2>
|
| 534 |
+
<p className="text-sm text-slate-500">Слова и фразы, которые AI никогда не должен использовать</p>
|
| 535 |
+
</div>
|
| 536 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 537 |
|
| 538 |
+
<div className="flex flex-wrap gap-2 mb-6">
|
| 539 |
+
{persona.banned_words.map((word) => (
|
| 540 |
+
<div
|
| 541 |
+
key={word}
|
| 542 |
+
className="inline-flex items-center gap-2 px-3 py-1.5 bg-red-50 text-red-700 border border-red-100 rounded-lg text-sm font-medium"
|
| 543 |
+
>
|
| 544 |
+
<span>{word}</span>
|
| 545 |
+
<button
|
| 546 |
+
onClick={() => removeBannedWord(word)}
|
| 547 |
+
className="hover:bg-red-200 rounded-md p-0.5 transition-colors"
|
| 548 |
+
>
|
| 549 |
+
<X className="w-3.5 h-3.5" />
|
| 550 |
+
</button>
|
| 551 |
+
</div>
|
| 552 |
+
))}
|
| 553 |
</div>
|
|
|
|
| 554 |
|
| 555 |
+
<div className="flex gap-3">
|
| 556 |
+
<input
|
| 557 |
+
type="text"
|
| 558 |
+
value={newBannedWord}
|
| 559 |
+
onChange={(e) => setNewBannedWord(e.target.value)}
|
| 560 |
+
onKeyDown={(e) => e.key === 'Enter' && addBannedWord()}
|
| 561 |
+
placeholder="Например: дешево, бесплатно, скидка..."
|
| 562 |
+
className="flex-1 px-4 py-3 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-red-500/20 focus:border-red-500 transition-all outline-none"
|
| 563 |
+
/>
|
| 564 |
+
<button
|
| 565 |
+
onClick={addBannedWord}
|
| 566 |
+
className="px-6 py-3 bg-red-600 hover:bg-red-700 text-white rounded-xl font-bold shadow-lg hover:shadow-red-500/25 transition-all flex items-center gap-2"
|
| 567 |
>
|
| 568 |
+
<Plus className="w-5 h-5" />
|
| 569 |
+
Добавить
|
| 570 |
+
</button>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 571 |
</div>
|
| 572 |
+
</motion.div>
|
| 573 |
+
|
| 574 |
+
{/* ROI Calculator Settings */}
|
| 575 |
+
<motion.div variants={item} className="bg-gradient-to-br from-emerald-50 to-teal-50 rounded-2xl border border-emerald-100 p-8 shadow-sm">
|
| 576 |
+
<div className="flex items-center gap-3 mb-6">
|
| 577 |
+
<div className="p-2 bg-emerald-100 rounded-xl text-emerald-600">
|
| 578 |
+
<Calculator className="w-6 h-6" />
|
| 579 |
+
</div>
|
| 580 |
+
<div>
|
| 581 |
+
<h2 className="text-xl font-bold text-slate-900">Настройки ROI (Калькулятор выгоды)</h2>
|
| 582 |
+
<p className="text-sm text-slate-600">Настройте расчёт экономии от AI</p>
|
| 583 |
+
</div>
|
| 584 |
</div>
|
|
|
|
| 585 |
|
| 586 |
+
<div>
|
| 587 |
+
<label className="block text-sm font-bold text-slate-700 mb-2">
|
| 588 |
+
<div className="flex items-center gap-2">
|
| 589 |
+
<DollarSign className="w-4 h-4 text-emerald-600" />
|
| 590 |
+
Средняя зарплата менеджера (USD/месяц)
|
| 591 |
+
</div>
|
| 592 |
+
</label>
|
| 593 |
+
<input
|
| 594 |
+
type="number"
|
| 595 |
+
min="0"
|
| 596 |
+
step="100"
|
| 597 |
+
value={persona.manager_monthly_salary}
|
| 598 |
+
onChange={(e) => setPersona({ ...persona, manager_monthly_salary: parseInt(e.target.value) || 1000 })}
|
| 599 |
+
className="w-full md:w-64 px-4 py-3 bg-white border border-emerald-200 rounded-xl focus:ring-2 focus:ring-emerald-500/20 focus:border-emerald-500 transition-all outline-none font-semibold text-emerald-900"
|
| 600 |
+
placeholder="1000"
|
| 601 |
+
/>
|
| 602 |
+
<div className="mt-3 flex items-start gap-2 text-xs text-emerald-700 bg-emerald-100/50 p-3 rounded-lg border border-emerald-100">
|
| 603 |
+
<AlertCircle className="w-4 h-4 mt-0.5 flex-shrink-0" />
|
| 604 |
+
<p>
|
| 605 |
+
Мы рассчитываем почасовую ставку (зарплата / 160 часов) и экономию времени AI (3 мин на сообщение).
|
| 606 |
+
</p>
|
| 607 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 608 |
</div>
|
| 609 |
+
</motion.div>
|
|
|
|
| 610 |
|
| 611 |
+
{/* Save Button */}
|
| 612 |
+
<motion.div variants={item} className="flex justify-end pt-4 pb-12">
|
| 613 |
+
<button
|
| 614 |
+
onClick={handleSave}
|
| 615 |
+
disabled={saving}
|
| 616 |
+
className="px-8 py-4 bg-gradient-to-r from-indigo-600 to-purple-600 hover:from-indigo-500 hover:to-purple-500 text-white rounded-xl font-bold shadow-xl hover:shadow-2xl hover:-translate-y-1 transition-all duration-300 flex items-center gap-3 disabled:opacity-50 disabled:cursor-not-allowed disabled:transform-none"
|
| 617 |
+
>
|
| 618 |
+
{saving ? (
|
| 619 |
+
<>
|
| 620 |
+
<Loader2 className="w-6 h-6 animate-spin" />
|
| 621 |
+
Сохранение...
|
| 622 |
+
</>
|
| 623 |
+
) : (
|
| 624 |
+
<>
|
| 625 |
+
<Save className="w-6 h-6" />
|
| 626 |
+
Сохранить настройки
|
| 627 |
+
</>
|
| 628 |
+
)}
|
| 629 |
+
</button>
|
| 630 |
+
</motion.div>
|
| 631 |
</motion.div>
|
| 632 |
+
)}
|
| 633 |
</div>
|
| 634 |
</div>
|
| 635 |
)
|
frontend/components/BookingSettings.tsx
ADDED
|
@@ -0,0 +1,174 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
'use client'
|
| 2 |
+
|
| 3 |
+
import { useState, useEffect } from 'react'
|
| 4 |
+
import { Calendar, Clock, Loader2, Save, CheckCircle2 } from 'lucide-react'
|
| 5 |
+
import { motion } from 'framer-motion'
|
| 6 |
+
import { cn } from '@/lib/utils'
|
| 7 |
+
|
| 8 |
+
interface BookingSettingsProps {
|
| 9 |
+
settings: any
|
| 10 |
+
onSave: (settings: any) => Promise<void>
|
| 11 |
+
loading?: boolean
|
| 12 |
+
}
|
| 13 |
+
|
| 14 |
+
const DEFAULT_SETTINGS = {
|
| 15 |
+
working_days: ['mon', 'tue', 'wed', 'thu', 'fri'],
|
| 16 |
+
working_hours: {
|
| 17 |
+
start: '09:00',
|
| 18 |
+
end: '18:00'
|
| 19 |
+
},
|
| 20 |
+
slot_duration: 30, // minutes
|
| 21 |
+
timezone: 'Europe/Moscow' // default
|
| 22 |
+
}
|
| 23 |
+
|
| 24 |
+
const DAYS = [
|
| 25 |
+
{ id: 'mon', label: 'Пн' },
|
| 26 |
+
{ id: 'tue', label: 'Вт' },
|
| 27 |
+
{ id: 'wed', label: 'Ср' },
|
| 28 |
+
{ id: 'thu', label: 'Чт' },
|
| 29 |
+
{ id: 'fri', label: 'Пт' },
|
| 30 |
+
{ id: 'sat', label: 'Сб' },
|
| 31 |
+
{ id: 'sun', label: 'Вс' }
|
| 32 |
+
]
|
| 33 |
+
|
| 34 |
+
export default function BookingSettings({ settings, onSave, loading }: BookingSettingsProps) {
|
| 35 |
+
const [localSettings, setLocalSettings] = useState(DEFAULT_SETTINGS)
|
| 36 |
+
const [isSaving, setIsSaving] = useState(false)
|
| 37 |
+
|
| 38 |
+
useEffect(() => {
|
| 39 |
+
if (settings) {
|
| 40 |
+
setLocalSettings({ ...DEFAULT_SETTINGS, ...settings })
|
| 41 |
+
}
|
| 42 |
+
}, [settings])
|
| 43 |
+
|
| 44 |
+
const handleSave = async () => {
|
| 45 |
+
setIsSaving(true)
|
| 46 |
+
await onSave(localSettings)
|
| 47 |
+
setIsSaving(false)
|
| 48 |
+
}
|
| 49 |
+
|
| 50 |
+
const toggleDay = (dayId: string) => {
|
| 51 |
+
const currentDays = localSettings.working_days || []
|
| 52 |
+
const newDays = currentDays.includes(dayId)
|
| 53 |
+
? currentDays.filter(d => d !== dayId)
|
| 54 |
+
: [...currentDays, dayId]
|
| 55 |
+
|
| 56 |
+
setLocalSettings({ ...localSettings, working_days: newDays })
|
| 57 |
+
}
|
| 58 |
+
|
| 59 |
+
return (
|
| 60 |
+
<div className="bg-white rounded-2xl shadow-sm border border-slate-200 p-8">
|
| 61 |
+
<div className="flex items-center gap-3 mb-6">
|
| 62 |
+
<div className="p-2 bg-blue-50 rounded-xl text-blue-600">
|
| 63 |
+
<Calendar className="w-6 h-6" />
|
| 64 |
+
</div>
|
| 65 |
+
<div>
|
| 66 |
+
<h2 className="text-xl font-bold text-slate-900">Настройки записи</h2>
|
| 67 |
+
<p className="text-sm text-slate-500">Укажите ваше рабочее время для AI ассистента</p>
|
| 68 |
+
</div>
|
| 69 |
+
</div>
|
| 70 |
+
|
| 71 |
+
<div className="space-y-8">
|
| 72 |
+
{/* Working Days */}
|
| 73 |
+
<div>
|
| 74 |
+
<label className="block text-sm font-bold text-slate-700 mb-3">Рабочие дни</label>
|
| 75 |
+
<div className="flex gap-2">
|
| 76 |
+
{DAYS.map((day) => {
|
| 77 |
+
const isSelected = localSettings.working_days?.includes(day.id)
|
| 78 |
+
return (
|
| 79 |
+
<button
|
| 80 |
+
key={day.id}
|
| 81 |
+
onClick={() => toggleDay(day.id)}
|
| 82 |
+
className={cn(
|
| 83 |
+
"w-10 h-10 rounded-lg font-medium transition-all flex items-center justify-center border-2",
|
| 84 |
+
isSelected
|
| 85 |
+
? "bg-blue-600 border-blue-600 text-white shadow-md shadow-blue-200"
|
| 86 |
+
: "bg-white border-slate-200 text-slate-600 hover:border-blue-300 hover:bg-blue-50"
|
| 87 |
+
)}
|
| 88 |
+
>
|
| 89 |
+
{day.label}
|
| 90 |
+
</button>
|
| 91 |
+
)
|
| 92 |
+
})}
|
| 93 |
+
</div>
|
| 94 |
+
</div>
|
| 95 |
+
|
| 96 |
+
{/* Working Hours */}
|
| 97 |
+
<div className="grid grid-cols-2 gap-6">
|
| 98 |
+
<div>
|
| 99 |
+
<label className="block text-sm font-bold text-slate-700 mb-2">Начало работы</label>
|
| 100 |
+
<div className="relative">
|
| 101 |
+
<Clock className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400" />
|
| 102 |
+
<input
|
| 103 |
+
type="time"
|
| 104 |
+
value={localSettings.working_hours?.start || '09:00'}
|
| 105 |
+
onChange={(e) => setLocalSettings({
|
| 106 |
+
...localSettings,
|
| 107 |
+
working_hours: { ...localSettings.working_hours, start: e.target.value }
|
| 108 |
+
})}
|
| 109 |
+
className="w-full pl-10 pr-4 py-2 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-blue-500/20 focus:border-blue-500 outline-none"
|
| 110 |
+
/>
|
| 111 |
+
</div>
|
| 112 |
+
</div>
|
| 113 |
+
<div>
|
| 114 |
+
<label className="block text-sm font-bold text-slate-700 mb-2">Конец работы</label>
|
| 115 |
+
<div className="relative">
|
| 116 |
+
<Clock className="absolute left-3 top-1/2 -translate-y-1/2 w-4 h-4 text-slate-400" />
|
| 117 |
+
<input
|
| 118 |
+
type="time"
|
| 119 |
+
value={localSettings.working_hours?.end || '18:00'}
|
| 120 |
+
onChange={(e) => setLocalSettings({
|
| 121 |
+
...localSettings,
|
| 122 |
+
working_hours: { ...localSettings.working_hours, end: e.target.value }
|
| 123 |
+
})}
|
| 124 |
+
className="w-full pl-10 pr-4 py-2 bg-slate-50 border border-slate-200 rounded-xl focus:ring-2 focus:ring-blue-500/20 focus:border-blue-500 outline-none"
|
| 125 |
+
/>
|
| 126 |
+
</div>
|
| 127 |
+
</div>
|
| 128 |
+
</div>
|
| 129 |
+
|
| 130 |
+
{/* Slot Duration */}
|
| 131 |
+
<div>
|
| 132 |
+
<label className="block text-sm font-bold text-slate-700 mb-3">Длительность встречи (минут)</label>
|
| 133 |
+
<div className="flex gap-3">
|
| 134 |
+
{[15, 30, 45, 60].map((duration) => (
|
| 135 |
+
<button
|
| 136 |
+
key={duration}
|
| 137 |
+
onClick={() => setLocalSettings({ ...localSettings, slot_duration: duration })}
|
| 138 |
+
className={cn(
|
| 139 |
+
"px-4 py-2 rounded-lg font-medium transition-all border-2",
|
| 140 |
+
localSettings.slot_duration === duration
|
| 141 |
+
? "bg-blue-50 border-blue-600 text-blue-700"
|
| 142 |
+
: "bg-white border-slate-200 text-slate-600 hover:border-blue-300"
|
| 143 |
+
)}
|
| 144 |
+
>
|
| 145 |
+
{duration} мин
|
| 146 |
+
</button>
|
| 147 |
+
))}
|
| 148 |
+
</div>
|
| 149 |
+
</div>
|
| 150 |
+
|
| 151 |
+
{/* Save Button */}
|
| 152 |
+
<div className="pt-4 flex justify-end">
|
| 153 |
+
<button
|
| 154 |
+
onClick={handleSave}
|
| 155 |
+
disabled={isSaving || loading}
|
| 156 |
+
className="px-6 py-3 bg-blue-600 hover:bg-blue-700 text-white rounded-xl font-bold shadow-lg hover:shadow-blue-500/25 transition-all flex items-center gap-2 disabled:opacity-50"
|
| 157 |
+
>
|
| 158 |
+
{isSaving ? (
|
| 159 |
+
<>
|
| 160 |
+
<Loader2 className="w-5 h-5 animate-spin" />
|
| 161 |
+
Сохранение...
|
| 162 |
+
</>
|
| 163 |
+
) : (
|
| 164 |
+
<>
|
| 165 |
+
<Save className="w-5 h-5" />
|
| 166 |
+
Сохранить расписание
|
| 167 |
+
</>
|
| 168 |
+
)}
|
| 169 |
+
</button>
|
| 170 |
+
</div>
|
| 171 |
+
</div>
|
| 172 |
+
</div>
|
| 173 |
+
)
|
| 174 |
+
}
|