This commit is contained in:
David Arranz 2025-10-20 12:36:25 +02:00
parent c69a7cd142
commit cad3a403b9
3 changed files with 60 additions and 64 deletions

View File

@ -58,7 +58,7 @@ export class CustomerRepository
async update(customer: Customer, transaction?: Transaction): Promise<Result<void, Error>> { async update(customer: Customer, transaction?: Transaction): Promise<Result<void, Error>> {
try { try {
const mapper: ICustomerDomainMapper = this._registry.getDomainMapper({ const mapper: ICustomerDomainMapper = this._registry.getDomainMapper({
resource: "customer-invoice", resource: "customer",
}); });
const dto = mapper.mapToPersistence(customer); const dto = mapper.mapToPersistence(customer);

View File

@ -3,7 +3,7 @@ import {
TextField TextField
} from "@repo/rdx-ui/components"; } from "@repo/rdx-ui/components";
import { import {
Field, FieldDescription, FieldGroup, FieldLegend, FieldSet, FormControl, Field, FieldDescription, FieldGroup, FieldLabel, FieldLegend, FieldSet, FormControl,
FormField, FormField,
FormItem, FormItem,
FormLabel, FormLabel,
@ -11,7 +11,7 @@ import {
RadioGroup, RadioGroup,
RadioGroupItem RadioGroupItem
} from '@repo/shadcn-ui/components'; } from '@repo/shadcn-ui/components';
import { Controller, useFormContext, useWatch } from "react-hook-form"; import { Controller, useFormContext } from "react-hook-form";
import { CustomerInvoiceTaxesMultiSelect } from '../../../../../customer-invoices/src/web/components'; import { CustomerInvoiceTaxesMultiSelect } from '../../../../../customer-invoices/src/web/components';
import { useTranslation } from "../../i18n"; import { useTranslation } from "../../i18n";
import { CustomerFormData } from "../../schemas"; import { CustomerFormData } from "../../schemas";
@ -20,12 +20,6 @@ export const CustomerBasicInfoFields = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const { control } = useFormContext<CustomerFormData>(); const { control } = useFormContext<CustomerFormData>();
const isCompany = useWatch({
control,
name: "is_company",
defaultValue: "true",
});
return ( return (
<FieldSet> <FieldSet>
<FieldLegend>{t("form_groups.basic_info.title")}</FieldLegend> <FieldLegend>{t("form_groups.basic_info.title")}</FieldLegend>
@ -80,18 +74,15 @@ export const CustomerBasicInfoFields = () => {
/> />
</Field> </Field>
{isCompany === "false" ? (
<TextField <TextField
className='lg:col-span-full' className='lg:col-span-full'
control={control} control={control}
name='trade_name' name='trade_name'
label={t("form_fields.trade_name.label")} label={t("form_fields.trade_name.label")}
placeholder={t("form_fields.trade_name.placeholder")} placeholder={t("form_fields.trade_name.placeholder")}
description={t("form_fields.trade_name.description")} description={t("form_fields.trade_name.description")}
/> />
) : (
<></>
)}
<TextField <TextField
className='lg:col-span-2 lg:col-start-1' className='lg:col-span-2 lg:col-start-1'
@ -101,19 +92,25 @@ export const CustomerBasicInfoFields = () => {
placeholder={t("form_fields.reference.placeholder")} placeholder={t("form_fields.reference.placeholder")}
description={t("form_fields.reference.description")} description={t("form_fields.reference.description")}
/> />
<Field className='lg:col-span-2'> <Field className='lg:col-span-2'>
<Controller <Controller
control={control} control={control}
name='default_taxes' name='default_taxes'
render={({ field }) => ( render={({ field, fieldState }) => (
<CustomerInvoiceTaxesMultiSelect <Field data-invalid={fieldState.invalid} className={"gap-1"}>
value={field.value} <FieldLabel className='text-xs text-muted-foreground text-nowrap' htmlFor={"default_taxes"}>
onChange={field.onChange} {t("form_fields.default_taxes.label")}
required </FieldLabel>
label={t("form_fields.default_taxes.label")} <CustomerInvoiceTaxesMultiSelect
placeholder={t("form_fields.default_taxes.placeholder")} value={field.value}
description={t("form_fields.default_taxes.description")} onChange={field.onChange}
/> required
label={t("form_fields.default_taxes.label")}
placeholder={t("form_fields.default_taxes.placeholder")}
description={t("form_fields.default_taxes.description")}
/>
</Field>
)} )}
/> />
</Field> </Field>

View File

@ -1,6 +1,7 @@
import { AppBreadcrumb, AppContent } from "@repo/rdx-ui/components"; import { AppContent, AppHeader } from "@repo/rdx-ui/components";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { PageHeader } from '@erp/core/components';
import { UnsavedChangesProvider, UpdateCommitButtonGroup, useHookForm } from "@erp/core/hooks"; import { UnsavedChangesProvider, UpdateCommitButtonGroup, useHookForm } from "@erp/core/hooks";
import { showErrorToast, showSuccessToast } from "@repo/rdx-ui/helpers"; import { showErrorToast, showSuccessToast } from "@repo/rdx-ui/helpers";
import { FieldErrors, FormProvider } from "react-hook-form"; import { FieldErrors, FormProvider } from "react-hook-form";
@ -61,19 +62,13 @@ export const CustomerCreatePage = () => {
}; };
return ( return (
<> <UnsavedChangesProvider isDirty={form.formState.isDirty}>
<AppBreadcrumb /> <AppHeader>
<AppContent> <PageHeader
<UnsavedChangesProvider isDirty={form.formState.isDirty}> backIcon
<div className='flex items-center justify-between space-y-6'> title={t("pages.create.title")}
<div className='space-y-2'> description={t("pages.create.description")}
<h2 className='text-2xl font-bold tracking-tight text-balance scroll-m-2'> rightSlot={
{t("pages.create.title")}
</h2>
<p className='text-muted-foreground scroll-m-20 tracking-tight text-balance'>
{t("pages.create.description")}
</p>
</div>
<UpdateCommitButtonGroup <UpdateCommitButtonGroup
isLoading={isCreating} isLoading={isCreating}
disabled={isCreating} disabled={isCreating}
@ -87,27 +82,31 @@ export const CustomerCreatePage = () => {
}} }}
onBack={() => handleBack()} onBack={() => handleBack()}
/> />
</div> }
{/* Alerta de error de actualización (si ha fallado el último intento) */} />
{isCreateError && ( </AppHeader>
<ErrorAlert <AppContent>
title={t("pages.create.errorTitle", "No se pudo guardar los cambios")} {/* Alerta de error de actualización (si ha fallado el último intento) */}
message={ {isCreateError && (
(createError as Error)?.message ?? <ErrorAlert
t("pages.create.errorMsg", "Revisa los datos e inténtalo de nuevo.") title={t("pages.create.errorTitle", "No se pudo guardar los cambios")}
} message={
/> (createError as Error)?.message ??
)} t("pages.create.errorMsg", "Revisa los datos e inténtalo de nuevo.")
}
/>
)}
<FormProvider {...form}>
<CustomerEditForm
formId='customer-create-form'
onSubmit={handleSubmit}
onError={handleError}
className="bg-white rounded-xl border shadow-xl max-w-7xl mx-auto"
/>
</FormProvider>
<FormProvider {...form}>
<CustomerEditForm
formId='customer-create-form'
onSubmit={handleSubmit}
onError={handleError}
/>
</FormProvider>
</UnsavedChangesProvider>
</AppContent> </AppContent>
</> </UnsavedChangesProvider>
); );
}; };