diff --git a/apps/web/src/app/(dashboard)/(account)/profiel/[handle]/_actions/person.ts b/apps/web/src/app/(dashboard)/(account)/profiel/[handle]/_actions/person.ts index c2521277..e514aea5 100644 --- a/apps/web/src/app/(dashboard)/(account)/profiel/[handle]/_actions/person.ts +++ b/apps/web/src/app/(dashboard)/(account)/profiel/[handle]/_actions/person.ts @@ -16,27 +16,20 @@ export async function updatePerson( ) { const expectedSchema = z.object({ firstName: z.string().trim().min(1), - lastNamePrefix: z - .string() - .trim() - .nullable() - .transform((tussenvoegsel) => - tussenvoegsel === "" ? null : tussenvoegsel, - ), + lastNamePrefix: z.string().trim().nullable().default(null), lastName: z.string().min(1), dateOfBirth: z.string().pipe(z.coerce.date()), birthCity: z.string(), birthCountry: z.string().length(2).toLowerCase(), }); - const data: Record = Object.fromEntries( - formData.entries(), - ); + const data: Record = + Object.fromEntries(formData.entries()); - // Set all empty strings to null + // Set all empty strings to undefined for (const key in data) { if (data[key] === "") { - data[key] = null; + data[key] = undefined; } } diff --git a/apps/web/src/app/(dashboard)/(management)/locatie/[location]/cohorten/[cohort]/(overview)/_actions/create.ts b/apps/web/src/app/(dashboard)/(management)/locatie/[location]/cohorten/[cohort]/(overview)/_actions/create.ts index dfabf324..c06f486d 100644 --- a/apps/web/src/app/(dashboard)/(management)/locatie/[location]/cohorten/[cohort]/(overview)/_actions/create.ts +++ b/apps/web/src/app/(dashboard)/(management)/locatie/[location]/cohorten/[cohort]/(overview)/_actions/create.ts @@ -18,28 +18,20 @@ export async function createPerson( const expectedSchema = z.object({ email: z.string().trim().toLowerCase().email().optional(), firstName: z.string().trim().min(1), - lastNamePrefix: z - .string() - .trim() - .nullable() - .transform((tussenvoegsel) => - tussenvoegsel === "" ? null : tussenvoegsel, - ) - .optional(), + lastNamePrefix: z.string().trim().nullable().default(null), lastName: z.string().min(1).optional(), dateOfBirth: z.string().pipe(z.coerce.date()).optional(), birthCity: z.string().optional(), birthCountry: z.string().length(2).toLowerCase().optional(), }); - const data: Record = Object.fromEntries( - formData.entries(), - ); + const data: Record = + Object.fromEntries(formData.entries()); - // Set all empty strings to null + // Set all empty strings to undefined for (const key in data) { if (data[key] === "") { - data[key] = null; + data[key] = undefined; } } diff --git a/apps/web/src/app/(dashboard)/(management)/locatie/[location]/personen/_actions/create.ts b/apps/web/src/app/(dashboard)/(management)/locatie/[location]/personen/_actions/create.ts index 55ba8446..d2df5e08 100644 --- a/apps/web/src/app/(dashboard)/(management)/locatie/[location]/personen/_actions/create.ts +++ b/apps/web/src/app/(dashboard)/(management)/locatie/[location]/personen/_actions/create.ts @@ -19,7 +19,7 @@ export async function createPerson( .object({ email: z.string().trim().toLowerCase().email().optional(), firstName: z.string().trim().min(1), - lastNamePrefix: z.string().trim().nullable().optional(), + lastNamePrefix: z.string().trim().nullable().default(null), lastName: z.string().min(1).optional(), dateOfBirth: z.string().pipe(z.coerce.date()).optional(), birthCity: z.string().optional(), @@ -172,7 +172,7 @@ export async function updatePerson( ) { const expectedSchema = z.object({ firstName: z.string().trim().min(1), - lastNamePrefix: z.string().trim().nullable().optional(), + lastNamePrefix: z.string().trim().nullable().default(null), lastName: z.string().min(1).optional(), dateOfBirth: z.string().pipe(z.coerce.date()).optional(), birthCity: z.string().optional(), @@ -187,10 +187,6 @@ export async function updatePerson( if (data[key] === "") { data[key] = undefined; } - - if (data[key] === null && key !== "lastNamePrefix") { - data[key] = undefined; - } } try {