fix admin save state architecture
This commit is contained in:
@@ -14,6 +14,7 @@ import { getLocalizedPath } from "@/lib/locale";
|
||||
import { removeManagedMediaFile } from "@/lib/media-storage";
|
||||
import { mediaFieldInputSchema } from "@/lib/media-validation";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { isCheckedFormValue } from "@/lib/form-data";
|
||||
import {
|
||||
assetInputSchema,
|
||||
categoryInputSchema,
|
||||
@@ -40,7 +41,7 @@ function withMessage(pathname: string, type: "success" | "error", message: strin
|
||||
}
|
||||
|
||||
function normalizeCheckboxValue(formData: FormData, key: string) {
|
||||
return formData.get(key) === "on";
|
||||
return isCheckedFormValue(formData.get(key));
|
||||
}
|
||||
|
||||
function parseJsonArray(rawValue: FormDataEntryValue | null, key: string) {
|
||||
|
||||
@@ -78,6 +78,8 @@ export default async function RootPortfolioProjectPage({
|
||||
logoutAction={logoutAction}
|
||||
headerTitle={copy.title}
|
||||
headerDescription={copy.subtitle}
|
||||
saveFormId="portfolio-project-form"
|
||||
saveButtonLabel={copy.saveProject}
|
||||
>
|
||||
<div className="space-y-6">
|
||||
{searchParams?.success ? (
|
||||
@@ -100,7 +102,6 @@ export default async function RootPortfolioProjectPage({
|
||||
project={project}
|
||||
formId="portfolio-project-form"
|
||||
redirectPath={`/root/portfolio/projects/${project.id}`}
|
||||
submitLabel={copy.saveProject}
|
||||
/>
|
||||
</MotionFade>
|
||||
|
||||
|
||||
@@ -58,6 +58,7 @@ export default async function RootNewPortfolioProjectPage({
|
||||
logoutAction={logoutAction}
|
||||
headerTitle={copy.title}
|
||||
headerDescription={copy.subtitle}
|
||||
saveFormId="portfolio-project-form"
|
||||
>
|
||||
<div className="space-y-6">
|
||||
{searchParams?.error ? (
|
||||
@@ -73,7 +74,6 @@ export default async function RootNewPortfolioProjectPage({
|
||||
mediaOptions={mediaOptions}
|
||||
formId="portfolio-project-form"
|
||||
redirectPath="/root/portfolio/projects/new"
|
||||
submitLabel="Projekt anlegen"
|
||||
/>
|
||||
</MotionFade>
|
||||
</div>
|
||||
|
||||
@@ -5,6 +5,7 @@ import { redirect } from "next/navigation";
|
||||
import { isRedirectError } from "next/dist/client/components/redirect";
|
||||
|
||||
import { clearAdminSessionCookie, isAdminAuthenticated } from "@/lib/admin-auth";
|
||||
import { isCheckedFormValue } from "@/lib/form-data";
|
||||
import {
|
||||
getMailSettings,
|
||||
updateMailSettings,
|
||||
@@ -53,7 +54,7 @@ function parseMailSettingsFormData(
|
||||
smtp: {
|
||||
host,
|
||||
port: parsePort(portValue || String(existingSettings.smtp.port)),
|
||||
secure: formData.get("smtpSecure") === "on",
|
||||
secure: isCheckedFormValue(formData.get("smtpSecure")),
|
||||
username,
|
||||
password: password.trim() ? password : existingSettings.smtp.password,
|
||||
},
|
||||
|
||||
@@ -5,6 +5,7 @@ import { redirect } from "next/navigation";
|
||||
import { isRedirectError } from "next/dist/client/components/redirect";
|
||||
|
||||
import { clearAdminSessionCookie, isAdminAuthenticated } from "@/lib/admin-auth";
|
||||
import { isCheckedFormValue } from "@/lib/form-data";
|
||||
import {
|
||||
getContactProtectionSettings,
|
||||
updateContactProtectionSettings,
|
||||
@@ -39,10 +40,10 @@ function parseContactProtectionFormData(
|
||||
formData: FormData,
|
||||
existingSettings: ContactProtectionSettings,
|
||||
): ContactProtectionSettings {
|
||||
const turnstileEnabled = formData.get("turnstileEnabled") === "on";
|
||||
const turnstileEnabled = isCheckedFormValue(formData.get("turnstileEnabled"));
|
||||
const turnstileSiteKey = String(formData.get("turnstileSiteKey") ?? "").trim();
|
||||
const turnstileSecretKey = String(formData.get("turnstileSecretKey") ?? "");
|
||||
const rateLimitEnabled = formData.get("contactRateLimitEnabled") === "on";
|
||||
const rateLimitEnabled = isCheckedFormValue(formData.get("contactRateLimitEnabled"));
|
||||
|
||||
if (turnstileEnabled && !turnstileSiteKey) {
|
||||
throw new Error("Turnstile site key is required when Turnstile is enabled.");
|
||||
|
||||
Reference in New Issue
Block a user