Repaso a customers

This commit is contained in:
David Arranz 2026-04-04 00:52:56 +02:00
parent a7a4768a0f
commit ce1c2c9b76
6 changed files with 59 additions and 38 deletions

View File

@ -53,6 +53,8 @@ export class UpdateCustomerInputMapper implements IUpdateCustomerInputMapper {
const errors: ValidationErrorDetail[] = []; const errors: ValidationErrorDetail[] = [];
const customerPatchProps: CustomerPatchProps = {}; const customerPatchProps: CustomerPatchProps = {};
console.log(dto);
toPatchField(dto.reference).ifSet((reference) => { toPatchField(dto.reference).ifSet((reference) => {
customerPatchProps.reference = extractOrPushError( customerPatchProps.reference = extractOrPushError(
maybeFromNullableResult(reference, (value) => Name.create(value)), maybeFromNullableResult(reference, (value) => Name.create(value)),

View File

@ -122,7 +122,7 @@
"email_secondary": { "email_secondary": {
"label": "Email secundario", "label": "Email secundario",
"placeholder": "Ingrese el correo electrónico", "placeholder": "Ingrese el correo electrónico",
"description": "La dirección de correo electrónico secundario del clientºe" "description": "La dirección de correo electrónico secundario del cliente"
}, },
"phone_primary": { "phone_primary": {
"label": "Teléfono", "label": "Teléfono",

View File

@ -39,7 +39,7 @@ export const mapCustomerToCustomerUpdateForm = (customer: Customer): CustomerUpd
legalRecord: customer.legalRecord ?? "", legalRecord: customer.legalRecord ?? "",
languageCode: customer.languageCode ?? "ES", languageCode: customer.languageCode ?? "es",
currencyCode: customer.currencyCode ?? "EUR", currencyCode: customer.currencyCode ?? "EUR",
}; };
}; };

View File

@ -28,6 +28,6 @@ export const defaultCustomerUpdateForm: CustomerUpdateForm = {
legalRecord: "", legalRecord: "",
languageCode: "ES", languageCode: "es",
currencyCode: "EUR", currencyCode: "EUR",
}; };

View File

@ -15,32 +15,33 @@ import { z } from "zod/v4";
*/ */
export const CustomerUpdateFormSchema = z.object({ export const CustomerUpdateFormSchema = z.object({
reference: z.string(), reference: z.string().optional().or(z.literal("")),
isCompany: z.boolean(), isCompany: z.boolean(),
name: z.string().min(1, "El nombre es obligatorio"), name: z.string().min(1, "El nombre es obligatorio"),
tradeName: z.string(), tradeName: z.string().optional().or(z.literal("")),
tin: z.string(), tin: z.string(),
defaultTaxes: z.array(z.string()), defaultTaxes: z.array(z.string()),
street: z.string(), street: z.string().optional().or(z.literal("")),
street2: z.string(), street2: z.string().optional().or(z.literal("")),
city: z.string(), city: z.string().optional().or(z.literal("")),
province: z.string(), province: z.string().optional().or(z.literal("")),
postalCode: z.string(), postalCode: z.string().optional().or(z.literal("")),
country: z.string().min(1, "El país es obligatorio"), country: z.string().min(1, "El país es obligatorio").optional().or(z.literal("")),
primaryEmail: z.string(), primaryEmail: z.email("Email inválido").optional().or(z.literal("")),
secondaryEmail: z.string(), secondaryEmail: z.email("Email inválido").optional().or(z.literal("")),
primaryPhone: z.string(),
secondaryPhone: z.string(),
primaryMobile: z.string(),
secondaryMobile: z.string(),
fax: z.string(), primaryPhone: z.string().optional().or(z.literal("")),
website: z.string(), secondaryPhone: z.string().optional().or(z.literal("")),
primaryMobile: z.string().optional().or(z.literal("")),
secondaryMobile: z.string().optional().or(z.literal("")),
legalRecord: z.string(), fax: z.string().optional().or(z.literal("")),
website: z.url("URL inválida").optional().or(z.literal("")),
legalRecord: z.string().optional().or(z.literal("")),
languageCode: z.string().min(1, "El idioma es obligatorio"), languageCode: z.string().min(1, "El idioma es obligatorio"),
currencyCode: z.string().min(1, "La moneda es obligatoria"), currencyCode: z.string().min(1, "La moneda es obligatoria"),

View File

@ -1,4 +1,4 @@
import { RadioGroupField, TextAreaField, TextField } from "@repo/rdx-ui/components"; import { FormFieldLabel, TextAreaField, TextField } from "@repo/rdx-ui/components";
import { import {
Field, Field,
FieldDescription, FieldDescription,
@ -7,6 +7,9 @@ import {
FieldLabel, FieldLabel,
FieldLegend, FieldLegend,
FieldSet, FieldSet,
FormControl,
RadioGroup,
RadioGroupItem,
} from "@repo/shadcn-ui/components"; } from "@repo/shadcn-ui/components";
import { useEffect } from "react"; import { useEffect } from "react";
import { Controller, useFormContext } from "react-hook-form"; import { Controller, useFormContext } from "react-hook-form";
@ -53,23 +56,38 @@ export const CustomerBasicInfoFields = ({
name="isCompany" name="isCompany"
render={({ field, fieldState }) => ( render={({ field, fieldState }) => (
<Field className="gap-1" data-invalid={fieldState.invalid}> <Field className="gap-1" data-invalid={fieldState.invalid}>
<RadioGroupField <FormFieldLabel required>{t("form_fields.customer_type.label")}</FormFieldLabel>
description={t("form_fields.customer_type.description")}
items={[ <FormControl>
{ <RadioGroup
value: "true", className="gap-3"
label: t("form_fields.customer_type.company"), name={field.name}
}, onValueChange={(value) => field.onChange(value === "true")}
{ value={String(field.value)}
value: "false", >
label: t("form_fields.customer_type.individual"), <div className="flex items-start gap-2">
}, <RadioGroupItem id="customer-type-company" value="true" />
]} <label
label={t("form_fields.customer_type.label")} className="cursor-pointer text-sm font-medium leading-none"
name={field.name} htmlFor="customer-type-company"
onValueChange={(value) => field.onChange(value === "true")} >
value={String(field.value)} {t("form_fields.customer_type.company")}
/> </label>
</div>
<div className="flex items-start gap-2">
<RadioGroupItem id="customer-type-individual" value="false" />
<label
className="cursor-pointer text-sm font-medium leading-none"
htmlFor="customer-type-individual"
>
{t("form_fields.customer_type.individual")}
</label>
</div>
</RadioGroup>
</FormControl>
<FieldDescription>{t("form_fields.customer_type.description")}</FieldDescription>
<FieldError errors={[fieldState.error]} /> <FieldError errors={[fieldState.error]} />
</Field> </Field>
)} )}