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,
|
onDirtyChange,
|
||||||
...rest
|
...rest
|
||||||
}: UseHookFormProps<TFields, TContext>): UseFormReturn<TFields> {
|
}: UseHookFormProps<TFields, TContext>): UseFormReturn<TFields> {
|
||||||
|
|
||||||
const form = useForm<TFields, TContext>({
|
const form = useForm<TFields, TContext>({
|
||||||
...rest,
|
...rest,
|
||||||
resolver: zodResolver(resolverSchema),
|
resolver: zodResolver(resolverSchema),
|
||||||
|
|||||||
@ -1,20 +1,16 @@
|
|||||||
import { Description, FieldGroup, Fieldset, Legend } from "@repo/rdx-ui/components";
|
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 { UserIcon } from "lucide-react";
|
||||||
import { useTranslation } from "../../../i18n";
|
import { useTranslation } from "../../../i18n";
|
||||||
import { CustomerInvoiceFormData } from "../../../schemas";
|
|
||||||
import { RecipientModalSelectorField } from "./recipient-modal-selector-field";
|
import { RecipientModalSelectorField } from "./recipient-modal-selector-field";
|
||||||
|
|
||||||
export const InvoiceRecipient = () => {
|
export const InvoiceRecipient = () => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { control } = useFormContext<CustomerInvoiceFormData>();
|
const { control, getValues } = useFormContext();
|
||||||
|
|
||||||
const recipient = useWatch({
|
|
||||||
control,
|
const recipient = getValues('recipient');
|
||||||
name: "recipient",
|
|
||||||
defaultValue: "",
|
|
||||||
});
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Fieldset>
|
<Fieldset>
|
||||||
@ -26,7 +22,7 @@ export const InvoiceRecipient = () => {
|
|||||||
<RecipientModalSelectorField
|
<RecipientModalSelectorField
|
||||||
control={control}
|
control={control}
|
||||||
name='customer_id'
|
name='customer_id'
|
||||||
initialRecipient='recipient'
|
initialRecipient={recipient}
|
||||||
/>
|
/>
|
||||||
</FieldGroup>
|
</FieldGroup>
|
||||||
</Fieldset>
|
</Fieldset>
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import { CustomerModalSelector } from "@erp/customers/components";
|
import { CustomerModalSelector } from "@erp/customers/components";
|
||||||
import { FormField, FormItem } from "@repo/shadcn-ui/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";
|
import { Control, FieldPath, FieldValues } from "react-hook-form";
|
||||||
|
|
||||||
@ -10,6 +11,7 @@ type CustomerModalSelectorFieldProps<TFormValues extends FieldValues> = {
|
|||||||
required?: boolean;
|
required?: boolean;
|
||||||
readOnly?: boolean;
|
readOnly?: boolean;
|
||||||
className?: string;
|
className?: string;
|
||||||
|
initialRecipient?: unknown;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function RecipientModalSelectorField<TFormValues extends FieldValues>({
|
export function RecipientModalSelectorField<TFormValues extends FieldValues>({
|
||||||
@ -19,10 +21,12 @@ export function RecipientModalSelectorField<TFormValues extends FieldValues>({
|
|||||||
required = false,
|
required = false,
|
||||||
readOnly = false,
|
readOnly = false,
|
||||||
className,
|
className,
|
||||||
|
initialRecipient = {},
|
||||||
}: CustomerModalSelectorFieldProps<TFormValues>) {
|
}: CustomerModalSelectorFieldProps<TFormValues>) {
|
||||||
const isDisabled = disabled;
|
const isDisabled = disabled;
|
||||||
const isReadOnly = readOnly && !disabled;
|
const isReadOnly = readOnly && !disabled;
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<FormField
|
<FormField
|
||||||
control={control}
|
control={control}
|
||||||
@ -36,6 +40,9 @@ export function RecipientModalSelectorField<TFormValues extends FieldValues>({
|
|||||||
value={value}
|
value={value}
|
||||||
onValueChange={onChange}
|
onValueChange={onChange}
|
||||||
className='bg-fuchsia-200'
|
className='bg-fuchsia-200'
|
||||||
|
initialCustomer={{
|
||||||
|
...initialRecipient as CustomerSummary
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</FormItem>
|
</FormItem>
|
||||||
);
|
);
|
||||||
|
|||||||
@ -47,7 +47,8 @@ export const CustomerInvoiceUpdatePage = () => {
|
|||||||
} = useUpdateCustomerInvoice();
|
} = useUpdateCustomerInvoice();
|
||||||
|
|
||||||
// 3) Form hook
|
// 3) Form hook
|
||||||
const form = useHookForm<CustomerInvoiceFormData, CustomerInvoice>({
|
|
||||||
|
const form = useHookForm<CustomerInvoice>({
|
||||||
resolverSchema: CustomerInvoiceFormSchema,
|
resolverSchema: CustomerInvoiceFormSchema,
|
||||||
initialValues: invoiceData ?? defaultCustomerInvoiceFormData,
|
initialValues: invoiceData ?? defaultCustomerInvoiceFormData,
|
||||||
disabled: isUpdating,
|
disabled: isUpdating,
|
||||||
@ -171,7 +172,6 @@ export const CustomerInvoiceUpdatePage = () => {
|
|||||||
onSubmit={handleSubmit}
|
onSubmit={handleSubmit}
|
||||||
onError={handleError}
|
onError={handleError}
|
||||||
className='max-w-full'
|
className='max-w-full'
|
||||||
initialValues={invoiceData}
|
|
||||||
/>
|
/>
|
||||||
</FormProvider>
|
</FormProvider>
|
||||||
</AppContent>
|
</AppContent>
|
||||||
|
|||||||
@ -36,7 +36,7 @@ export const CustomerModalSelector = ({
|
|||||||
const debouncedQuery = useDebouncedValue(searchQuery, 300);
|
const debouncedQuery = useDebouncedValue(searchQuery, 300);
|
||||||
|
|
||||||
// Cliente seleccionado y creación local optimista
|
// 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] =
|
const [newClient, setNewClient] =
|
||||||
useState<Omit<CustomerSummary, "id" | "status" | "company_id">>(defaultCustomerFormData);
|
useState<Omit<CustomerSummary, "id" | "status" | "company_id">>(defaultCustomerFormData);
|
||||||
const [localCreated, setLocalCreated] = useState<CustomerSummary[]>([]);
|
const [localCreated, setLocalCreated] = useState<CustomerSummary[]>([]);
|
||||||
|
|||||||
@ -79,9 +79,7 @@ export function DatePickerInputComp<TFormValues extends FieldValues>({
|
|||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (field.value) {
|
if (field.value) {
|
||||||
// field.value ya viene en formato parseDateFormat
|
// field.value ya viene en formato parseDateFormat
|
||||||
console.log(field.value, parseDateFormat);
|
|
||||||
const parsed = parse(field.value, parseDateFormat, new Date());
|
const parsed = parse(field.value, parseDateFormat, new Date());
|
||||||
console.log("parsed =>", parsed);
|
|
||||||
if (isValid(parsed)) {
|
if (isValid(parsed)) {
|
||||||
setDisplayValue(format(parsed, displayDateFormat));
|
setDisplayValue(format(parsed, displayDateFormat));
|
||||||
}
|
}
|
||||||
@ -93,7 +91,6 @@ export function DatePickerInputComp<TFormValues extends FieldValues>({
|
|||||||
const [inputError, setInputError] = useState<string | null>(null);
|
const [inputError, setInputError] = useState<string | null>(null);
|
||||||
|
|
||||||
const handleDisplayValueChange = (value: string) => {
|
const handleDisplayValueChange = (value: string) => {
|
||||||
console.log("handleDisplayValueChange => ", value)
|
|
||||||
setDisplayValue(value);
|
setDisplayValue(value);
|
||||||
setInputError(null);
|
setInputError(null);
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user