diff --git a/apps/edr-freight-api/src/modules/companies/dto/update-profile.dto.ts b/apps/edr-freight-api/src/modules/companies/dto/update-profile.dto.ts index 214c3858a..c89326fa1 100644 --- a/apps/edr-freight-api/src/modules/companies/dto/update-profile.dto.ts +++ b/apps/edr-freight-api/src/modules/companies/dto/update-profile.dto.ts @@ -36,13 +36,13 @@ export class UpdateProfileDto { @IsTin({ message: "TIN must be exactly 10 digits" }) tin?: string; - // Ethiopian VAT registration numbers are 10 digits, the same shape as the - // TIN. Both portal forms enforce that; without it here the API happily stored - // whatever a stale client sent, and the two layers disagreed about what the - // column may hold. + // Ethiopian VAT registration numbers are 10 digits (the same shape as the + // TIN), but some are issued with an 11th. Both portal forms enforce the same + // range; without it here the API happily stored whatever a stale client sent, + // and the two layers disagreed about what the column may hold. @IsOptional() @IsString() - @Matches(/^\d{10}$/, { message: "VAT number must be exactly 10 digits" }) + @Matches(/^\d{10,11}$/, { message: "VAT number must be 10 or 11 digits" }) vatNumber?: string; // `fanNumber` is deliberately absent: the FAN is the Fayda number of the diff --git a/apps/edr-freight-web/portal/src/pages/accounts/companyProfileForm/schema.test.ts b/apps/edr-freight-web/portal/src/pages/accounts/companyProfileForm/schema.test.ts index f38d54432..0d357f691 100644 --- a/apps/edr-freight-web/portal/src/pages/accounts/companyProfileForm/schema.test.ts +++ b/apps/edr-freight-web/portal/src/pages/accounts/companyProfileForm/schema.test.ts @@ -59,10 +59,22 @@ describe("VAT number", () => { ).toBeUndefined(); }); + it("accepts eleven digits", () => { + expect( + errorFor(values({ vatNumber: "00123456789" }), "vatNumber"), + ).toBeUndefined(); + }); + + it("rejects twelve digits", () => { + expect(errorFor(values({ vatNumber: "001234567890" }), "vatNumber")).toBe( + "VAT number must be 10 or 11 digits", + ); + }); + // `.length(10)` used to pass this, so a ten-letter string reached the API. it("rejects ten non-digits", () => { expect(errorFor(values({ vatNumber: "ABCDEFGHIJ" }), "vatNumber")).toBe( - "VAT number must be exactly 10 digits", + "VAT number must be 10 or 11 digits", ); }); diff --git a/apps/edr-freight-web/portal/src/pages/accounts/companyProfileForm/schema.ts b/apps/edr-freight-web/portal/src/pages/accounts/companyProfileForm/schema.ts index 37f92e05e..db48667db 100644 --- a/apps/edr-freight-web/portal/src/pages/accounts/companyProfileForm/schema.ts +++ b/apps/edr-freight-web/portal/src/pages/accounts/companyProfileForm/schema.ts @@ -25,7 +25,7 @@ export const onboardingSchema = z.object({ vatNumber: z .string() .min(1, "VAT number is required") - .regex(/^\d{10}$/, "VAT number must be exactly 10 digits"), + .regex(/^\d{10,11}$/, "VAT number must be 10 or 11 digits"), // The owner's passport number — the foreign-company identity credential // (Fayda is an Ethiopian national ID). Required only for a foreign company; // enforced in buildOnboardingSchema since that depends on `nationality`. diff --git a/apps/edr-freight-web/portal/src/pages/accounts/companyProfileForm/steps/CompanyInfoStep.tsx b/apps/edr-freight-web/portal/src/pages/accounts/companyProfileForm/steps/CompanyInfoStep.tsx index 3f37506a4..978377151 100644 --- a/apps/edr-freight-web/portal/src/pages/accounts/companyProfileForm/steps/CompanyInfoStep.tsx +++ b/apps/edr-freight-web/portal/src/pages/accounts/companyProfileForm/steps/CompanyInfoStep.tsx @@ -51,7 +51,7 @@ export default function CompanyInfoStep({ index={1} title="VAT number" status={ - watch("vatNumber")?.length === 10 && !errors.vatNumber + (watch("vatNumber")?.length ?? 0) >= 10 && !errors.vatNumber ? "done" : "todo" } @@ -59,7 +59,7 @@ export default function CompanyInfoStep({ diff --git a/apps/edr-freight-web/portal/src/pages/settings/TabCompanyProfile.tsx b/apps/edr-freight-web/portal/src/pages/settings/TabCompanyProfile.tsx index 6a315392c..deaec110f 100644 --- a/apps/edr-freight-web/portal/src/pages/settings/TabCompanyProfile.tsx +++ b/apps/edr-freight-web/portal/src/pages/settings/TabCompanyProfile.tsx @@ -46,7 +46,7 @@ export const COMPANY_PROFILE_SCHEMA = z.object({ vatNumber: z .string() .min(1, "VAT number is required") - .regex(/^\d{10}$/, "VAT number must be exactly 10 digits"), + .regex(/^\d{10,11}$/, "VAT number must be 10 or 11 digits"), ownerPassportNumber: z.string().optional(), // Registration/address fields are eTrade-sourced — locked once eTrade // supplies a value, editable only as an escape hatch when it doesn't @@ -332,7 +332,7 @@ export default function TabCompanyProfile({