@@ -3,6 +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 { ZodError } from "zod";
|
||||
|
||||
import { routing } from "@/i18n/routing";
|
||||
@@ -136,6 +137,10 @@ export async function upsertCategoryAction(formData: FormData) {
|
||||
await revalidatePortfolioPages();
|
||||
redirect(withMessage(redirectPath, "success", "Category saved."));
|
||||
} catch (error) {
|
||||
if (isRedirectError(error)) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
const message =
|
||||
error instanceof ZodError
|
||||
? parseZodError(error)
|
||||
@@ -172,7 +177,11 @@ export async function deleteCategoryAction(formData: FormData) {
|
||||
|
||||
await revalidatePortfolioPages();
|
||||
redirect(withMessage(redirectPath, "success", "Category deleted."));
|
||||
} catch {
|
||||
} catch (error) {
|
||||
if (isRedirectError(error)) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
redirect(withMessage(redirectPath, "error", "Unable to delete category."));
|
||||
}
|
||||
}
|
||||
@@ -515,6 +524,10 @@ export async function saveProjectAction(formData: FormData) {
|
||||
withMessage(`/root/portfolio/projects/${projectResult.project.id}`, "success", "Project saved."),
|
||||
);
|
||||
} catch (error) {
|
||||
if (isRedirectError(error)) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
const message =
|
||||
error instanceof ZodError
|
||||
? parseZodError(error)
|
||||
@@ -564,12 +577,6 @@ export async function deleteProjectAction(formData: FormData) {
|
||||
redirect(withMessage("/root/portfolio/projects", "error", "Project not found."));
|
||||
}
|
||||
|
||||
const projectPaths = collectUniqueManagedPaths([
|
||||
project.coverImagePath,
|
||||
...project.sections.map((section) => section.imagePath),
|
||||
...project.assets.map((asset) => asset.filePath),
|
||||
]);
|
||||
|
||||
await prisma.portfolioProject.delete({
|
||||
where: {
|
||||
id,
|
||||
@@ -585,7 +592,11 @@ export async function deleteProjectAction(formData: FormData) {
|
||||
}
|
||||
|
||||
redirect(withMessage("/root/portfolio/projects", "success", "Project deleted."));
|
||||
} catch {
|
||||
} catch (error) {
|
||||
if (isRedirectError(error)) {
|
||||
throw error;
|
||||
}
|
||||
|
||||
redirect(withMessage("/root/portfolio/projects", "error", "Unable to delete project."));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user