From b38de29a882ce26a9326f7f65403ea3916a58cac Mon Sep 17 00:00:00 2001 From: Meier Lukas Date: Sun, 26 Jan 2025 21:25:57 +0100 Subject: [PATCH] fix: app url not required (#2130) --- apps/nextjs/src/app/[locale]/manage/apps/_form.tsx | 10 +++++----- packages/validation/src/app.ts | 14 +++++++++++--- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/apps/nextjs/src/app/[locale]/manage/apps/_form.tsx b/apps/nextjs/src/app/[locale]/manage/apps/_form.tsx index 2cf9bf9b3..9ec5b92d1 100644 --- a/apps/nextjs/src/app/[locale]/manage/apps/_form.tsx +++ b/apps/nextjs/src/app/[locale]/manage/apps/_form.tsx @@ -25,11 +25,11 @@ export const AppForm = (props: AppFormProps) => { const t = useI18n(); const form = useZodForm(validation.app.manage, { - initialValues: initialValues ?? { - name: "", - description: "", - iconUrl: "", - href: "", + initialValues: { + name: initialValues?.name ?? "", + description: initialValues?.description ?? "", + iconUrl: initialValues?.iconUrl ?? "", + href: initialValues?.href ?? "", }, }); diff --git a/packages/validation/src/app.ts b/packages/validation/src/app.ts index dfe1a749a..b8b73e35a 100644 --- a/packages/validation/src/app.ts +++ b/packages/validation/src/app.ts @@ -1,13 +1,21 @@ import { z } from "zod"; const manageAppSchema = z.object({ - name: z.string().min(1).max(64), - description: z.string().max(512).nullable(), - iconUrl: z.string().min(1), + name: z.string().trim().min(1).max(64), + description: z + .string() + .trim() + .max(512) + .transform((value) => (value.length === 0 ? null : value)) + .nullable(), + iconUrl: z.string().trim().min(1), href: z .string() + .trim() .url() .regex(/^https?:\/\//) // Only allow http and https for security reasons (javascript: is not allowed) + .or(z.literal("")) + .transform((value) => (value.length === 0 ? null : value)) .nullable(), });