Skip to content

Commit

Permalink
Update types
Browse files Browse the repository at this point in the history
  • Loading branch information
koechkevin committed Jul 1, 2024
1 parent d3c1b2e commit fd376d2
Show file tree
Hide file tree
Showing 11 changed files with 223 additions and 56 deletions.
10 changes: 10 additions & 0 deletions apps/roboshield/next.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down
179 changes: 148 additions & 31 deletions apps/roboshield/payload-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};
}
/**
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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;
Expand All @@ -102,7 +226,7 @@ export interface User {
export interface PayloadPreference {
id: string;
user: {
relationTo: "users";
relationTo: 'users';
value: string | User;
};
key?: string | null;
Expand Down Expand Up @@ -145,27 +269,25 @@ 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;
href: string;
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;
Expand All @@ -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;
}[]
Expand All @@ -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;
Expand All @@ -219,6 +335,7 @@ export interface SettingsSite {
createdAt?: string | null;
}

declare module "payload" {

declare module 'payload' {
export interface GeneratedTypes extends Config {}
}
}
Original file line number Diff line number Diff line change
@@ -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<Page, "blocks"> {}

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<any> = components[block.blockType];

if (Component) {
return <Component key={index} {...block} />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 5 additions & 1 deletion apps/roboshield/src/components/Delays/Delays.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 4 additions & 1 deletion apps/roboshield/src/components/PageHeader/PageHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
<>
<TwoToneBackground sx={{ backgroundColor: "background.default" }}>
Expand Down
10 changes: 6 additions & 4 deletions apps/roboshield/src/lib/data/blockify/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ type PropsifyBlockBySlug = {
>;
};

const pageHeader: PropsifyBlockFunction<
ExtractBlockType<NonNullable<Page["blocks"]>[number], "page-header">
> = async (block, api) => {
type BlockType = ExtractBlockType<
NonNullable<Page["blocks"]>[number],
"page-header"
>;
const pageHeader: PropsifyBlockFunction<BlockType> = async (block, api) => {
// some block specific computation, i.e using api
return {
...block,
Expand All @@ -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);
Expand Down
15 changes: 12 additions & 3 deletions apps/roboshield/src/lib/data/blockify/processBlockRoboForm.ts
Original file line number Diff line number Diff line change
@@ -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<T> = (
block: T,
api: Api,
) => Promise<T & { slug: string }>;

function sortSteps(steps: any[]) {
const stepOrder: string[] = [
Expand All @@ -14,14 +21,16 @@ function sortSteps(steps: any[]) {
);
}

async function processBlockRoboForm(block: any, api: Api) {
const processBlockRoboForm: PropsifyBlockFunction<
ExtractBlockType<NonNullable<Page["blocks"]>[number], "robo-form">
> = async (block, api) => {
const steps = sortSteps(block.steps ?? []);

return {
...block,
slug: "robo-form",
steps,
};
}
};

export default processBlockRoboForm;
1 change: 0 additions & 1 deletion apps/roboshield/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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<HTMLDivElement | null>(null);
Expand Down
Loading

0 comments on commit fd376d2

Please sign in to comment.