Skip to content

Commit

Permalink
Add block fields validation
Browse files Browse the repository at this point in the history
  • Loading branch information
koechkevin committed Jul 2, 2024
1 parent d9aec57 commit b868212
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions apps/roboshield/src/payload/Blocks/RoboForm.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Block, Field } from "payload/types";
import richText from "../fields/richText";
import { blocks } from "payload/dist/fields/validations";

const ExistingRobots: Block = {
slug: "existing-robots",
Expand Down Expand Up @@ -404,6 +405,26 @@ const RoboForm: Block = {
admin: {
initCollapsed: true,
},
validate: (value, args) => {
const requiredSteps: string[] = [
"existing-robots",
"delays",
"paths",
"block-bots",
"site-maps",
"finish",
];
const missingSteps = requiredSteps.filter(
(slug) =>
!value?.find(
({ blockType }: { blockType: string }) => blockType === slug,
),
);
if (missingSteps.length) {
return `The following steps are missing: ${missingSteps.join(", ")}`;
}
return blocks(value, args);
},
},
Labels,
],
Expand Down

0 comments on commit b868212

Please sign in to comment.