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 customerPatchProps: CustomerPatchProps = {};
console.log(dto);
toPatchField(dto.reference).ifSet((reference) => {
customerPatchProps.reference = extractOrPushError(
maybeFromNullableResult(reference, (value) => Name.create(value)),

View File

@ -122,7 +122,7 @@
"email_secondary": {
"label": "Email secundario",
"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": {
"label": "Teléfono",

View File

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

View File

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

View File

@ -15,32 +15,33 @@ import { z } from "zod/v4";
*/
export const CustomerUpdateFormSchema = z.object({
reference: z.string(),
reference: z.string().optional().or(z.literal("")),
isCompany: z.boolean(),
name: z.string().min(1, "El nombre es obligatorio"),
tradeName: z.string(),
tradeName: z.string().optional().or(z.literal("")),
tin: z.string(),
defaultTaxes: z.array(z.string()),
street: z.string(),
street2: z.string(),
city: z.string(),
province: z.string(),
postalCode: z.string(),
country: z.string().min(1, "El país es obligatorio"),
street: z.string().optional().or(z.literal("")),
street2: z.string().optional().or(z.literal("")),
city: z.string().optional().or(z.literal("")),
province: z.string().optional().or(z.literal("")),
postalCode: z.string().optional().or(z.literal("")),
country: z.string().min(1, "El país es obligatorio").optional().or(z.literal("")),
primaryEmail: z.string(),
secondaryEmail: z.string(),
primaryPhone: z.string(),
secondaryPhone: z.string(),
primaryMobile: z.string(),
secondaryMobile: z.string(),
primaryEmail: z.email("Email inválido").optional().or(z.literal("")),
secondaryEmail: z.email("Email inválido").optional().or(z.literal("")),
fax: z.string(),
website: z.string(),
primaryPhone: z.string().optional().or(z.literal("")),
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"),
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 {
Field,
FieldDescription,
@ -7,6 +7,9 @@ import {
FieldLabel,
FieldLegend,
FieldSet,
FormControl,
RadioGroup,
RadioGroupItem,
} from "@repo/shadcn-ui/components";
import { useEffect } from "react";
import { Controller, useFormContext } from "react-hook-form";
@ -53,23 +56,38 @@ export const CustomerBasicInfoFields = ({
name="isCompany"
render={({ field, fieldState }) => (
<Field className="gap-1" data-invalid={fieldState.invalid}>
<RadioGroupField
description={t("form_fields.customer_type.description")}
items={[
{
value: "true",
label: t("form_fields.customer_type.company"),
},
{
value: "false",
label: t("form_fields.customer_type.individual"),
},
]}
label={t("form_fields.customer_type.label")}
name={field.name}
onValueChange={(value) => field.onChange(value === "true")}
value={String(field.value)}
/>
<FormFieldLabel required>{t("form_fields.customer_type.label")}</FormFieldLabel>
<FormControl>
<RadioGroup
className="gap-3"
name={field.name}
onValueChange={(value) => field.onChange(value === "true")}
value={String(field.value)}
>
<div className="flex items-start gap-2">
<RadioGroupItem id="customer-type-company" value="true" />
<label
className="cursor-pointer text-sm font-medium leading-none"
htmlFor="customer-type-company"
>
{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]} />
</Field>
)}