refactor: simplificar Por Categoría — sin toggle, greeting_flow directo

- Eliminar checkbox 'Pedir finca al inicio': innecesario porque el
  dynamic_list ya auto-selecciona cuando solo hay 1 opción (finca, empresa, etc.)
- greeting_flow controla si hay flujo de bienvenida; si está vacío → greeting_menu
- Si greeting_flow tiene valor → greeting='' (dispara el flow) y se oculta greeting_menu
- Hint text explica que con 1 sola opción se auto-selecciona sin preguntar
- save-per-type deriva greeting/greeting_menu del greeting_flow, no de un toggle

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Lizandro Guarnizo
2026-07-30 23:19:50 -05:00
co-authored by Claude Sonnet 4.6
parent 909c6be32f
commit fe048f53a3
2 changed files with 28 additions and 51 deletions
+13 -35
View File
@@ -3215,10 +3215,7 @@ HTML;
foreach ([1, 2, 3] as $cat) {
$catCfg = $perTypeConfig[(string)$cat] ?? [];
$m = $catMeta[(string)$cat];
$greetingVal = array_key_exists('greeting', $catCfg) ? $catCfg['greeting'] : null;
$askFinca = $greetingVal !== null;
$chk = $askFinca ? ' checked' : '';
$greetFlow = self::h($catCfg['greeting_flow'] ?? ($askFinca ? 'ask_finca' : ''));
$greetFlow = self::h($catCfg['greeting_flow'] ?? '');
$fallback = $catCfg['fallback_flow'] ?? '';
$selMenu = $catCfg['greeting_menu'] ?? '';
@@ -3235,8 +3232,10 @@ HTML;
$flowOptsBase
);
$greetFlowStyle = $askFinca ? '' : 'display:none';
$greetMenuStyle = $askFinca ? 'display:none' : '';
// Mostrar greeting_menu solo cuando NO hay greeting_flow (cat 1)
$hasGreetFlow = $greetFlow !== '';
$greetFlowStyle = '';
$greetMenuStyle = $hasGreetFlow ? 'display:none' : '';
$label = $m['label']; $icon = $m['icon']; $bg = $m['bg']; $bd = $m['bd']; $clr = $m['clr'];
$categoryTabHtml .= <<<CATHTML
@@ -3245,26 +3244,21 @@ HTML;
<span style="font-size:20px">{$icon}</span>
<span style="font-weight:700;font-size:13px;color:{$clr}">{$label}</span>
</div>
<div class="form-group" style="margin-bottom:12px">
<label style="display:flex;align-items:center;gap:8px;font-weight:500">
<input type="checkbox" name="per_type_ask_finca[{$cat}]" value="1"{$chk} onchange="toggleAskFinca(this,{$cat})">
Pedir selección de finca al inicio
</label>
<div style="font-size:11px;color:#7a8291;margin-top:3px">Al activarlo, el bot solicita la finca antes de mostrar el menú principal</div>
</div>
<div id="cat-greet-flow-{$cat}" style="{$greetFlowStyle}" class="form-group" style="margin-bottom:12px">
<div class="form-group" style="{$greetFlowStyle};margin-bottom:12px">
<label>Flujo de bienvenida</label>
<input type="text" name="per_type_greeting_flow[{$cat}]" value="{$greetFlow}"
list="ptFlowsDatalist" placeholder="ej: ask_finca"
list="ptFlowsDatalist" placeholder="ej: ask_finca (se auto-selecciona si hay 1 sola opción)"
style="width:100%;padding:8px 12px;border:1px solid #e2e5ea;border-radius:8px;font-size:13px">
<div style="font-size:11px;color:#7a8291;margin-top:3px">Flow que se ejecuta en el primer mensaje del usuario</div>
<div style="font-size:11px;color:#7a8291;margin-top:3px">
Flow que se ejecuta al primer mensaje. Si el flow retorna 1 sola opción (finca, empresa, etc.) la selecciona automáticamente sin preguntar.
</div>
</div>
<div id="cat-greet-menu-{$cat}" style="{$greetMenuStyle}" class="form-group" style="margin-bottom:12px">
<label>Menú inicial</label>
<select name="per_type_menu[{$cat}]" style="width:100%;padding:9px 12px;border:1px solid #e2e5ea;border-radius:8px;font-size:13px">
{$menuOpts}
</select>
<div style="font-size:11px;color:#7a8291;margin-top:3px">Menú que se muestra cuando el usuario no tiene contexto activo</div>
<div style="font-size:11px;color:#7a8291;margin-top:3px">Menú que se muestra cuando no hay flujo de bienvenida configurado</div>
</div>
<div class="form-group" style="margin-bottom:0">
<label>Flujo de respaldo (fallback)</label>
@@ -3911,32 +3905,16 @@ HTML;
const CONFIG = {$botConfigJson};
const ENDPOINTS = {$botEndpointsJson};
function toggleAskFinca(chk, cat) {
var flowDiv = document.getElementById('cat-greet-flow-' + cat);
var menuDiv = document.getElementById('cat-greet-menu-' + cat);
if (chk.checked) {
if (flowDiv) flowDiv.style.display = '';
if (menuDiv) menuDiv.style.display = 'none';
var gf = document.querySelector('[name="per_type_greeting_flow[' + cat + ']"]');
if (gf && gf.value === '') gf.value = 'ask_finca';
} else {
if (flowDiv) flowDiv.style.display = 'none';
if (menuDiv) menuDiv.style.display = '';
}
}
function savePerType() {
const cid = document.querySelector('input[name="company_id"]').value;
const fd = new FormData();
fd.set('company_id', cid);
[1, 2, 3].forEach(function(cat) {
var chk = document.querySelector('[name="per_type_ask_finca[' + cat + ']"]');
fd.append('per_type_ask_finca[' + cat + ']', chk && chk.checked ? '1' : '0');
var gf = document.querySelector('[name="per_type_greeting_flow[' + cat + ']"]');
if (gf) fd.append('per_type_greeting_flow[' + cat + ']', gf.value);
var sel = document.querySelector('[name="per_type_menu[' + cat + ']"]');
if (sel) fd.append('per_type_menu[' + cat + ']', sel.value);
var fb = document.querySelector('[name="per_type_fallback[' + cat + ']"]');
if (gf) fd.append('per_type_greeting_flow[' + cat + ']', gf.value);
if (sel) fd.append('per_type_menu[' + cat + ']', sel.value);
if (fb) fd.append('per_type_fallback[' + cat + ']', fb.value);
});
var btn = document.getElementById('savePerTypeBtn');
+5 -6
View File
@@ -664,7 +664,6 @@ $routes = [
$perType = (is_array($rawPt) && count(array_filter(array_keys($rawPt), 'is_string')) > 0)
? $rawPt : [];
$ptAskFinca = $_POST['per_type_ask_finca'] ?? [];
$ptGreetFlow = $_POST['per_type_greeting_flow'] ?? [];
$ptMenus = $_POST['per_type_menu'] ?? [];
$ptFallback = $_POST['per_type_fallback'] ?? [];
@@ -673,14 +672,14 @@ $routes = [
$key = (string)$cat;
$current = $perType[$key] ?? []; // preserve menus/flows/commands from seed
$askFinca = ($ptAskFinca[$cat] ?? '0') === '1';
if ($askFinca) {
$gf = trim($ptGreetFlow[$cat] ?? 'ask_finca');
$gf = trim($ptGreetFlow[$cat] ?? '');
if ($gf !== '') {
// Si tiene greeting_flow → greeting='' para que el flow se dispare al primer mensaje
$current['greeting'] = '';
$current['greeting_flow'] = $gf !== '' ? $gf : 'ask_finca';
$current['greeting_flow'] = $gf;
unset($current['greeting_menu']);
} else {
// Sin greeting_flow → usa greeting_menu (cat 1)
$current['greeting'] = null;
unset($current['greeting_flow']);
$mk = trim($ptMenus[$cat] ?? '');