Facturas de cliente
This commit is contained in:
parent
06d5b269d1
commit
d6b2370cf1
@ -19,6 +19,7 @@ export function useHookForm<TFields extends FieldValues = FieldValues, TContext
|
||||
onDirtyChange,
|
||||
...rest
|
||||
}: UseHookFormProps<TFields, TContext>): UseFormReturn<TFields> {
|
||||
|
||||
const form = useForm<TFields, TContext>({
|
||||
...rest,
|
||||
resolver: zodResolver(resolverSchema),
|
||||
|
||||
@ -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<CustomerInvoiceFormData>();
|
||||
const { control, getValues } = useFormContext();
|
||||
|
||||
const recipient = useWatch({
|
||||
control,
|
||||
name: "recipient",
|
||||
defaultValue: "",
|
||||
});
|
||||
|
||||
const recipient = getValues('recipient');
|
||||
|
||||
return (
|
||||
<Fieldset>
|
||||
@ -26,7 +22,7 @@ export const InvoiceRecipient = () => {
|
||||
<RecipientModalSelectorField
|
||||
control={control}
|
||||
name='customer_id'
|
||||
initialRecipient='recipient'
|
||||
initialRecipient={recipient}
|
||||
/>
|
||||
</FieldGroup>
|
||||
</Fieldset>
|
||||
|
||||
@ -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<TFormValues extends FieldValues> = {
|
||||
required?: boolean;
|
||||
readOnly?: boolean;
|
||||
className?: string;
|
||||
initialRecipient?: unknown;
|
||||
};
|
||||
|
||||
export function RecipientModalSelectorField<TFormValues extends FieldValues>({
|
||||
@ -19,10 +21,12 @@ export function RecipientModalSelectorField<TFormValues extends FieldValues>({
|
||||
required = false,
|
||||
readOnly = false,
|
||||
className,
|
||||
initialRecipient = {},
|
||||
}: CustomerModalSelectorFieldProps<TFormValues>) {
|
||||
const isDisabled = disabled;
|
||||
const isReadOnly = readOnly && !disabled;
|
||||
|
||||
|
||||
return (
|
||||
<FormField
|
||||
control={control}
|
||||
@ -36,6 +40,9 @@ export function RecipientModalSelectorField<TFormValues extends FieldValues>({
|
||||
value={value}
|
||||
onValueChange={onChange}
|
||||
className='bg-fuchsia-200'
|
||||
initialCustomer={{
|
||||
...initialRecipient as CustomerSummary
|
||||
}}
|
||||
/>
|
||||
</FormItem>
|
||||
);
|
||||
|
||||
@ -47,7 +47,8 @@ export const CustomerInvoiceUpdatePage = () => {
|
||||
} = useUpdateCustomerInvoice();
|
||||
|
||||
// 3) Form hook
|
||||
const form = useHookForm<CustomerInvoiceFormData, CustomerInvoice>({
|
||||
|
||||
const form = useHookForm<CustomerInvoice>({
|
||||
resolverSchema: CustomerInvoiceFormSchema,
|
||||
initialValues: invoiceData ?? defaultCustomerInvoiceFormData,
|
||||
disabled: isUpdating,
|
||||
@ -171,7 +172,6 @@ export const CustomerInvoiceUpdatePage = () => {
|
||||
onSubmit={handleSubmit}
|
||||
onError={handleError}
|
||||
className='max-w-full'
|
||||
initialValues={invoiceData}
|
||||
/>
|
||||
</FormProvider>
|
||||
</AppContent>
|
||||
|
||||
@ -36,7 +36,7 @@ export const CustomerModalSelector = ({
|
||||
const debouncedQuery = useDebouncedValue(searchQuery, 300);
|
||||
|
||||
// Cliente seleccionado y creación local optimista
|
||||
const [selected, setSelected] = useState<CustomerSummary | null>(null);
|
||||
const [selected, setSelected] = useState<CustomerSummary | null>(initialCustomer ?? null);
|
||||
const [newClient, setNewClient] =
|
||||
useState<Omit<CustomerSummary, "id" | "status" | "company_id">>(defaultCustomerFormData);
|
||||
const [localCreated, setLocalCreated] = useState<CustomerSummary[]>([]);
|
||||
|
||||
@ -79,9 +79,7 @@ export function DatePickerInputComp<TFormValues extends FieldValues>({
|
||||
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<TFormValues extends FieldValues>({
|
||||
const [inputError, setInputError] = useState<string | null>(null);
|
||||
|
||||
const handleDisplayValueChange = (value: string) => {
|
||||
console.log("handleDisplayValueChange => ", value)
|
||||
setDisplayValue(value);
|
||||
setInputError(null);
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user