feat(registration): add birthdate & postcode
This commit is contained in:
@@ -29,6 +29,8 @@ export interface GuestEntry {
|
||||
lastName: string;
|
||||
email: string;
|
||||
phone: string;
|
||||
birthdate: string;
|
||||
postcode: string;
|
||||
}
|
||||
|
||||
export interface GuestErrors {
|
||||
@@ -36,6 +38,8 @@ export interface GuestErrors {
|
||||
lastName?: string;
|
||||
email?: string;
|
||||
phone?: string;
|
||||
birthdate?: string;
|
||||
postcode?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -52,6 +56,8 @@ export function parseGuests(raw: string | null | undefined): GuestEntry[] {
|
||||
lastName: g.lastName ?? "",
|
||||
email: g.email ?? "",
|
||||
phone: g.phone ?? "",
|
||||
birthdate: g.birthdate ?? "",
|
||||
postcode: g.postcode ?? "",
|
||||
}));
|
||||
} catch {
|
||||
return [];
|
||||
@@ -87,6 +93,22 @@ export function validatePhone(value: string): string | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function validateBirthdate(value: string): string | undefined {
|
||||
if (!value.trim()) return "Geboortedatum is verplicht";
|
||||
// Expect YYYY-MM-DD format
|
||||
if (!/^\d{4}-\d{2}-\d{2}$/.test(value))
|
||||
return "Voer een geldige geboortedatum in";
|
||||
const date = new Date(value);
|
||||
if (Number.isNaN(date.getTime())) return "Voer een geldige geboortedatum in";
|
||||
if (date > new Date()) return "Geboortedatum mag niet in de toekomst liggen";
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export function validatePostcode(value: string): string | undefined {
|
||||
if (!value.trim()) return "Postcode is verplicht";
|
||||
return undefined;
|
||||
}
|
||||
|
||||
/** Validates all guests and returns errors array + overall validity flag. */
|
||||
export function validateGuests(guests: GuestEntry[]): {
|
||||
errors: GuestErrors[];
|
||||
@@ -103,6 +125,8 @@ export function validateGuests(guests: GuestEntry[]): {
|
||||
g.phone.trim() && !/^[\d\s\-+()]{10,}$/.test(g.phone.replace(/\s/g, ""))
|
||||
? "Voer een geldig telefoonnummer in"
|
||||
: undefined,
|
||||
birthdate: validateBirthdate(g.birthdate),
|
||||
postcode: validatePostcode(g.postcode),
|
||||
}));
|
||||
const valid = !errors.some((e) => Object.values(e).some(Boolean));
|
||||
return { errors, valid };
|
||||
|
||||
Reference in New Issue
Block a user