@@ -6,6 +6,12 @@ import type { DatosGeneralesField } from '@/types/plan'
|
|||||||
|
|
||||||
import { Button } from '@/components/ui/button'
|
import { Button } from '@/components/ui/button'
|
||||||
import { Textarea } from '@/components/ui/textarea'
|
import { Textarea } from '@/components/ui/textarea'
|
||||||
|
import {
|
||||||
|
Tooltip,
|
||||||
|
TooltipContent,
|
||||||
|
TooltipProvider,
|
||||||
|
TooltipTrigger,
|
||||||
|
} from '@/components/ui/tooltip'
|
||||||
import { usePlan } from '@/data'
|
import { usePlan } from '@/data'
|
||||||
// import { toast } from 'sonner' // Asegúrate de tener sonner instalado o quita la línea
|
// import { toast } from 'sonner' // Asegúrate de tener sonner instalado o quita la línea
|
||||||
export const Route = createFileRoute('/planes/$planId/_detalle/datos')({
|
export const Route = createFileRoute('/planes/$planId/_detalle/datos')({
|
||||||
@@ -28,24 +34,41 @@ function DatosGeneralesPage() {
|
|||||||
|
|
||||||
// Efecto para transformar data?.datos en el arreglo de campos
|
// Efecto para transformar data?.datos en el arreglo de campos
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// 2. Validación de seguridad para sourceData
|
const properties = data?.estructuras_plan?.definicion?.properties
|
||||||
const sourceData = data?.datos
|
|
||||||
|
|
||||||
if (sourceData && typeof sourceData === 'object') {
|
const valores = data?.datos as Record<string, unknown>
|
||||||
|
|
||||||
|
if (properties && typeof properties === 'object') {
|
||||||
const datosTransformados: Array<DatosGeneralesField> = Object.entries(
|
const datosTransformados: Array<DatosGeneralesField> = Object.entries(
|
||||||
sourceData,
|
properties,
|
||||||
).map(([key, value], index) => ({
|
).map(([key, schema], index) => {
|
||||||
|
const rawValue = valores[key]
|
||||||
|
|
||||||
|
return {
|
||||||
id: (index + 1).toString(),
|
id: (index + 1).toString(),
|
||||||
label: formatLabel(key),
|
label: schema?.title || formatLabel(key),
|
||||||
// Forzamos el valor a string de forma segura
|
helperText: schema?.description || '',
|
||||||
value: typeof value === 'string' ? value : value?.toString() || '',
|
holder: schema?.examples || '',
|
||||||
|
value:
|
||||||
|
rawValue !== undefined && rawValue !== null ? String(rawValue) : '',
|
||||||
|
|
||||||
requerido: true,
|
requerido: true,
|
||||||
tipo: 'texto',
|
|
||||||
}))
|
// 👇 TIPO DE CAMPO
|
||||||
|
tipo: Array.isArray(schema?.enum)
|
||||||
|
? 'select'
|
||||||
|
: schema?.type === 'number'
|
||||||
|
? 'number'
|
||||||
|
: 'texto',
|
||||||
|
|
||||||
|
opciones: schema?.enum || [],
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
setCampos(datosTransformados)
|
setCampos(datosTransformados)
|
||||||
}
|
}
|
||||||
console.log(data)
|
|
||||||
|
console.log(properties)
|
||||||
}, [data])
|
}, [data])
|
||||||
|
|
||||||
// 3. Manejadores de acciones (Ahora como funciones locales)
|
// 3. Manejadores de acciones (Ahora como funciones locales)
|
||||||
@@ -105,11 +128,20 @@ function DatosGeneralesPage() {
|
|||||||
}`}
|
}`}
|
||||||
>
|
>
|
||||||
{/* Header de la Card */}
|
{/* Header de la Card */}
|
||||||
|
<TooltipProvider>
|
||||||
<div className="flex items-center justify-between border-b bg-slate-50/50 px-5 py-3">
|
<div className="flex items-center justify-between border-b bg-slate-50/50 px-5 py-3">
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
<h3 className="text-sm font-medium text-slate-700">
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<h3 className="cursor-help text-sm font-medium text-slate-700">
|
||||||
{campo.label}
|
{campo.label}
|
||||||
</h3>
|
</h3>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent className="max-w-xs text-xs">
|
||||||
|
{campo.helperText || 'Información del campo'}
|
||||||
|
</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
|
||||||
{campo.requerido && (
|
{campo.requerido && (
|
||||||
<span className="text-xs text-red-500">*</span>
|
<span className="text-xs text-red-500">*</span>
|
||||||
)}
|
)}
|
||||||
@@ -117,6 +149,8 @@ function DatosGeneralesPage() {
|
|||||||
|
|
||||||
{!isEditing && (
|
{!isEditing && (
|
||||||
<div className="flex gap-1">
|
<div className="flex gap-1">
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="icon"
|
size="icon"
|
||||||
@@ -125,6 +159,12 @@ function DatosGeneralesPage() {
|
|||||||
>
|
>
|
||||||
<Sparkles size={14} />
|
<Sparkles size={14} />
|
||||||
</Button>
|
</Button>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent>Generar con IA</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
|
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
<Button
|
<Button
|
||||||
variant="ghost"
|
variant="ghost"
|
||||||
size="icon"
|
size="icon"
|
||||||
@@ -133,9 +173,13 @@ function DatosGeneralesPage() {
|
|||||||
>
|
>
|
||||||
<Pencil size={14} />
|
<Pencil size={14} />
|
||||||
</Button>
|
</Button>
|
||||||
|
</TooltipTrigger>
|
||||||
|
<TooltipContent>Editar campo</TooltipContent>
|
||||||
|
</Tooltip>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
</TooltipProvider>
|
||||||
|
|
||||||
{/* Contenido de la Card */}
|
{/* Contenido de la Card */}
|
||||||
<div className="p-5">
|
<div className="p-5">
|
||||||
@@ -145,6 +189,7 @@ function DatosGeneralesPage() {
|
|||||||
value={editValue}
|
value={editValue}
|
||||||
onChange={(e) => setEditValue(e.target.value)}
|
onChange={(e) => setEditValue(e.target.value)}
|
||||||
className="min-h-[120px]"
|
className="min-h-[120px]"
|
||||||
|
placeholder={campo.holder}
|
||||||
/>
|
/>
|
||||||
<div className="flex justify-end gap-2">
|
<div className="flex justify-end gap-2">
|
||||||
<Button
|
<Button
|
||||||
|
|||||||
@@ -65,12 +65,15 @@ export interface Plan {
|
|||||||
estadoActual: PlanStatus
|
estadoActual: PlanStatus
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DatosGeneralesField {
|
export type DatosGeneralesField = {
|
||||||
id: string
|
id: string
|
||||||
label: string
|
label: string
|
||||||
|
helperText?: string
|
||||||
|
holder?: string
|
||||||
value: string
|
value: string
|
||||||
tipo: 'texto' | 'lista' | 'parrafo'
|
|
||||||
requerido: boolean
|
requerido: boolean
|
||||||
|
tipo: 'texto' | 'parrafo' | 'lista' | 'number' | 'select'
|
||||||
|
opciones?: Array<string>
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface CambioPlan {
|
export interface CambioPlan {
|
||||||
|
|||||||
Reference in New Issue
Block a user