diff --git a/modules/core/src/common/locales/en.json b/modules/core/src/common/locales/en.json index 8af37c72..f7cb7d25 100644 --- a/modules/core/src/common/locales/en.json +++ b/modules/core/src/common/locales/en.json @@ -1,6 +1,6 @@ { "common": { - "required": "required" + "required": "•" }, "components": { "taxes_multi_select": { diff --git a/modules/core/src/common/locales/es.json b/modules/core/src/common/locales/es.json index a59dc5b2..5a768fe3 100644 --- a/modules/core/src/common/locales/es.json +++ b/modules/core/src/common/locales/es.json @@ -1,6 +1,6 @@ { "common": { - "required": "requerido" + "required": "•" }, "components": { "taxes_multi_select": { diff --git a/modules/core/src/web/components/form/taxes-multi-select-field.tsx b/modules/core/src/web/components/form/taxes-multi-select-field.tsx index a629de84..6d4e4509 100644 --- a/modules/core/src/web/components/form/taxes-multi-select-field.tsx +++ b/modules/core/src/web/components/form/taxes-multi-select-field.tsx @@ -47,9 +47,15 @@ export function TaxesMultiSelectField({ render={({ field }) => ( {label && ( -
- {label} - {required && {t("common.required")}} +
+
+ + {label} + + {required && ( + {t("common.required")} + )} +
)} diff --git a/modules/customers/src/api/application/presenters/domain/customer.full.presenter.ts b/modules/customers/src/api/application/presenters/domain/customer.full.presenter.ts index cc3dfd8e..9cc7662b 100644 --- a/modules/customers/src/api/application/presenters/domain/customer.full.presenter.ts +++ b/modules/customers/src/api/application/presenters/domain/customer.full.presenter.ts @@ -39,7 +39,7 @@ export class CustomerFullPresenter extends Presenter value.toPrimitive()), - default_taxes: customer.defaultTaxes.getAll().join(", "), + default_taxes: customer.defaultTaxes.getAll().map((tax) => tax.toString()), status: customer.isActive ? "active" : "inactive", language_code: customer.languageCode.toPrimitive(), diff --git a/modules/customers/src/api/application/use-cases/update/map-dto-to-update-customer-props.ts b/modules/customers/src/api/application/use-cases/update/map-dto-to-update-customer-props.ts index 294fe828..0dd55699 100644 --- a/modules/customers/src/api/application/use-cases/update/map-dto-to-update-customer-props.ts +++ b/modules/customers/src/api/application/use-cases/update/map-dto-to-update-customer-props.ts @@ -1,4 +1,11 @@ -import { DomainError, ValidationErrorCollection, ValidationErrorDetail } from "@repo/rdx-ddd"; +import { + DomainError, + ValidationErrorCollection, + ValidationErrorDetail, + extractOrPushError, +} from "@repo/rdx-ddd"; +import { UpdateCustomerByIdRequestDTO } from "../../../../common"; +import { CustomerPatchProps } from "../../../domain"; import { City, @@ -34,7 +41,7 @@ import { Collection, Result, isNullishOrEmpty, toPatchField } from "@repo/rdx-ut * */ -export function mapDTOToUpdateCustomerPatchProps(dto: UpdateCustomerRequestDTO) { +export function mapDTOToUpdateCustomerPatchProps(dto: UpdateCustomerByIdRequestDTO) { try { const errors: ValidationErrorDetail[] = []; const customerPatchProps: CustomerPatchProps = {}; @@ -83,18 +90,50 @@ export function mapDTOToUpdateCustomerPatchProps(dto: UpdateCustomerRequestDTO) ); }); - toPatchField(dto.email).ifSet((email) => { - customerPatchProps.email = extractOrPushError( - maybeFromNullableVO(email, (value) => EmailAddress.create(value)), - "email", + toPatchField(dto.email_primary).ifSet((email_primary) => { + customerPatchProps.emailPrimary = extractOrPushError( + maybeFromNullableVO(email_primary, (value) => EmailAddress.create(value)), + "email_primary", errors ); }); - toPatchField(dto.phone).ifSet((phone) => { - customerPatchProps.phone = extractOrPushError( - maybeFromNullableVO(phone, (value) => PhoneNumber.create(value)), - "phone", + toPatchField(dto.email_secondary).ifSet((email_secondary) => { + customerPatchProps.emailSecondary = extractOrPushError( + maybeFromNullableVO(email_secondary, (value) => EmailAddress.create(value)), + "email_secondary", + errors + ); + }); + + toPatchField(dto.mobile_primary).ifSet((mobile_primary) => { + customerPatchProps.mobilePrimary = extractOrPushError( + maybeFromNullableVO(mobile_primary, (value) => PhoneNumber.create(value)), + "mobile_primary", + errors + ); + }); + + toPatchField(dto.mobile_secondary).ifSet((mobile_secondary) => { + customerPatchProps.mobilePrimary = extractOrPushError( + maybeFromNullableVO(mobile_secondary, (value) => PhoneNumber.create(value)), + "mobile_secondary", + errors + ); + }); + + toPatchField(dto.phone_primary).ifSet((phone_primary) => { + customerPatchProps.phonePrimary = extractOrPushError( + maybeFromNullableVO(phone_primary, (value) => PhoneNumber.create(value)), + "phone_primary", + errors + ); + }); + + toPatchField(dto.phone_secondary).ifSet((phone_secondary) => { + customerPatchProps.phoneSecondary = extractOrPushError( + maybeFromNullableVO(phone_secondary, (value) => PhoneNumber.create(value)), + "phone_secondary", errors ); }); @@ -158,7 +197,7 @@ export function mapDTOToUpdateCustomerPatchProps(dto: UpdateCustomerRequestDTO) return; } - defaultTaxes!.split(",").forEach((taxCode, index) => { + defaultTaxes!.forEach((taxCode, index) => { const tax = extractOrPushError(TaxCode.create(taxCode), `default_taxes.${index}`, errors); if (tax && customerPatchProps.defaultTaxes) { customerPatchProps.defaultTaxes.add(tax); @@ -173,7 +212,9 @@ export function mapDTOToUpdateCustomerPatchProps(dto: UpdateCustomerRequestDTO) } if (errors.length > 0) { - return Result.fail(new ValidationErrorCollection("Customer props mapping failed", errors)); + return Result.fail( + new ValidationErrorCollection("Customer props mapping failed (update)", errors) + ); } return Result.ok(customerPatchProps); @@ -183,7 +224,7 @@ export function mapDTOToUpdateCustomerPatchProps(dto: UpdateCustomerRequestDTO) } function mapDTOToUpdatePostalAddressPatchProps( - dto: UpdateCustomerRequestDTO, + dto: UpdateCustomerByIdRequestDTO, errors: ValidationErrorDetail[] ): PostalAddressPatchProps | undefined { const postalAddressPatchProps: PostalAddressPatchProps = {}; diff --git a/modules/customers/src/api/infrastructure/mappers/domain/customer.mapper.ts b/modules/customers/src/api/infrastructure/mappers/domain/customer.mapper.ts index c1abdf32..2765d950 100644 --- a/modules/customers/src/api/infrastructure/mappers/domain/customer.mapper.ts +++ b/modules/customers/src/api/infrastructure/mappers/domain/customer.mapper.ts @@ -197,7 +197,9 @@ export class CustomerDomainMapper // Si hubo errores de mapeo, devolvemos colección de validación if (errors.length > 0) { - return Result.fail(new ValidationErrorCollection("Customer props mapping failed", errors)); + return Result.fail( + new ValidationErrorCollection("Customer props mapping failed (CustomerMapper)", errors) + ); } const customerProps: CustomerProps = { diff --git a/modules/customers/src/common/dto/request/create-customer.request.dto.ts b/modules/customers/src/common/dto/request/create-customer.request.dto.ts index f3ab592d..60af2202 100644 --- a/modules/customers/src/common/dto/request/create-customer.request.dto.ts +++ b/modules/customers/src/common/dto/request/create-customer.request.dto.ts @@ -29,7 +29,7 @@ export const CreateCustomerRequestSchema = z.object({ legal_record: z.string().default(""), - default_taxes: z.string().default(""), + default_taxes: z.array(z.string()).default([]), status: z.string().toLowerCase().default("active"), language_code: z.string().toLowerCase().default("es"), currency_code: z.string().toUpperCase().default("EUR"), diff --git a/modules/customers/src/common/dto/request/update-customer-by-id.request.dto.ts b/modules/customers/src/common/dto/request/update-customer-by-id.request.dto.ts index 4b3e87ca..c942fb53 100644 --- a/modules/customers/src/common/dto/request/update-customer-by-id.request.dto.ts +++ b/modules/customers/src/common/dto/request/update-customer-by-id.request.dto.ts @@ -11,6 +11,7 @@ export const UpdateCustomerByIdRequestSchema = z.object({ name: z.string().optional(), trade_name: z.string().optional(), tin: z.string().optional(), + default_taxes: z.array(z.string()).optional(), // completo (sustituye), o null => vaciar street: z.string().optional(), street2: z.string().optional(), @@ -31,7 +32,6 @@ export const UpdateCustomerByIdRequestSchema = z.object({ legal_record: z.string().optional(), - default_taxes: z.string().optional(), // completo (sustituye), o null => vaciar language_code: z.string().optional(), currency_code: z.string().optional(), }); diff --git a/modules/customers/src/common/dto/response/create-customer.result.dto.ts b/modules/customers/src/common/dto/response/create-customer.result.dto.ts index 768a1f3e..7c398de2 100644 --- a/modules/customers/src/common/dto/response/create-customer.result.dto.ts +++ b/modules/customers/src/common/dto/response/create-customer.result.dto.ts @@ -25,7 +25,7 @@ export const CreateCustomerResponseSchema = z.object({ legal_record: z.string(), - default_taxes: z.string(), + default_taxes: z.array(z.string()), status: z.string(), language_code: z.string(), currency_code: z.string(), diff --git a/modules/customers/src/common/dto/response/get-customer-by-id.response.dto.ts b/modules/customers/src/common/dto/response/get-customer-by-id.response.dto.ts index 06d1af60..21464c23 100644 --- a/modules/customers/src/common/dto/response/get-customer-by-id.response.dto.ts +++ b/modules/customers/src/common/dto/response/get-customer-by-id.response.dto.ts @@ -30,7 +30,7 @@ export const GetCustomerByIdResponseSchema = z.object({ legal_record: z.string(), - default_taxes: z.string(), + default_taxes: z.array(z.string()), status: z.string(), language_code: z.string(), currency_code: z.string(), diff --git a/modules/customers/src/common/dto/response/list-customers.response.dto.ts b/modules/customers/src/common/dto/response/list-customers.response.dto.ts index 65d068aa..64248177 100644 --- a/modules/customers/src/common/dto/response/list-customers.response.dto.ts +++ b/modules/customers/src/common/dto/response/list-customers.response.dto.ts @@ -25,7 +25,7 @@ export const ListCustomersResponseSchema = createListViewResponseSchema( website: z.string(), //legal_record: z.string(), - //default_taxes: z.string(), + //default_taxes: z.array(z.string()), language_code: z.string(), currency_code: z.string(), diff --git a/modules/customers/src/common/dto/response/update-customer-by-id.response.dto.ts b/modules/customers/src/common/dto/response/update-customer-by-id.response.dto.ts index 24551e70..628616fa 100644 --- a/modules/customers/src/common/dto/response/update-customer-by-id.response.dto.ts +++ b/modules/customers/src/common/dto/response/update-customer-by-id.response.dto.ts @@ -30,7 +30,7 @@ export const UpdateCustomerByIdResponseSchema = z.object({ legal_record: z.string(), - default_taxes: z.string(), + default_taxes: z.array(z.string()), language_code: z.string(), currency_code: z.string(), diff --git a/modules/customers/src/web/components/customers-list-grid.tsx b/modules/customers/src/web/components/customers-list-grid.tsx index d1698160..9bf32b3d 100644 --- a/modules/customers/src/web/components/customers-list-grid.tsx +++ b/modules/customers/src/web/components/customers-list-grid.tsx @@ -79,7 +79,7 @@ export const CustomersListGrid = () => { size='icon' className='size-8' onClick={() => { - navigate(`${data.id}/edit`); + navigate(`${data.id}/edit`, { relative: "path" }); }} > diff --git a/modules/customers/src/web/pages/update/customer-additional-config-fields.tsx b/modules/customers/src/web/pages/update/customer-additional-config-fields.tsx index 1fa39ba3..3b55e1ed 100644 --- a/modules/customers/src/web/pages/update/customer-additional-config-fields.tsx +++ b/modules/customers/src/web/pages/update/customer-additional-config-fields.tsx @@ -1,5 +1,4 @@ -import { TaxesMultiSelectField } from "@erp/core/components"; -import { SelectField, TextAreaField } from "@repo/rdx-ui/components"; +import { SelectField } from "@repo/rdx-ui/components"; import { Card, CardContent, @@ -23,41 +22,29 @@ export const CustomerAdditionalConfigFields = ({ {t("form_groups.preferences.title")} {t("form_groups.preferences.description")} - - - - - + +
+ + +
); diff --git a/modules/customers/src/web/pages/update/customer-address-fields.tsx b/modules/customers/src/web/pages/update/customer-address-fields.tsx index 3034a822..25280e71 100644 --- a/modules/customers/src/web/pages/update/customer-address-fields.tsx +++ b/modules/customers/src/web/pages/update/customer-address-fields.tsx @@ -55,7 +55,7 @@ export const CustomerAddressFields = ({ control }: { control: Control
-
+
Identificación -
-
+
+
- -
+
+
+
-
+
-
+
-
+
+
diff --git a/modules/customers/src/web/pages/update/customer-edit-form.tsx b/modules/customers/src/web/pages/update/customer-edit-form.tsx index adde4ba2..b431de83 100644 --- a/modules/customers/src/web/pages/update/customer-edit-form.tsx +++ b/modules/customers/src/web/pages/update/customer-edit-form.tsx @@ -65,7 +65,7 @@ export const CustomerEditForm = ({ defaultValues, onSubmit, isPending }: Custome return (
- +
diff --git a/packages/rdx-ui/src/components/form/TextAreaField.tsx b/packages/rdx-ui/src/components/form/TextAreaField.tsx index d4f75050..a5a09fb8 100644 --- a/packages/rdx-ui/src/components/form/TextAreaField.tsx +++ b/packages/rdx-ui/src/components/form/TextAreaField.tsx @@ -46,9 +46,15 @@ export function TextAreaField({ render={({ field }) => ( {label && ( -
- {label} - {required && {t("common.required")}} +
+
+ + {label} + + {required && ( + {t("common.required")} + )} +
)}