diff --git a/docs/people/soci.md b/docs/people/soci.md index 5f179cf..5c33322 100644 --- a/docs/people/soci.md +++ b/docs/people/soci.md @@ -34,7 +34,8 @@ Owner decisions, 9 November 2026: 9. **Emails are automatic and always go to the PoliNetwork mailbox.** Every socio has one, since being a socio means one's PoliNetwork account is in the Soci group. 10. **The register holds the bookkeeping data:** legal name, optional alias, codice fiscale, place and date of birth, - residence address, admission date and end date with its reason. + residence address (one line, as the paper Libro Soci writes it), optional phone, admission date and end date with + its reason. 11. **Admitting a socio moves from Microsoft 365 › Members to People › Soci.** It keeps today's account workflow (account, licences, Soci group, welcome email) and collects the bookkeeping data in the same dialog. Changing a member number moves too. Microsoft 365 › Members becomes a read-only directory. @@ -99,7 +100,8 @@ Active ──(Direttivo: resigned / expelled / deceased / other)► Ended ── them in emails). - `codice_fiscale` (format, check digit and omocodia validated; at most one active record per code), `birth_date`, `birth_place` (comune, or city and country). - - Residence: street and number, postal code, city, province (Italy only), country. + - `residence`: one line, e.g. `Via Roma 1, Milano (MI)`. `phone` (optional): international format, stored without + spaces, e.g. `+393331234567`. - `admitted_on`; `ended_on`, `end_reason`, `end_note`. - Account state: `active` | `pending_deletion` | `deleted`, with `account_deleted_on`. - Created and updated by and at. @@ -178,7 +180,7 @@ Pages: activity. Actions: Edit, Change number, Mark as paid, End status (danger, reason and date), Restore. - **Admit socio** (lg dialog), in four parts: - Account: today's Microsoft 365 create form (name, address format, member number, welcome email address). - - Bookkeeping data: everything above, all required except the alias. + - Bookkeeping data: everything above, all required except the alias and the phone. - Admission date (default today), which records the first fee as paid. - A warning when the codice fiscale belongs to a former socio. - **Register existing socio**: the same data for an account already in Soci, with its current member number. Personal @@ -219,8 +221,8 @@ These are created by hand in the production IdP, as the `people:*` ones were. On `people:self` to the managed Socio role. `azure:members:create` and `azure:members:write` are deleted once `soci.members.admit` and `setNumber` replace them. -The codice fiscale, the birth data and the residence address are visible only with `soci:read`, or to the socio -themselves. +The codice fiscale, the birth data, the residence address and the phone are visible only with `soci:read`, or to the +socio themselves. ## Starting the register diff --git a/src/features/soci/soci-format.ts b/src/features/soci/soci-format.ts index 16b6a3c..cf10a0c 100644 --- a/src/features/soci/soci-format.ts +++ b/src/features/soci/soci-format.ts @@ -1,6 +1,6 @@ import type { StatusTone } from "@/components/primitives" -import type { END_REASONS, Residence, SocioRow } from "./soci.contract" +import type { END_REASONS, SocioRow } from "./soci.contract" type Tone = { label: string; tone: StatusTone } @@ -42,28 +42,16 @@ export const MISMATCH = { still_in_soci: "Ended, but still in the Soci group", } satisfies Record, string> -/** "Via Bonardi 9, 20133 Milano (MI), IT", or null when nothing is recorded. */ -export function formatResidence(residence: Residence) { - const place = [residence.postalCode, residence.city].filter(Boolean).join(" ") - const parts = [ - residence.street, - place ? `${place}${residence.province ? ` (${residence.province})` : ""}` : null, - residence.country, - ] - const text = parts.filter(Boolean).join(", ") - return text === "" ? null : text -} - /** The bookkeeping fields still empty on a record registered from Microsoft 365. */ export function missingDetails(socio: { codiceFiscale: string | null birthDate: string | null birthPlace: string | null - residence: Residence + residence: string | null }) { const missing: string[] = [] if (!socio.codiceFiscale) missing.push("codice fiscale") if (!socio.birthDate || !socio.birthPlace) missing.push("birth data") - if (!socio.residence.street || !socio.residence.city || !socio.residence.country) missing.push("residence") + if (!socio.residence) missing.push("residence") return missing } diff --git a/src/features/soci/soci.contract.ts b/src/features/soci/soci.contract.ts index 16ed094..803712f 100644 --- a/src/features/soci/soci.contract.ts +++ b/src/features/soci/soci.contract.ts @@ -48,29 +48,11 @@ const dateSchema = z.iso.date() const text = (max: number) => z.string().trim().min(1).max(max) /** A name as written on an identity document. */ const legalName = text(80) -/** ISO 3166-1 alpha-2, e.g. `IT`. */ -const countrySchema = z +/** International format: `+`, the country code and the number, e.g. `+393331234567`. */ +export const phoneSchema = z .string() - .trim() - .toUpperCase() - .regex(/^[A-Z]{2}$/, "A two-letter country code, e.g. IT") -/** The two-letter sigla of an Italian province, e.g. `MI`. */ -const provinceSchema = z - .string() - .trim() - .toUpperCase() - .regex(/^[A-Z]{2}$/, "The province's two-letter code, e.g. MI") - -export const residenceSchema = z.object({ - /** Street and number. */ - street: z.string().nullable(), - postalCode: z.string().nullable(), - city: z.string().nullable(), - /** Only in Italy. */ - province: z.string().nullable(), - country: z.string().nullable(), -}) -export type Residence = z.infer + .transform((value) => value.replace(/[\s().-]/g, "")) + .pipe(z.string().regex(/^\+[1-9]\d{6,14}$/, "A phone number in international format, e.g. +39 333 123 4567")) /** The bookkeeping data the association keeps. Nullable fields may be missing for a socio registered afterwards. */ const bookkeepingFields = { @@ -82,7 +64,10 @@ const bookkeepingFields = { birthDate: z.string().nullable(), /** The comune, or the city and country. */ birthPlace: z.string().nullable(), - residence: residenceSchema, + /** The residence address as one line, as the Libro Soci writes it, e.g. `Via Roma 1, Milano (MI)`. */ + residence: z.string().nullable(), + /** International format. Never required. */ + phone: z.string().nullable(), } /** One row of the register. */ @@ -160,27 +145,6 @@ const optional = >(schema: T) => .nullish() .transform(blankToNull) -const residenceInput = (required: R) => { - const field = (schema: z.ZodType) => (required ? schema : optional(schema)) - return z - .object({ - street: field(text(200)), - postalCode: field(text(16)), - city: field(text(120)), - province: optional(provinceSchema), - country: field(countrySchema), - }) - .superRefine((r, ctx) => { - const italy = r.country === "IT" - if (italy && r.postalCode && !/^\d{5}$/.test(r.postalCode)) - ctx.addIssue({ code: "custom", path: ["postalCode"], message: "An Italian postal code has five digits." }) - if (!italy && r.province) - ctx.addIssue({ code: "custom", path: ["province"], message: "The province is only for Italy." }) - if (required && italy && !r.province) - ctx.addIssue({ code: "custom", path: ["province"], message: "Choose the province." }) - }) -} - function detailsInput(required: R) { const field = (schema: z.ZodType) => (required ? schema : optional(schema)) return z @@ -191,9 +155,8 @@ function detailsInput(required: R) { codiceFiscale: required ? codiceFiscaleSchema : optional(codiceFiscaleSchema), birthDate: field(dateSchema), birthPlace: field(text(120)), - residence: required - ? residenceInput(true) - : residenceInput(false).prefault({ street: null, postalCode: null, city: null, country: null }), + residence: field(text(200)), + phone: optional(phoneSchema), }) .superRefine((d, ctx) => { if (d.codiceFiscale && d.birthDate && !matchesBirthDate(d.codiceFiscale, d.birthDate)) @@ -205,7 +168,7 @@ function detailsInput(required: R) { }) } -/** Everything required but the alias: for admitting a new socio. */ +/** Everything required but the alias and the phone: for admitting a new socio. */ export const requiredDetailsSchema = detailsInput(true) /** Only the legal name required: for a socio registered afterwards, and for edits. Empty strings mean unknown. */ export const optionalDetailsSchema = detailsInput(false) diff --git a/src/features/soci/soci.fake.server.ts b/src/features/soci/soci.fake.server.ts index c33965e..dc3b63d 100644 --- a/src/features/soci/soci.fake.server.ts +++ b/src/features/soci/soci.fake.server.ts @@ -39,8 +39,6 @@ function account(id: string, name: string, employeeId: string | null, created: s } } -const NO_RESIDENCE = { street: null, postalCode: null, city: null, province: null, country: null } - function record( number: number, acc: Account, @@ -60,7 +58,8 @@ function record( codiceFiscale: details.codiceFiscale ?? null, birthDate: details.birthDate ?? null, birthPlace: details.birthPlace ?? null, - residence: details.residence ?? NO_RESIDENCE, + residence: details.residence ?? null, + phone: details.phone ?? null, admittedOn, endedOn: end?.endedOn ?? null, endReason: end?.endReason ?? null, @@ -75,7 +74,7 @@ function record( } } -const milano = (street: string) => ({ street, postalCode: "20133", city: "Milano", province: "MI", country: "IT" }) +const milano = (street: string) => `${street}, 20133 Milano (MI)` /** Deterministic, so the same register comes back after a dev server restart. */ function build(): State { @@ -95,6 +94,7 @@ function build(): State { birthDate: "1995-09-01", birthPlace: "Milano", residence: milano("Via Bonardi 9"), + phone: "+393331234567", }), record(4, marco, "2019-11-02", { firstName: "Marco Antonio", @@ -108,7 +108,8 @@ function build(): State { codiceFiscale: "CLMSRA99D50L219L", birthDate: "1999-04-10", birthPlace: "Torino", - residence: { street: "Rue de Rivoli 12", postalCode: "75001", city: "Paris", province: null, country: "FR" }, + residence: "Rue de Rivoli 12, 75001 Paris, France", + phone: "+33612345678", }), // Ended, but still in Soci: a mismatch. record( @@ -301,6 +302,7 @@ export function fakeSociApi(): SociApi { "birthDate", "birthPlace", "residence", + "phone", "admittedOn", ] as const const changed = fields.filter((key) => JSON.stringify(next[key]) !== JSON.stringify(r[key])) diff --git a/src/features/soci/socio-dialogs.tsx b/src/features/soci/socio-dialogs.tsx index 5563140..edf0d6e 100644 --- a/src/features/soci/socio-dialogs.tsx +++ b/src/features/soci/socio-dialogs.tsx @@ -387,9 +387,9 @@ export function RegisterSocioDialog({ const [errors, setErrors] = useState({}) const fixedNumber = account?.employeeId && isMemberNumber(account.employeeId) ? account.employeeId : null - // Nothing but the name is known yet, so the country starts empty too. + // Nothing but the name is known yet. function prefill(next: Unregistered | null): DetailsDraft { - return { ...EMPTY_DETAILS, country: "", firstName: next?.givenName ?? "", lastName: next?.surname ?? "" } + return { ...EMPTY_DETAILS, firstName: next?.givenName ?? "", lastName: next?.surname ?? "" } } // The day in Rome, as the hint shows it: the fee year turns on that calendar. function suggestedDate(next: Unregistered | null) { diff --git a/src/features/soci/socio-form.tsx b/src/features/soci/socio-form.tsx index 86d3a24..f696221 100644 --- a/src/features/soci/socio-form.tsx +++ b/src/features/soci/socio-form.tsx @@ -18,11 +18,8 @@ export type DetailsDraft = { codiceFiscale: string birthDate: string birthPlace: string - street: string - postalCode: string - city: string - province: string - country: string + residence: string + phone: string } export const EMPTY_DETAILS: DetailsDraft = { @@ -32,11 +29,8 @@ export const EMPTY_DETAILS: DetailsDraft = { codiceFiscale: "", birthDate: "", birthPlace: "", - street: "", - postalCode: "", - city: "", - province: "", - country: "IT", + residence: "", + phone: "", } export function draftOf(details: SocioDetails): DetailsDraft { @@ -47,31 +41,14 @@ export function draftOf(details: SocioDetails): DetailsDraft { codiceFiscale: details.codiceFiscale ?? "", birthDate: details.birthDate ?? "", birthPlace: details.birthPlace ?? "", - street: details.residence.street ?? "", - postalCode: details.residence.postalCode ?? "", - city: details.residence.city ?? "", - province: details.residence.province ?? "", - country: details.residence.country ?? "", + residence: details.residence ?? "", + phone: details.phone ?? "", } } -/** The contract's input shape; the schemas trim, upper-case and turn empty strings into `null`. */ +/** The contract's input shape; the schemas trim, normalize and turn empty strings into `null`. */ export function detailsInput(draft: DetailsDraft) { - return { - firstName: draft.firstName, - lastName: draft.lastName, - alias: draft.alias, - codiceFiscale: draft.codiceFiscale, - birthDate: draft.birthDate, - birthPlace: draft.birthPlace, - residence: { - street: draft.street, - postalCode: draft.postalCode, - city: draft.city, - province: draft.province, - country: draft.country, - }, - } + return { ...draft } } const FIELD_KEYS = [ @@ -81,11 +58,8 @@ const FIELD_KEYS = [ "codiceFiscale", "birthDate", "birthPlace", - "street", - "postalCode", - "city", - "province", - "country", + "residence", + "phone", "account", "number", "admittedOn", @@ -97,7 +71,7 @@ type FieldKey = (typeof FIELD_KEYS)[number] export type FieldErrors = { [Key in FieldKey]?: string } /** - * The first message per field from a failed parse of a contract input: `details.residence.city` becomes `city`, and + * The first message per field from a failed parse of a contract input: `details.residence` becomes `residence`, and * `account.firstName` becomes `accountFirstName` (and `account.sendEmailTo` `accountEmail`), apart from the legal name. */ export function fieldErrors(error: z.ZodError | undefined) { @@ -106,7 +80,7 @@ export function fieldErrors(error: z.ZodError | undefined) { const [head, next] = issue.path const name = head !== "account" - ? issue.path.find((part) => part !== "details" && part !== "residence") + ? issue.path.find((part) => part !== "details") : next === "firstName" ? "accountFirstName" : next === "lastName" @@ -146,7 +120,7 @@ type DetailsFieldsProps = { draft: DetailsDraft onChange: (draft: DetailsDraft) => void errors: FieldErrors - /** Admission needs everything but the alias; a socio registered afterwards may complete them later. */ + /** Admission needs everything but the alias and the phone; a socio registered afterwards may complete them later. */ required: boolean /** The register, to warn when the codice fiscale belongs to a former or active socio. */ register: readonly SocioRow[] @@ -154,11 +128,10 @@ type DetailsFieldsProps = { self?: number } -/** The bookkeeping data the association keeps: legal name, alias, codice fiscale, birth and residence. */ +/** The bookkeeping data the association keeps: legal name, alias, codice fiscale, birth, residence and phone. */ export function DetailsFields({ id, draft, onChange, errors, required, register, self }: DetailsFieldsProps) { const set = (key: keyof DetailsDraft) => (value: string) => onChange({ ...draft, [key]: value }) const optional = !required - const italy = draft.country.trim().toUpperCase() === "IT" const code = normalizeCodiceFiscale(draft.codiceFiscale) const holders = holdersOf(code, register, self) const dateMismatch = @@ -240,52 +213,43 @@ export function DetailsFields({ id, draft, onChange, errors, required, register, {text("birthPlace", "Birth place", { optional })} - {text("street", "Street and number", { optional })} -
- {text("postalCode", "Postal code", { optional })} - {text("city", "City", { optional })} -
-
- - { - const country = event.target.value.toUpperCase() - onChange({ ...draft, country, province: country === "IT" ? draft.province : "" }) - }} - className={cn("h-9 font-mono uppercase", fieldControl)} - /> - - {italy ? ( - - set("province")(event.target.value.toUpperCase())} - className={cn("h-9 font-mono uppercase", fieldControl)} - /> - - ) : null} -
+ + set("residence")(event.target.value)} + className={cn("h-9", fieldControl)} + /> + + + set("phone")(event.target.value)} + className={cn("h-9", fieldControl)} + /> + ) } diff --git a/src/features/soci/socio-page.tsx b/src/features/soci/socio-page.tsx index d424461..606d67f 100644 --- a/src/features/soci/socio-page.tsx +++ b/src/features/soci/socio-page.tsx @@ -22,7 +22,6 @@ import { ACCOUNT_STATE, END_REASON, formatMemberNumber, - formatResidence, MISMATCH, missingDetails, socioName, @@ -61,7 +60,8 @@ export function SocioPage({ { key: "Codice fiscale", value: value(socio.codiceFiscale, true) }, { key: "Birth date", value: socio.birthDate ? formatDay(socio.birthDate) : }, { key: "Birth place", value: value(socio.birthPlace) }, - { key: "Residence", value: value(formatResidence(socio.residence)) }, + { key: "Residence", value: value(socio.residence) }, + { key: "Phone", value: value(socio.phone) }, ] const admission: KeyValueItem[] = [ { key: "Member number", value: {formatMemberNumber(socio.number)} }, diff --git a/tests/soci.test.mjs b/tests/soci.test.mjs index fc41d5e..b0da0c3 100644 --- a/tests/soci.test.mjs +++ b/tests/soci.test.mjs @@ -17,7 +17,8 @@ const details = { codiceFiscale: "rssmra80a01h501u", birthDate: "1980-01-01", birthPlace: "Roma", - residence: { street: "Via Roma 1", postalCode: "20133", city: "Milano", province: "mi", country: "it" }, + residence: " Via Roma 1, 20133 Milano (MI) ", + phone: "", } const admission = { account: { firstName: "Mario", lastName: "Rossi", mailbox: { kind: "standard" }, sendEmailTo: "mario@example.org" }, @@ -41,21 +42,14 @@ void test("the codice fiscale is checked like the backend: format, omocodia, che assert.equal(codiceFiscaleSchema.parse(" rssmra80a01 h501u "), "RSSMRA80A01H501U") }) -void test("admitting needs every detail but the alias, normalized as the backend stores it", () => { +void test("admitting needs every detail but the alias and the phone, normalized as the backend stores it", () => { const parsed = admitInputSchema.parse(admission) assert.equal(parsed.details.codiceFiscale, "RSSMRA80A01H501U") - assert.deepEqual(parsed.details.residence, { - street: "Via Roma 1", - postalCode: "20133", - city: "Milano", - province: "MI", - country: "IT", - }) + assert.equal(parsed.details.residence, "Via Roma 1, 20133 Milano (MI)") assert.equal(parsed.details.alias, null) - for (const missing of ["birthPlace", "codiceFiscale", "birthDate"]) + assert.equal(parsed.details.phone, null) + for (const missing of ["birthPlace", "codiceFiscale", "birthDate", "residence"]) assert.equal(admitInputSchema.safeParse({ ...admission, details: { ...details, [missing]: "" } }).success, false) - const noProvince = { ...details, residence: { ...details.residence, province: "" } } - assert.equal(admitInputSchema.safeParse({ ...admission, details: noProvince }).success, false) const wrongDate = { ...details, birthDate: "1980-01-02" } assert.equal(admitInputSchema.safeParse({ ...admission, details: wrongDate }).success, false) }) @@ -68,13 +62,15 @@ void test("registering and editing need only the legal name", () => { admittedOn: "2025-03-14", }) assert.equal(registered.details.codiceFiscale, null) - assert.equal(registered.details.residence.street, null) + assert.equal(registered.details.residence, null) + assert.equal(registered.details.phone, null) const empty = { ...minimal, codiceFiscale: "", birthDate: "", birthPlace: "", - residence: { street: "", postalCode: "", city: "", province: "", country: "" }, + residence: "", + phone: "", } assert.equal(updateInputSchema.safeParse({ number: 41, details: empty, admittedOn: "2025-10-13" }).success, true) assert.equal( @@ -83,6 +79,21 @@ void test("registering and editing need only the legal name", () => { ) }) +void test("the phone is optional, in international format, without spaces or separators", () => { + const withPhone = (phone) => admitInputSchema.safeParse({ ...admission, details: { ...details, phone } }) + assert.equal(withPhone("+39 333 123 4567").data?.details.phone, "+393331234567") + assert.equal(withPhone("+44 (20) 7946-0958").data?.details.phone, "+442079460958") + for (const invalid of ["333 123 4567", "0039 333 123 4567", "+39 333", "+39 333 abc 4567"]) { + const parsed = withPhone(invalid) + assert.equal(parsed.success, false, invalid) + // `fieldErrors` in socio-form.tsx shows this path on the Phone field. + assert.deepEqual( + parsed.error.issues.map((issue) => issue.path.join(".")), + ["details.phone"] + ) + } +}) + void test("an account name the backend refuses is reported on the account's field, not the legal name", () => { const parsed = admitInputSchema.safeParse({ ...admission, account: { ...admission.account, lastName: "O’Brien" } }) assert.equal(parsed.success, false)