@@ -87,27 +87,33 @@ function RouteComponent() {
|
|||||||
|
|
||||||
// 1. Transformar datos de la API para el menú de selección
|
// 1. Transformar datos de la API para el menú de selección
|
||||||
const availableFields = useMemo(() => {
|
const availableFields = useMemo(() => {
|
||||||
if (!data?.datos) return []
|
if (!data?.estructuras_plan?.definicion?.properties) return []
|
||||||
return Object.entries(data.datos).map(([key, value]) => ({
|
return Object.entries(data.estructuras_plan.definicion.properties).map(
|
||||||
key,
|
([key, value]) => ({
|
||||||
label: formatLabel(key),
|
key,
|
||||||
value: String(value || ''),
|
label: value.title,
|
||||||
}))
|
value: String(value.description || ''),
|
||||||
|
}),
|
||||||
|
)
|
||||||
}, [data])
|
}, [data])
|
||||||
|
|
||||||
// 2. Manejar el estado inicial si viene de "Datos Generales"
|
// 2. Manejar el estado inicial si viene de "Datos Generales"
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const state = routerState.location.state as any
|
const state = routerState.location.state as any
|
||||||
if (state?.prefill && availableFields.length > 0) {
|
if (!state?.campo_edit || availableFields.length === 0) return
|
||||||
// Intentamos encontrar qué campo es por su valor o si mandaste el fieldKey
|
|
||||||
const field = availableFields.find(
|
const field = availableFields.find(
|
||||||
(f) => f.value === state.prefill || f.key === state.fieldKey,
|
(f) =>
|
||||||
)
|
f.value === state.campo_edit.label || f.key === state.campo_edit.clave,
|
||||||
if (field && !selectedFields.find((sf) => sf.key === field.key)) {
|
)
|
||||||
setSelectedFields([field])
|
|
||||||
}
|
if (field && !selectedFields.some((sf) => sf.key === field.key)) {
|
||||||
setInput(`Mejora este campo: ${field?.label} `)
|
setSelectedFields([field])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setInput((prev) =>
|
||||||
|
injectFieldsIntoInput(prev || 'Mejora este campo:', field ? [field] : []),
|
||||||
|
)
|
||||||
}, [availableFields])
|
}, [availableFields])
|
||||||
|
|
||||||
// 3. Lógica para el disparador ":"
|
// 3. Lógica para el disparador ":"
|
||||||
@@ -127,7 +133,7 @@ function RouteComponent() {
|
|||||||
) => {
|
) => {
|
||||||
const baseText = input.replace(/\[[^\]]+]/g, '').trim()
|
const baseText = input.replace(/\[[^\]]+]/g, '').trim()
|
||||||
|
|
||||||
const tags = fields.map((f) => `[${f.label}]`).join(' ')
|
const tags = fields.map((f) => `${f.label}`).join(' ')
|
||||||
|
|
||||||
return `${baseText} ${tags}`.trim()
|
return `${baseText} ${tags}`.trim()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ function DatosGeneralesPage() {
|
|||||||
const rawValue = valores[key]
|
const rawValue = valores[key]
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
clave: key,
|
||||||
id: (index + 1).toString(),
|
id: (index + 1).toString(),
|
||||||
label: schema?.title || formatLabel(key),
|
label: schema?.title || formatLabel(key),
|
||||||
helperText: schema?.description || '',
|
helperText: schema?.description || '',
|
||||||
@@ -131,14 +132,16 @@ function DatosGeneralesPage() {
|
|||||||
// toast.success('Cambios guardados localmente')
|
// toast.success('Cambios guardados localmente')
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleIARequest = (descripcion: string) => {
|
const handleIARequest = (clave: string) => {
|
||||||
|
console.log(clave)
|
||||||
|
|
||||||
navigate({
|
navigate({
|
||||||
to: '/planes/$planId/iaplan',
|
to: '/planes/$planId/iaplan',
|
||||||
params: {
|
params: {
|
||||||
planId: planId, // o dinámico
|
planId: planId, // o dinámico
|
||||||
},
|
},
|
||||||
state: {
|
state: {
|
||||||
prefill: descripcion,
|
campo_edit: clave,
|
||||||
} as any,
|
} as any,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -154,8 +157,9 @@ function DatosGeneralesPage() {
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div className="grid grid-cols-1 gap-6 lg:grid-cols-2">
|
<div className="grid grid-cols-1 gap-6 lg:grid-cols-2">
|
||||||
{campos.map((campo) => {
|
{campos.map((campo, key) => {
|
||||||
const isEditing = editingId === campo.id
|
const isEditing = editingId === campo.id
|
||||||
|
console.log(campo)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
@@ -194,7 +198,7 @@ function DatosGeneralesPage() {
|
|||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="icon"
|
size="icon"
|
||||||
className="h-8 w-8 text-teal-600"
|
className="h-8 w-8 text-teal-600"
|
||||||
onClick={() => handleIARequest(campo.value)}
|
onClick={() => handleIARequest(campo)}
|
||||||
>
|
>
|
||||||
<Sparkles size={14} />
|
<Sparkles size={14} />
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
Reference in New Issue
Block a user