Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions docs/people/soci.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down
18 changes: 3 additions & 15 deletions src/features/soci/soci-format.ts
Original file line number Diff line number Diff line change
@@ -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 }

Expand Down Expand Up @@ -42,28 +42,16 @@ export const MISMATCH = {
still_in_soci: "Ended, but still in the Soci group",
} satisfies Record<NonNullable<SocioRow["mismatch"]>, 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
}
59 changes: 11 additions & 48 deletions src/features/soci/soci.contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<typeof residenceSchema>
.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 = {
Expand All @@ -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. */
Expand Down Expand Up @@ -160,27 +145,6 @@ const optional = <T extends z.ZodType<string, string>>(schema: T) =>
.nullish()
.transform(blankToNull)

const residenceInput = <R extends boolean>(required: R) => {
const field = (schema: z.ZodType<string, string>) => (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<R extends boolean>(required: R) {
const field = (schema: z.ZodType<string, string>) => (required ? schema : optional(schema))
return z
Expand All @@ -191,9 +155,8 @@ function detailsInput<R extends boolean>(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))
Expand All @@ -205,7 +168,7 @@ function detailsInput<R extends boolean>(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)
Expand Down
12 changes: 7 additions & 5 deletions src/features/soci/soci.fake.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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 {
Expand All @@ -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",
Expand All @@ -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(
Expand Down Expand Up @@ -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]))
Expand Down
4 changes: 2 additions & 2 deletions src/features/soci/socio-dialogs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,9 @@ export function RegisterSocioDialog({
const [errors, setErrors] = useState<FieldErrors>({})
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) {
Expand Down
Loading
Loading