diff --git a/apps/roboshield/next.config.mjs b/apps/roboshield/next.config.mjs index 38c5c24cd..1cb3e068d 100644 --- a/apps/roboshield/next.config.mjs +++ b/apps/roboshield/next.config.mjs @@ -31,6 +31,16 @@ const nextConfig = { config.experiments = { ...config.experiments, topLevelAwait: true }; // eslint-disable-line no-param-reassign return config; }, + images: { + remotePatterns: [ + { + protocol: 'http', + hostname: 'localhost', + port: '3000', + pathname: '**', + }, + ], + }, }; export default withSentryConfig(nextConfig, { diff --git a/apps/roboshield/payload-types.ts b/apps/roboshield/payload-types.ts index 0251bfb07..1322dcbe6 100644 --- a/apps/roboshield/payload-types.ts +++ b/apps/roboshield/payload-types.ts @@ -11,11 +11,11 @@ export interface Config { media: Media; pages: Page; users: User; - "payload-preferences": PayloadPreference; - "payload-migrations": PayloadMigration; + 'payload-preferences': PayloadPreference; + 'payload-migrations': PayloadMigration; }; globals: { - "settings-site": SettingsSite; + 'settings-site': SettingsSite; }; } /** @@ -47,13 +47,137 @@ export interface Page { fullTitle?: string | null; slug?: string | null; blocks?: - | { - title: string; - subtitle: string; - id?: string | null; - blockName?: string | null; - blockType: "page-header"; - }[] + | ( + | { + title: string; + subtitle: string; + id?: string | null; + blockName?: string | null; + blockType: 'page-header'; + } + | { + toolTipText: string; + steps?: + | ( + | { + title: string; + hint?: + | { + [k: string]: unknown; + }[] + | null; + defaultFetchExistingRobots?: boolean | null; + existingRobotsTxt: string; + placeholder: string; + urlValidationError: string; + fetch: string; + id?: string | null; + blockName?: string | null; + blockType: 'existing-robots'; + } + | { + title: string; + hint?: + | { + [k: string]: unknown; + }[] + | null; + crawlDelay: { + label: string; + title: string; + }; + cacheDelay: { + label: string; + title: string; + }; + visitTime: { + label: string; + title: string; + }; + id?: string | null; + blockName?: string | null; + blockType: 'delays'; + } + | { + title: string; + hint?: + | { + [k: string]: unknown; + }[] + | null; + selectPlatform: { + label: string; + title: string; + }; + disallowedPaths: { + label: string; + title: string; + }; + allowedPaths: { + label: string; + title: string; + }; + id?: string | null; + blockName?: string | null; + blockType: 'paths'; + } + | { + title: string; + hint?: + | { + [k: string]: unknown; + }[] + | null; + aiWebCrawlers: { + label: string; + title: string; + }; + searchEngineCrawlers: { + label: string; + title: string; + }; + id?: string | null; + blockName?: string | null; + blockType: 'block-bots'; + } + | { + title: string; + hint?: + | { + [k: string]: unknown; + }[] + | null; + placeholder: string; + id?: string | null; + blockName?: string | null; + blockType: 'site-maps'; + } + | { + title: string; + hint?: + | { + [k: string]: unknown; + }[] + | null; + placeholder: string; + id?: string | null; + blockName?: string | null; + blockType: 'finish'; + } + )[] + | null; + labels: { + continue: string; + back: string; + reset: string; + download: string; + copyToClipboard: string; + }; + id?: string | null; + blockName?: string | null; + blockType: 'robo-form'; + } + )[] | null; meta?: { title?: string | null; @@ -71,7 +195,7 @@ export interface Page { | null; updatedAt: string; createdAt: string; - _status?: ("draft" | "published") | null; + _status?: ('draft' | 'published') | null; } /** * This interface was referenced by `Config`'s JSON-Schema @@ -81,7 +205,7 @@ export interface User { id: string; firstName: string; lastName: string; - roles: ("admin" | "editor")[]; + roles: ('admin' | 'editor')[]; updatedAt: string; createdAt: string; email: string; @@ -102,7 +226,7 @@ export interface User { export interface PayloadPreference { id: string; user: { - relationTo: "users"; + relationTo: 'users'; value: string | User; }; key?: string | null; @@ -145,9 +269,9 @@ export interface SettingsSite { menus?: | { label: string; - linkType?: ("custom" | "internal") | null; + linkType?: ('custom' | 'internal') | null; doc?: { - relationTo: "pages"; + relationTo: 'pages'; value: string | Page; } | null; url?: string | null; @@ -155,17 +279,15 @@ export interface SettingsSite { id?: string | null; }[] | null; - connect?: - | ("Facebook" | "Twitter" | "Instagram" | "Linkedin" | "Github" | "Slack") - | null; + connect?: ('Facebook' | 'Twitter' | 'Instagram' | 'Linkedin' | 'Github' | 'Slack') | null; }; secondaryNavigation?: { menus?: | { label: string; - linkType?: ("custom" | "internal") | null; + linkType?: ('custom' | 'internal') | null; doc?: { - relationTo: "pages"; + relationTo: 'pages'; value: string | Page; } | null; url?: string | null; @@ -178,13 +300,7 @@ export interface SettingsSite { title: string; links?: | { - platform: - | "Facebook" - | "Twitter" - | "Instagram" - | "Linkedin" - | "Github" - | "Slack"; + platform: 'Facebook' | 'Twitter' | 'Instagram' | 'Linkedin' | 'Github' | 'Slack'; url: string; id?: string | null; }[] @@ -204,9 +320,9 @@ export interface SettingsSite { name: string; logo: string | Media; label: string; - linkType?: ("custom" | "internal") | null; + linkType?: ('custom' | 'internal') | null; doc?: { - relationTo: "pages"; + relationTo: 'pages'; value: string | Page; } | null; url?: string | null; @@ -219,6 +335,7 @@ export interface SettingsSite { createdAt?: string | null; } -declare module "payload" { + +declare module 'payload' { export interface GeneratedTypes extends Config {} -} +} \ No newline at end of file diff --git a/apps/roboshield/src/components/BlockRenderer/BlockRenderer.tsx b/apps/roboshield/src/components/BlockRenderer/BlockRenderer.tsx index 759cf72b4..60d6aaff0 100644 --- a/apps/roboshield/src/components/BlockRenderer/BlockRenderer.tsx +++ b/apps/roboshield/src/components/BlockRenderer/BlockRenderer.tsx @@ -1,17 +1,20 @@ import PageHeader from "@/roboshield/components/PageHeader/PageHeader"; import { Page } from "@/root/payload-types"; +import RoboForm from "@/roboshield/components/RoboForm"; +import { FC } from "react"; interface BlockRendererProps extends Pick {} const components = { "page-header": PageHeader, + "robo-form": RoboForm, }; export default function BlockRenderer({ blocks }: BlockRendererProps) { return ( <> {blocks?.map((block, index) => { - const Component = components[block.blockType]; + const Component: FC = components[block.blockType]; if (Component) { return ; diff --git a/apps/roboshield/src/components/CommonSettings/CommonSettings.tsx b/apps/roboshield/src/components/CommonSettings/CommonSettings.tsx index 03071d22d..e282c3e51 100644 --- a/apps/roboshield/src/components/CommonSettings/CommonSettings.tsx +++ b/apps/roboshield/src/components/CommonSettings/CommonSettings.tsx @@ -18,7 +18,11 @@ import { platforms } from "@/roboshield/lib/config"; import { StepComponent } from "@/roboshield/types/stepComponent"; import SkipToLastStep from "@/roboshield/components/SkipToLastStep"; import StepHint from "@/roboshield/components/StepHint"; -import { LabelNode } from "@/roboshield/lib/data/payload.types"; + +interface LabelNode { + title: string; + label: string; +} interface Props extends StepComponent { selectPlatform?: LabelNode; diff --git a/apps/roboshield/src/components/Delays/Delays.tsx b/apps/roboshield/src/components/Delays/Delays.tsx index e11d4f26b..2bd0d7572 100644 --- a/apps/roboshield/src/components/Delays/Delays.tsx +++ b/apps/roboshield/src/components/Delays/Delays.tsx @@ -10,7 +10,11 @@ import { useGlobalState } from "@/roboshield/context/GlobalContext"; import { StepComponent } from "@/roboshield/types/stepComponent"; import SkipToLastStep from "@/roboshield/components/SkipToLastStep"; import StepHint from "@/roboshield/components/StepHint"; -import { LabelNode } from "@/roboshield/lib/data/payload.types"; + +interface LabelNode { + title: string; + label: string; +} interface Props extends StepComponent { crawlDelay?: LabelNode; diff --git a/apps/roboshield/src/components/PageHeader/PageHeader.tsx b/apps/roboshield/src/components/PageHeader/PageHeader.tsx index c856793b0..51425ebce 100644 --- a/apps/roboshield/src/components/PageHeader/PageHeader.tsx +++ b/apps/roboshield/src/components/PageHeader/PageHeader.tsx @@ -9,7 +9,10 @@ type PageHeaderProps = ExtractBlockType< "page-header" >; -export default function PageHeader({ title, subtitle }: PageHeaderProps) { +export default function PageHeader({ + title, + subtitle, +}: PageHeaderProps): JSX.Element { return ( <> diff --git a/apps/roboshield/src/lib/data/blockify/index.ts b/apps/roboshield/src/lib/data/blockify/index.ts index d13774217..96454043e 100644 --- a/apps/roboshield/src/lib/data/blockify/index.ts +++ b/apps/roboshield/src/lib/data/blockify/index.ts @@ -16,9 +16,11 @@ type PropsifyBlockBySlug = { >; }; -const pageHeader: PropsifyBlockFunction< - ExtractBlockType[number], "page-header"> -> = async (block, api) => { +type BlockType = ExtractBlockType< + NonNullable[number], + "page-header" +>; +const pageHeader: PropsifyBlockFunction = async (block, api) => { // some block specific computation, i.e using api return { ...block, @@ -36,7 +38,7 @@ export const blockify = async (blocks: Page["blocks"], api: Api) => { const slug = block.blockType as NonNullable< Page["blocks"] >[number]["blockType"]; - const propsifyBlock = propsifyBlockBySlug[slug]; + const propsifyBlock = propsifyBlockBySlug[slug] as any; if (propsifyBlock) { return propsifyBlock(block, api); diff --git a/apps/roboshield/src/lib/data/blockify/processBlockRoboForm.ts b/apps/roboshield/src/lib/data/blockify/processBlockRoboForm.ts index e019e29dd..9acc1e5d6 100644 --- a/apps/roboshield/src/lib/data/blockify/processBlockRoboForm.ts +++ b/apps/roboshield/src/lib/data/blockify/processBlockRoboForm.ts @@ -1,4 +1,11 @@ -import { Api } from "../payload.types"; +import { Page } from "@/root/payload-types"; +import { Api } from "@/roboshield/lib/payload"; +import { ExtractBlockType } from "@/roboshield/utils/blocks"; + +type PropsifyBlockFunction = ( + block: T, + api: Api, +) => Promise; function sortSteps(steps: any[]) { const stepOrder: string[] = [ @@ -14,7 +21,9 @@ function sortSteps(steps: any[]) { ); } -async function processBlockRoboForm(block: any, api: Api) { +const processBlockRoboForm: PropsifyBlockFunction< + ExtractBlockType[number], "robo-form"> +> = async (block, api) => { const steps = sortSteps(block.steps ?? []); return { @@ -22,6 +31,6 @@ async function processBlockRoboForm(block: any, api: Api) { slug: "robo-form", steps, }; -} +}; export default processBlockRoboForm; diff --git a/apps/roboshield/src/pages/index.tsx b/apps/roboshield/src/pages/index.tsx index e368b0bbe..0f47872e3 100644 --- a/apps/roboshield/src/pages/index.tsx +++ b/apps/roboshield/src/pages/index.tsx @@ -2,7 +2,6 @@ import { getPageServerSideProps } from "@/roboshield/lib/data"; import RoboForm from "@/roboshield/components/RoboForm"; import Hero from "@/roboshield/components/Hero"; import { useRef } from "react"; -import { Block } from "payload/types"; export default function Index(props: any) { const scrolRef = useRef(null); diff --git a/apps/roboshield/src/payload/Blocks/RoboForm.ts b/apps/roboshield/src/payload/Blocks/RoboForm.ts index e9ef92b5b..855307715 100644 --- a/apps/roboshield/src/payload/Blocks/RoboForm.ts +++ b/apps/roboshield/src/payload/Blocks/RoboForm.ts @@ -16,8 +16,11 @@ const ExistingRobots: Block = { label: "Hint", defaultValue: [ { - children: null, - text: "Start by fetching the robots.txt file of the website you want to generate robots for.", + children: [ + { + text: "Start by fetching the robots.txt file of the website you want to generate robots for.", + }, + ], }, ], }) as unknown as Field, @@ -70,8 +73,11 @@ const Delays: Block = { label: "Hint", defaultValue: [ { - children: null, - text: "You can set bot delays for the robots you want to generate.", + children: [ + { + text: "You can set bot delays for the robots you want to generate.", + }, + ], }, ], }) as unknown as Field, @@ -150,8 +156,11 @@ const Paths: Block = { label: "hint", defaultValue: [ { - text: "You can set disallowed and allowed paths for the robots you want to generate. All paths should be relative to the root of your site and end with a /", - children: null, + children: [ + { + text: "You can set disallowed and allowed paths for the robots you want to generate. All paths should be relative to the root of your site and end with a /", + }, + ], }, ], }) as unknown as Field, @@ -230,8 +239,11 @@ const BlockBots: Block = { name: "hint", defaultValue: [ { - text: "Select bots you want to block from crawling your website.", - children: null, + children: [ + { + text: "Select bots you want to block from crawling your website.", + }, + ], }, ], }) as unknown as Field, @@ -291,8 +303,9 @@ const SiteMaps: Block = { name: "hint", defaultValue: [ { - text: "You can add sitemap URLs to your robots.txt file.", - children: null, + children: [ + { text: "You can add sitemap URLs to your robots.txt file." }, + ], }, ], }) as unknown as Field, @@ -319,8 +332,11 @@ const Finish: Block = { name: "hint", defaultValue: [ { - children: null, - text: "Your robots.txt file has been generated successfully. You can now copy the code or download the file.", + children: [ + { + text: "Your robots.txt file has been generated successfully. You can now copy the code or download the file.", + }, + ], }, ], }) as unknown as Field, diff --git a/apps/roboshield/src/payload/collections/Pages.ts b/apps/roboshield/src/payload/collections/Pages.ts index b8a2d00e0..28eab0f2d 100644 --- a/apps/roboshield/src/payload/collections/Pages.ts +++ b/apps/roboshield/src/payload/collections/Pages.ts @@ -1,7 +1,7 @@ import { CollectionConfig } from "payload/types"; import fullTitle from "../fields/fullTitle"; import slug from "../fields/slug"; -import RoboForm from "../Blocks/RoboForm"; +import RoboForm from "../blocks/RoboForm"; import { PageHeader } from "../blocks/PageHeader"; const Pages: CollectionConfig = {