Spaces:
Running
Running
axeronis commited on
Commit ·
cb4b8d4
1
Parent(s): 4c9faf8
fix: unify qualification fields management logic between frontend and backend
Browse files
backend/app/api/playbook.py
CHANGED
|
@@ -522,11 +522,11 @@ async def get_custom_fields(
|
|
| 522 |
detail="Tenant not found"
|
| 523 |
)
|
| 524 |
|
| 525 |
-
# Extract qualification_fields from ai_settings
|
| 526 |
default_fields = ["Имя", "Контакт", "Бюджет", "Срочность"]
|
| 527 |
|
| 528 |
if tenant.ai_settings and isinstance(tenant.ai_settings, dict):
|
| 529 |
-
#
|
| 530 |
custom_fields = tenant.ai_settings.get("qualification_fields") or tenant.ai_settings.get("custom_fields", default_fields)
|
| 531 |
else:
|
| 532 |
custom_fields = default_fields
|
|
|
|
| 522 |
detail="Tenant not found"
|
| 523 |
)
|
| 524 |
|
| 525 |
+
# Extract qualification_fields from ai_settings
|
| 526 |
default_fields = ["Имя", "Контакт", "Бюджет", "Срочность"]
|
| 527 |
|
| 528 |
if tenant.ai_settings and isinstance(tenant.ai_settings, dict):
|
| 529 |
+
# We exclusively use qualification_fields now, with fallback to legacy custom_fields
|
| 530 |
custom_fields = tenant.ai_settings.get("qualification_fields") or tenant.ai_settings.get("custom_fields", default_fields)
|
| 531 |
else:
|
| 532 |
custom_fields = default_fields
|
backend/app/api/tenants.py
CHANGED
|
@@ -200,6 +200,11 @@ async def update_my_tenant(
|
|
| 200 |
# Update fields
|
| 201 |
if request.ai_settings is not None:
|
| 202 |
current_settings = tenant.ai_settings or {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 203 |
current_settings.update(request.ai_settings)
|
| 204 |
tenant.ai_settings = current_settings
|
| 205 |
|
|
@@ -485,6 +490,11 @@ async def update_tenant(
|
|
| 485 |
if request.ai_settings is not None:
|
| 486 |
# Merge new settings provided
|
| 487 |
current_settings = tenant.ai_settings or {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 488 |
current_settings.update(request.ai_settings)
|
| 489 |
tenant.ai_settings = current_settings
|
| 490 |
|
|
|
|
| 200 |
# Update fields
|
| 201 |
if request.ai_settings is not None:
|
| 202 |
current_settings = tenant.ai_settings or {}
|
| 203 |
+
|
| 204 |
+
# MIGRATION: If incoming data has custom_fields, move it to qualification_fields
|
| 205 |
+
if "custom_fields" in request.ai_settings:
|
| 206 |
+
request.ai_settings["qualification_fields"] = request.ai_settings.pop("custom_fields")
|
| 207 |
+
|
| 208 |
current_settings.update(request.ai_settings)
|
| 209 |
tenant.ai_settings = current_settings
|
| 210 |
|
|
|
|
| 490 |
if request.ai_settings is not None:
|
| 491 |
# Merge new settings provided
|
| 492 |
current_settings = tenant.ai_settings or {}
|
| 493 |
+
|
| 494 |
+
# MIGRATION: If incoming data has custom_fields, move it to qualification_fields
|
| 495 |
+
if "custom_fields" in request.ai_settings:
|
| 496 |
+
request.ai_settings["qualification_fields"] = request.ai_settings.pop("custom_fields")
|
| 497 |
+
|
| 498 |
current_settings.update(request.ai_settings)
|
| 499 |
tenant.ai_settings = current_settings
|
| 500 |
|
frontend/app/settings/brain/page.tsx
CHANGED
|
@@ -22,7 +22,7 @@ import { useTranslation } from '@/lib/i18n'
|
|
| 22 |
interface AISettings {
|
| 23 |
business_description: string
|
| 24 |
selling_style: 'Consultative' | 'Aggressive' | 'Friendly' | 'Educational'
|
| 25 |
-
|
| 26 |
ideal_customer_profile: string
|
| 27 |
}
|
| 28 |
|
|
@@ -105,7 +105,7 @@ export default function BrainSettingsPage() {
|
|
| 105 |
const [settings, setSettings] = useState<AISettings>({
|
| 106 |
business_description: '',
|
| 107 |
selling_style: 'Consultative',
|
| 108 |
-
|
| 109 |
ideal_customer_profile: ''
|
| 110 |
})
|
| 111 |
|
|
@@ -144,7 +144,7 @@ export default function BrainSettingsPage() {
|
|
| 144 |
business_description: aiSettings.business_description || '',
|
| 145 |
selling_style: aiSettings.selling_style || 'Consultative',
|
| 146 |
// Use qualification_fields (new) or custom_fields (legacy) or empty array
|
| 147 |
-
|
| 148 |
ideal_customer_profile: aiSettings.ideal_customer_profile || ''
|
| 149 |
})
|
| 150 |
setPersona({
|
|
@@ -299,13 +299,13 @@ export default function BrainSettingsPage() {
|
|
| 299 |
if (delimiters.test(input)) {
|
| 300 |
// Multiple fields detected - split and add all
|
| 301 |
const fields = input.split(delimiters).map(f => f.trim()).filter(Boolean)
|
| 302 |
-
const existingFields = settings.
|
| 303 |
const newFields = fields.filter(f => !existingFields.includes(f))
|
| 304 |
|
| 305 |
if (newFields.length > 0) {
|
| 306 |
setSettings({
|
| 307 |
...settings,
|
| 308 |
-
|
| 309 |
})
|
| 310 |
toast.success('Добавлено', `${newFields.length} поле(й) добавлено`)
|
| 311 |
} else {
|
|
@@ -313,13 +313,13 @@ export default function BrainSettingsPage() {
|
|
| 313 |
}
|
| 314 |
} else {
|
| 315 |
// Single field
|
| 316 |
-
if (settings.
|
| 317 |
toast.error('Ошибка', 'Это поле уже добавлено')
|
| 318 |
return
|
| 319 |
}
|
| 320 |
setSettings({
|
| 321 |
...settings,
|
| 322 |
-
|
| 323 |
})
|
| 324 |
}
|
| 325 |
setNewField('')
|
|
@@ -328,7 +328,7 @@ export default function BrainSettingsPage() {
|
|
| 328 |
const removeCustomField = (field: string) => {
|
| 329 |
setSettings({
|
| 330 |
...settings,
|
| 331 |
-
|
| 332 |
})
|
| 333 |
}
|
| 334 |
|
|
@@ -1212,7 +1212,7 @@ export default function BrainSettingsPage() {
|
|
| 1212 |
</div>
|
| 1213 |
|
| 1214 |
<div className="flex flex-wrap gap-2 mb-6">
|
| 1215 |
-
{(settings.
|
| 1216 |
<div
|
| 1217 |
key={field}
|
| 1218 |
className="inline-flex items-center gap-2 px-3 py-1.5 bg-indigo-500/20 text-indigo-700 border border-indigo-100 rounded-lg text-sm font-medium"
|
|
|
|
| 22 |
interface AISettings {
|
| 23 |
business_description: string
|
| 24 |
selling_style: 'Consultative' | 'Aggressive' | 'Friendly' | 'Educational'
|
| 25 |
+
qualification_fields: string[]
|
| 26 |
ideal_customer_profile: string
|
| 27 |
}
|
| 28 |
|
|
|
|
| 105 |
const [settings, setSettings] = useState<AISettings>({
|
| 106 |
business_description: '',
|
| 107 |
selling_style: 'Consultative',
|
| 108 |
+
qualification_fields: [], // Empty by default - user must configure
|
| 109 |
ideal_customer_profile: ''
|
| 110 |
})
|
| 111 |
|
|
|
|
| 144 |
business_description: aiSettings.business_description || '',
|
| 145 |
selling_style: aiSettings.selling_style || 'Consultative',
|
| 146 |
// Use qualification_fields (new) or custom_fields (legacy) or empty array
|
| 147 |
+
qualification_fields: aiSettings.qualification_fields || aiSettings.custom_fields || [],
|
| 148 |
ideal_customer_profile: aiSettings.ideal_customer_profile || ''
|
| 149 |
})
|
| 150 |
setPersona({
|
|
|
|
| 299 |
if (delimiters.test(input)) {
|
| 300 |
// Multiple fields detected - split and add all
|
| 301 |
const fields = input.split(delimiters).map(f => f.trim()).filter(Boolean)
|
| 302 |
+
const existingFields = settings.qualification_fields
|
| 303 |
const newFields = fields.filter(f => !existingFields.includes(f))
|
| 304 |
|
| 305 |
if (newFields.length > 0) {
|
| 306 |
setSettings({
|
| 307 |
...settings,
|
| 308 |
+
qualification_fields: [...existingFields, ...newFields]
|
| 309 |
})
|
| 310 |
toast.success('Добавлено', `${newFields.length} поле(й) добавлено`)
|
| 311 |
} else {
|
|
|
|
| 313 |
}
|
| 314 |
} else {
|
| 315 |
// Single field
|
| 316 |
+
if (settings.qualification_fields.includes(input)) {
|
| 317 |
toast.error('Ошибка', 'Это поле уже добавлено')
|
| 318 |
return
|
| 319 |
}
|
| 320 |
setSettings({
|
| 321 |
...settings,
|
| 322 |
+
qualification_fields: [...settings.qualification_fields, input]
|
| 323 |
})
|
| 324 |
}
|
| 325 |
setNewField('')
|
|
|
|
| 328 |
const removeCustomField = (field: string) => {
|
| 329 |
setSettings({
|
| 330 |
...settings,
|
| 331 |
+
qualification_fields: settings.qualification_fields.filter(f => f !== field)
|
| 332 |
})
|
| 333 |
}
|
| 334 |
|
|
|
|
| 1212 |
</div>
|
| 1213 |
|
| 1214 |
<div className="flex flex-wrap gap-2 mb-6">
|
| 1215 |
+
{(settings.qualification_fields || []).map((field) => (
|
| 1216 |
<div
|
| 1217 |
key={field}
|
| 1218 |
className="inline-flex items-center gap-2 px-3 py-1.5 bg-indigo-500/20 text-indigo-700 border border-indigo-100 rounded-lg text-sm font-medium"
|