Fixed forms

This commit is contained in:
2025-06-26 20:10:05 +02:00
parent b60245d0a7
commit be221f3e1c
5 changed files with 21 additions and 11 deletions

View File

@@ -5,6 +5,7 @@ import { getSession } from "../auth/session"
import { insertUrl } from "../db/urls"
import { advancedUrlSchema, urlFormSchema } from "../schema/url"
import { deleteUrl as deleteUrlDb } from "../db/urls"
import { revalidatePath } from "next/cache"
type Response = {
error: boolean
@@ -30,7 +31,12 @@ export async function addUrl(unsafeData: unknown): Promise<Response> {
}
}
await insertUrl(data)
await insertUrl({
...data,
slug: data.slug.length === 0 ? undefined : data.slug,
})
revalidatePath("/dashboard")
return {
error: false,
@@ -57,7 +63,12 @@ export async function createAdvanceUrl(unsafeData: unknown): Promise<Response> {
}
}
await insertUrl(data)
await insertUrl({
...data,
slug: data.slug?.length === 0 ? undefined : data.slug,
title: data.title?.length === 0 ? undefined : data.title,
maxVisits: data.maxVisits > 0 ? data.maxVisits : undefined,
})
return {
error: false,