diff --git a/apps/roboshield/payload-types.ts b/apps/roboshield/payload-types.ts index f78ea8dbd..c2caf7ae0 100644 --- a/apps/roboshield/payload-types.ts +++ b/apps/roboshield/payload-types.ts @@ -55,6 +55,57 @@ export interface Page { blockName?: string | null; blockType: "page-header"; } + | { + content?: + | ( + | { + content: { + [k: string]: unknown; + }[]; + id?: string | null; + blockName?: string | null; + blockType: "richtext"; + } + | { + image: string | Media; + id?: string | null; + blockName?: string | null; + blockType: "mediaBlock"; + } + | { + externalEmbeddFields?: { + embedType?: ("url" | "code") | null; + url?: string | null; + caption?: string | null; + code?: string | null; + }; + id?: string | null; + blockName?: string | null; + blockType: "externalEmbedd"; + } + )[] + | null; + id?: string | null; + blockName?: string | null; + blockType: "content"; + } + | { + title: string; + statistics?: + | { + name: string; + value: string; + description: { + [k: string]: unknown; + }[]; + icon?: string | Media | null; + id?: string | null; + }[] + | null; + id?: string | null; + blockName?: string | null; + blockType: "statistics"; + } | { toolTipText: string; steps?: diff --git a/apps/roboshield/src/components/BlockRenderer/BlockRenderer.tsx b/apps/roboshield/src/components/BlockRenderer/BlockRenderer.tsx index 60d6aaff0..fb633bc12 100644 --- a/apps/roboshield/src/components/BlockRenderer/BlockRenderer.tsx +++ b/apps/roboshield/src/components/BlockRenderer/BlockRenderer.tsx @@ -1,4 +1,6 @@ -import PageHeader from "@/roboshield/components/PageHeader/PageHeader"; +import PageHeader from "@/roboshield/components/PageHeader"; +import Content from "@/roboshield/components/Content"; +import Statistics from "@/roboshield/components/Statistics"; import { Page } from "@/root/payload-types"; import RoboForm from "@/roboshield/components/RoboForm"; import { FC } from "react"; @@ -7,17 +9,19 @@ interface BlockRendererProps extends Pick {} const components = { "page-header": PageHeader, + content: Content, + statistics: Statistics, "robo-form": RoboForm, }; export default function BlockRenderer({ blocks }: BlockRendererProps) { return ( <> - {blocks?.map((block, index) => { + {blocks?.map((block) => { const Component: FC = components[block.blockType]; if (Component) { - return ; + return ; } return null; diff --git a/apps/roboshield/src/components/Content/Content.tsx b/apps/roboshield/src/components/Content/Content.tsx new file mode 100644 index 000000000..d01bbb7ae --- /dev/null +++ b/apps/roboshield/src/components/Content/Content.tsx @@ -0,0 +1,63 @@ +import { Section } from "@commons-ui/core"; +import { Page } from "@/root/payload-types"; +import { + ExtractBlockType, + ExtractNestedBlockType, +} from "@/roboshield/utils/blocks"; +import LongFormRichText from "@/roboshield/components/LongFormRichText"; +import LongFormMedia from "@/roboshield/components/LongFormMedia"; +import LongFormExternalEmbed from "@/roboshield/components/LongFormExternalEmbed"; + +type ContentProps = ExtractBlockType< + NonNullable[number], + "content" +>; + +export type ExternalEmbeddBlock = ExtractNestedBlockType< + NonNullable[number], + "externalEmbedd" +>; + +export type RichTextBlock = ExtractNestedBlockType< + NonNullable[number], + "richtext" +>; + +export type MediaBlock = ExtractNestedBlockType< + NonNullable[number], + "mediaBlock" +>; + +type ComponentMap = { + richtext: (props: RichTextBlock) => JSX.Element; + mediaBlock?: (props: MediaBlock) => JSX.Element; + externalEmbedd?: (props: ExternalEmbeddBlock) => JSX.Element; +}; +export default function Content({ content }: ContentProps) { + const COMPONENT_BY_CONTENT_TYPE: ComponentMap = { + richtext: LongFormRichText, + mediaBlock: LongFormMedia, + externalEmbedd: LongFormExternalEmbed, + }; + + return ( +
+ {content?.map((child) => { + const Component = COMPONENT_BY_CONTENT_TYPE[child.blockType]; + + if (Component) { + return ; + } + + return null; + })} +
+ ); +} diff --git a/apps/roboshield/src/components/Content/index.ts b/apps/roboshield/src/components/Content/index.ts new file mode 100644 index 000000000..7238170d4 --- /dev/null +++ b/apps/roboshield/src/components/Content/index.ts @@ -0,0 +1,3 @@ +import Content from "./Content"; + +export default Content; diff --git a/apps/roboshield/src/components/LongFormExternalEmbed/LongFormExternalEmbed.tsx b/apps/roboshield/src/components/LongFormExternalEmbed/LongFormExternalEmbed.tsx new file mode 100644 index 000000000..7f75a2a79 --- /dev/null +++ b/apps/roboshield/src/components/LongFormExternalEmbed/LongFormExternalEmbed.tsx @@ -0,0 +1,30 @@ +import { RichTypography } from "@commons-ui/core"; +import { Box } from "@mui/material"; +import React from "react"; +import { ExternalEmbeddBlock } from "@/roboshield/components/Content/Content"; + +export default function LongFormExternalEmbed(props: ExternalEmbeddBlock) { + const { externalEmbeddFields: { code = "", caption = "", url = "" } = {} } = + props; + + return ( + + {code && {code}} + {url && ( +