feat(editorial): validate publications and preserve partial event updates
This commit is contained in:
1 parent
76f0420d64
commit
db4acbb46e
14 files changed
+613
-16
No files matched your search
@@ -1,3 +1,4 @@
|
||||
import { publicationIssues } from "./publication-preflight";
|
||||
import type { ActionResult } from "./safe-action-shared";
|
||||
export type ArticleSaveResult = ActionResult<{ redirectTo: string }>;
|
||||
export class ArticleInputError extends Error {
|
||||
@@ -10,7 +11,9 @@ export class ArticleInputError extends Error {
|
||||
| "summaryTooLong"
|
||||
| "imageTooLong"
|
||||
| "invalidStatus"
|
||||
| "publishDateRequired",
|
||||
| "publishDateRequired"
|
||||
| "imageInvalid"
|
||||
| "linksInvalid",
|
||||
) {
|
||||
super(code);
|
||||
}
|
||||
@@ -34,6 +37,17 @@ export function readArticleInput(form: FormData) {
|
||||
const publishAt = status === "scheduled" ? new Date(text("publishAt")) : null;
|
||||
if (publishAt && Number.isNaN(publishAt.getTime()))
|
||||
throw new ArticleInputError("publishDateRequired");
|
||||
if (status !== "draft") {
|
||||
const issue = publicationIssues({
|
||||
kind: "article",
|
||||
image,
|
||||
body: fullStory,
|
||||
status,
|
||||
publishAt,
|
||||
}).find((issue) => issue.severity === "error");
|
||||
if (issue?.code === "imageInvalid" || issue?.code === "linksInvalid")
|
||||
throw new ArticleInputError(issue.code);
|
||||
}
|
||||
return {
|
||||
title,
|
||||
shortStory,
|
||||
@@ -57,6 +71,8 @@ export function articleInputField(
|
||||
titleTooLong: "title",
|
||||
summaryTooLong: "shortStory",
|
||||
imageTooLong: "image",
|
||||
imageInvalid: "image",
|
||||
linksInvalid: "fullStory",
|
||||
invalidStatus: "status",
|
||||
publishDateRequired: "publishAt",
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user