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>> {
try {
const mapper: ICustomerDomainMapper = this._registry.getDomainMapper({
resource: "customer-invoice",
resource: "customer",
});
const dto = mapper.mapToPersistence(customer);

View File

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

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 { PageHeader } from '@erp/core/components';
import { UnsavedChangesProvider, UpdateCommitButtonGroup, useHookForm } from "@erp/core/hooks";
import { showErrorToast, showSuccessToast } from "@repo/rdx-ui/helpers";
import { FieldErrors, FormProvider } from "react-hook-form";
@ -61,19 +62,13 @@ export const CustomerCreatePage = () => {
};
return (
<>
<AppBreadcrumb />
<AppContent>
<UnsavedChangesProvider isDirty={form.formState.isDirty}>
<div className='flex items-center justify-between space-y-6'>
<div className='space-y-2'>
<h2 className='text-2xl font-bold tracking-tight text-balance scroll-m-2'>
{t("pages.create.title")}
</h2>
<p className='text-muted-foreground scroll-m-20 tracking-tight text-balance'>
{t("pages.create.description")}
</p>
</div>
<UnsavedChangesProvider isDirty={form.formState.isDirty}>
<AppHeader>
<PageHeader
backIcon
title={t("pages.create.title")}
description={t("pages.create.description")}
rightSlot={
<UpdateCommitButtonGroup
isLoading={isCreating}
disabled={isCreating}
@ -87,27 +82,31 @@ export const CustomerCreatePage = () => {
}}
onBack={() => handleBack()}
/>
</div>
{/* Alerta de error de actualización (si ha fallado el último intento) */}
{isCreateError && (
<ErrorAlert
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.")
}
/>
)}
}
/>
</AppHeader>
<AppContent>
{/* Alerta de error de actualización (si ha fallado el último intento) */}
{isCreateError && (
<ErrorAlert
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>
</>
</UnsavedChangesProvider>
);
};