FactuGES_ERP/modules/customers/src/web/components/form-debug.tsx

35 lines
1.0 KiB
TypeScript
Raw Normal View History

2025-09-18 09:46:25 +00:00
import { UseFormReturn } from "react-hook-form";
export const FormDebug = ({ form }: { form: UseFormReturn }) => {
const {
watch,
formState: { isDirty, dirtyFields, defaultValues },
} = form;
const currentValues = watch();
return (
2025-09-19 16:55:30 +00:00
<div className='p-4 border rounded bg-red-50 mb-6'>
2025-09-18 09:46:25 +00:00
<p>
<strong>¿Formulario modificado?</strong> {isDirty ? "Sí" : "No"}
</p>
<div className='mt-2'>
<strong>Campos modificados:</strong>
{Object.keys(dirtyFields).length > 0 ? (
<ul className='list-disc list-inside mt-1'>
{Object.keys(dirtyFields).map((campo) => (
<li key={campo}>
<span className='font-medium'>{campo}:</span>{" "}
<span className='text-gray-500 line-through'>{String(defaultValues![campo])}</span>{" "}
➝ <span className='text-green-600'>{String(currentValues[campo])}</span>
</li>
))}
</ul>
) : (
<p>Ninguno</p>
)}
</div>
</div>
);
};