@@ -3,7 +3,7 @@
|
||||
import { MediaUsageType, Prisma } from "@prisma/client";
|
||||
import { revalidatePath } from "next/cache";
|
||||
import { redirect } from "next/navigation";
|
||||
import { isRedirectError } from "next/dist/client/components/redirect";
|
||||
import { isRedirectError } from "next/dist/client/components/redirect-error";
|
||||
import { ZodError } from "zod";
|
||||
|
||||
import { routing } from "@/i18n/routing";
|
||||
@@ -23,9 +23,9 @@ import {
|
||||
sectionInputSchema,
|
||||
} from "@/lib/portfolio-validation";
|
||||
|
||||
function ensureAdmin() {
|
||||
if (!isAdminAuthenticated()) {
|
||||
clearAdminSessionCookie();
|
||||
async function ensureAdmin() {
|
||||
if (!(await isAdminAuthenticated())) {
|
||||
await clearAdminSessionCookie();
|
||||
redirect("/");
|
||||
}
|
||||
}
|
||||
@@ -105,7 +105,7 @@ async function removeManagedPaths(paths: string[]) {
|
||||
}
|
||||
|
||||
export async function upsertCategoryAction(formData: FormData) {
|
||||
ensureAdmin();
|
||||
await ensureAdmin();
|
||||
|
||||
const redirectPath = getRedirectPath(formData, "/portfolio/categories");
|
||||
|
||||
@@ -155,7 +155,7 @@ export async function upsertCategoryAction(formData: FormData) {
|
||||
}
|
||||
|
||||
export async function deleteCategoryAction(formData: FormData) {
|
||||
ensureAdmin();
|
||||
await ensureAdmin();
|
||||
|
||||
const redirectPath = getRedirectPath(formData, "/portfolio/categories");
|
||||
const id = String(formData.get("id") ?? "");
|
||||
@@ -189,7 +189,7 @@ export async function deleteCategoryAction(formData: FormData) {
|
||||
}
|
||||
|
||||
export async function saveProjectAction(formData: FormData) {
|
||||
ensureAdmin();
|
||||
await ensureAdmin();
|
||||
|
||||
const fallbackRedirect = String(formData.get("id") ?? "").trim()
|
||||
? `/portfolio/projects/${String(formData.get("id") ?? "").trim()}`
|
||||
@@ -564,7 +564,7 @@ export async function saveProjectAction(formData: FormData) {
|
||||
}
|
||||
|
||||
export async function deleteProjectAction(formData: FormData) {
|
||||
ensureAdmin();
|
||||
await ensureAdmin();
|
||||
|
||||
const id = String(formData.get("id") ?? "");
|
||||
|
||||
|
||||
@@ -23,14 +23,14 @@ const copy = {
|
||||
};
|
||||
|
||||
export default async function RootPortfolioCategoriesPage() {
|
||||
if (!isAdminAuthenticated()) {
|
||||
if (!(await isAdminAuthenticated())) {
|
||||
redirect("/");
|
||||
}
|
||||
|
||||
async function logoutAction() {
|
||||
"use server";
|
||||
|
||||
clearAdminSessionCookie();
|
||||
await clearAdminSessionCookie();
|
||||
redirect("/");
|
||||
}
|
||||
|
||||
|
||||
@@ -21,31 +21,33 @@ const copy = {
|
||||
};
|
||||
|
||||
type RootPortfolioPageProps = {
|
||||
searchParams?: {
|
||||
searchParams?: Promise<{
|
||||
category?: string;
|
||||
status?: "all" | "draft" | "published";
|
||||
success?: string;
|
||||
error?: string;
|
||||
};
|
||||
}>;
|
||||
};
|
||||
|
||||
export default async function RootPortfolioPage({ searchParams }: RootPortfolioPageProps) {
|
||||
if (!isAdminAuthenticated()) {
|
||||
const resolvedSearchParams = await searchParams;
|
||||
|
||||
if (!(await isAdminAuthenticated())) {
|
||||
redirect("/");
|
||||
}
|
||||
|
||||
async function logoutAction() {
|
||||
"use server";
|
||||
|
||||
clearAdminSessionCookie();
|
||||
await clearAdminSessionCookie();
|
||||
redirect("/");
|
||||
}
|
||||
|
||||
const selectedCategory = searchParams?.category && searchParams.category !== "__all__"
|
||||
? searchParams.category
|
||||
const selectedCategory = resolvedSearchParams?.category && resolvedSearchParams.category !== "__all__"
|
||||
? resolvedSearchParams.category
|
||||
: "";
|
||||
const selectedStatus = searchParams?.status === "draft" || searchParams?.status === "published"
|
||||
? searchParams.status
|
||||
const selectedStatus = resolvedSearchParams?.status === "draft" || resolvedSearchParams?.status === "published"
|
||||
? resolvedSearchParams.status
|
||||
: "all";
|
||||
const [categories, projects] = await Promise.all([
|
||||
getAdminPortfolioCategories(),
|
||||
|
||||
@@ -44,29 +44,31 @@ const copy = {
|
||||
};
|
||||
|
||||
type RootPortfolioProjectPageProps = {
|
||||
params: {
|
||||
params: Promise<{
|
||||
id: string;
|
||||
};
|
||||
}>;
|
||||
};
|
||||
|
||||
export default async function RootPortfolioProjectPage({
|
||||
params,
|
||||
}: RootPortfolioProjectPageProps) {
|
||||
if (!isAdminAuthenticated()) {
|
||||
if (!(await isAdminAuthenticated())) {
|
||||
redirect("/");
|
||||
}
|
||||
|
||||
async function logoutAction() {
|
||||
"use server";
|
||||
|
||||
clearAdminSessionCookie();
|
||||
await clearAdminSessionCookie();
|
||||
redirect("/");
|
||||
}
|
||||
|
||||
const { id } = await params;
|
||||
|
||||
const [categories, mediaOptions, project] = await Promise.all([
|
||||
getActivePortfolioCategories(),
|
||||
getMediaOptions(),
|
||||
getAdminPortfolioProjectById(params.id),
|
||||
getAdminPortfolioProjectById(id),
|
||||
]);
|
||||
|
||||
if (!project) {
|
||||
|
||||
@@ -25,14 +25,14 @@ const copy = {
|
||||
};
|
||||
|
||||
export default async function RootNewPortfolioProjectPage() {
|
||||
if (!isAdminAuthenticated()) {
|
||||
if (!(await isAdminAuthenticated())) {
|
||||
redirect("/");
|
||||
}
|
||||
|
||||
async function logoutAction() {
|
||||
"use server";
|
||||
|
||||
clearAdminSessionCookie();
|
||||
await clearAdminSessionCookie();
|
||||
redirect("/");
|
||||
}
|
||||
|
||||
|
||||
@@ -21,31 +21,33 @@ const copy = {
|
||||
};
|
||||
|
||||
type RootPortfolioProjectsPageProps = {
|
||||
searchParams?: {
|
||||
searchParams?: Promise<{
|
||||
category?: string;
|
||||
status?: "all" | "draft" | "published";
|
||||
};
|
||||
}>;
|
||||
};
|
||||
|
||||
export default async function RootPortfolioProjectsPage({
|
||||
searchParams,
|
||||
}: RootPortfolioProjectsPageProps) {
|
||||
if (!isAdminAuthenticated()) {
|
||||
const resolvedSearchParams = await searchParams;
|
||||
|
||||
if (!(await isAdminAuthenticated())) {
|
||||
redirect("/");
|
||||
}
|
||||
|
||||
async function logoutAction() {
|
||||
"use server";
|
||||
|
||||
clearAdminSessionCookie();
|
||||
await clearAdminSessionCookie();
|
||||
redirect("/");
|
||||
}
|
||||
|
||||
const selectedCategory = searchParams?.category && searchParams.category !== "__all__"
|
||||
? searchParams.category
|
||||
const selectedCategory = resolvedSearchParams?.category && resolvedSearchParams.category !== "__all__"
|
||||
? resolvedSearchParams.category
|
||||
: "";
|
||||
const selectedStatus = searchParams?.status === "draft" || searchParams?.status === "published"
|
||||
? searchParams.status
|
||||
const selectedStatus = resolvedSearchParams?.status === "draft" || resolvedSearchParams?.status === "published"
|
||||
? resolvedSearchParams.status
|
||||
: "all";
|
||||
const [categories, projects] = await Promise.all([
|
||||
getAdminPortfolioCategories(),
|
||||
|
||||
Reference in New Issue
Block a user