From d6b2370cf140214c3e05ac84e509fe2cd0e860ed Mon Sep 17 00:00:00 2001 From: david Date: Thu, 2 Oct 2025 19:14:45 +0200 Subject: [PATCH] Facturas de cliente --- .../src/web/hooks/use-hook-form/use-hook-form.ts | 1 + .../editor/recipient/invoice-recipient.tsx | 14 +++++--------- .../recipient/recipient-modal-selector-field.tsx | 7 +++++++ .../pages/update/customer-invoices-update-page.tsx | 4 ++-- .../customer-modal-selector.tsx | 2 +- .../date-picker-input-comp.tsx | 3 --- 6 files changed, 16 insertions(+), 15 deletions(-) diff --git a/modules/core/src/web/hooks/use-hook-form/use-hook-form.ts b/modules/core/src/web/hooks/use-hook-form/use-hook-form.ts index 1fd33a75..8056c894 100644 --- a/modules/core/src/web/hooks/use-hook-form/use-hook-form.ts +++ b/modules/core/src/web/hooks/use-hook-form/use-hook-form.ts @@ -19,6 +19,7 @@ export function useHookForm): UseFormReturn { + const form = useForm({ ...rest, resolver: zodResolver(resolverSchema), diff --git a/modules/customer-invoices/src/web/components/editor/recipient/invoice-recipient.tsx b/modules/customer-invoices/src/web/components/editor/recipient/invoice-recipient.tsx index 8ff420b8..827c1838 100644 --- a/modules/customer-invoices/src/web/components/editor/recipient/invoice-recipient.tsx +++ b/modules/customer-invoices/src/web/components/editor/recipient/invoice-recipient.tsx @@ -1,20 +1,16 @@ import { Description, FieldGroup, Fieldset, Legend } from "@repo/rdx-ui/components"; -import { useFormContext, useWatch } from "react-hook-form"; +import { useFormContext } from "react-hook-form"; import { UserIcon } from "lucide-react"; import { useTranslation } from "../../../i18n"; -import { CustomerInvoiceFormData } from "../../../schemas"; import { RecipientModalSelectorField } from "./recipient-modal-selector-field"; export const InvoiceRecipient = () => { const { t } = useTranslation(); - const { control } = useFormContext(); + const { control, getValues } = useFormContext(); - const recipient = useWatch({ - control, - name: "recipient", - defaultValue: "", - }); + + const recipient = getValues('recipient'); return (
@@ -26,7 +22,7 @@ export const InvoiceRecipient = () => {
diff --git a/modules/customer-invoices/src/web/components/editor/recipient/recipient-modal-selector-field.tsx b/modules/customer-invoices/src/web/components/editor/recipient/recipient-modal-selector-field.tsx index 8f2b09f7..43e5aecb 100644 --- a/modules/customer-invoices/src/web/components/editor/recipient/recipient-modal-selector-field.tsx +++ b/modules/customer-invoices/src/web/components/editor/recipient/recipient-modal-selector-field.tsx @@ -1,5 +1,6 @@ import { CustomerModalSelector } from "@erp/customers/components"; import { FormField, FormItem } from "@repo/shadcn-ui/components"; +import { CustomerSummary } from 'node_modules/@erp/customers/src/web/schemas'; import { Control, FieldPath, FieldValues } from "react-hook-form"; @@ -10,6 +11,7 @@ type CustomerModalSelectorFieldProps = { required?: boolean; readOnly?: boolean; className?: string; + initialRecipient?: unknown; }; export function RecipientModalSelectorField({ @@ -19,10 +21,12 @@ export function RecipientModalSelectorField({ required = false, readOnly = false, className, + initialRecipient = {}, }: CustomerModalSelectorFieldProps) { const isDisabled = disabled; const isReadOnly = readOnly && !disabled; + return ( ({ value={value} onValueChange={onChange} className='bg-fuchsia-200' + initialCustomer={{ + ...initialRecipient as CustomerSummary + }} /> ); diff --git a/modules/customer-invoices/src/web/pages/update/customer-invoices-update-page.tsx b/modules/customer-invoices/src/web/pages/update/customer-invoices-update-page.tsx index 7f9ee9dc..7e7948b4 100644 --- a/modules/customer-invoices/src/web/pages/update/customer-invoices-update-page.tsx +++ b/modules/customer-invoices/src/web/pages/update/customer-invoices-update-page.tsx @@ -47,7 +47,8 @@ export const CustomerInvoiceUpdatePage = () => { } = useUpdateCustomerInvoice(); // 3) Form hook - const form = useHookForm({ + + const form = useHookForm({ resolverSchema: CustomerInvoiceFormSchema, initialValues: invoiceData ?? defaultCustomerInvoiceFormData, disabled: isUpdating, @@ -171,7 +172,6 @@ export const CustomerInvoiceUpdatePage = () => { onSubmit={handleSubmit} onError={handleError} className='max-w-full' - initialValues={invoiceData} /> diff --git a/modules/customers/src/web/components/customer-modal-selector/customer-modal-selector.tsx b/modules/customers/src/web/components/customer-modal-selector/customer-modal-selector.tsx index c84f09bb..14d6ee3b 100644 --- a/modules/customers/src/web/components/customer-modal-selector/customer-modal-selector.tsx +++ b/modules/customers/src/web/components/customer-modal-selector/customer-modal-selector.tsx @@ -36,7 +36,7 @@ export const CustomerModalSelector = ({ const debouncedQuery = useDebouncedValue(searchQuery, 300); // Cliente seleccionado y creación local optimista - const [selected, setSelected] = useState(null); + const [selected, setSelected] = useState(initialCustomer ?? null); const [newClient, setNewClient] = useState>(defaultCustomerFormData); const [localCreated, setLocalCreated] = useState([]); diff --git a/packages/rdx-ui/src/components/form/date-picker-input-field/date-picker-input-comp.tsx b/packages/rdx-ui/src/components/form/date-picker-input-field/date-picker-input-comp.tsx index fc3a5706..1ef0dab4 100644 --- a/packages/rdx-ui/src/components/form/date-picker-input-field/date-picker-input-comp.tsx +++ b/packages/rdx-ui/src/components/form/date-picker-input-field/date-picker-input-comp.tsx @@ -79,9 +79,7 @@ export function DatePickerInputComp({ useEffect(() => { if (field.value) { // field.value ya viene en formato parseDateFormat - console.log(field.value, parseDateFormat); const parsed = parse(field.value, parseDateFormat, new Date()); - console.log("parsed =>", parsed); if (isValid(parsed)) { setDisplayValue(format(parsed, displayDateFormat)); } @@ -93,7 +91,6 @@ export function DatePickerInputComp({ const [inputError, setInputError] = useState(null); const handleDisplayValueChange = (value: string) => { - console.log("handleDisplayValueChange => ", value) setDisplayValue(value); setInputError(null); };