Skip to content

Commit

Permalink
Partial type fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Kipruto <[email protected]>
  • Loading branch information
kelvinkipruto committed Jun 28, 2024
1 parent 2259ffe commit fca4657
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,22 +1,17 @@
import PageHeader from "@/roboshield/components/PageHeader/PageHeader";
import { Page } from "@/root/payload-types";

type BlockType = Page["blocks"];
interface BlockRendererProps {
blocks: BlockType;
}
interface BlockRendererProps extends Pick<Page, "blocks"> {}

const components = {
"page-header": PageHeader,
};

type BlockSlug = keyof typeof components;

export default function BlockRenderer({ blocks }: BlockRendererProps) {
return (
<>
{blocks?.map((block, index) => {
const Component = components[block.blockType as BlockSlug];
const Component = components[block.blockType];

if (Component) {
return <Component key={index} {...block} />;
Expand Down
12 changes: 7 additions & 5 deletions apps/roboshield/src/payload/fields/richText.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { deepmerge } from "@mui/utils";

import mapLinkTypeToHref, { NodeType } from "../utils/mapLinkTypeToHref";
import { Field, PayloadRequest } from "payload/types";
import { Field, FieldHook, PayloadRequest } from "payload/types";

async function insertHref(nodes: NodeType[] | null, payload: PayloadRequest) {
if (!nodes?.length) {
Expand Down Expand Up @@ -53,15 +53,17 @@ async function mapLinkToHrefAfterRead({
return insertHref(value, payload);
}

function richText(overrides: Partial<Field>) {
const richTextResult = {
function richText(overrides: Partial<Field>): Field {
const richTextResult: Partial<Field> = {
type: "richText",
hooks: {
afterRead: [mapLinkToHrefAfterRead],
afterRead: [
mapLinkToHrefAfterRead as unknown as FieldHook<any, any, any>,
],
},
};

return deepmerge(richTextResult, overrides);
return deepmerge(richTextResult, overrides) as Field;
}

export default richText;
3 changes: 2 additions & 1 deletion apps/roboshield/src/payload/globals/Site/EngagementTab.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Tab } from "payload/types";
import socialLinks from "../../fields/socialLinks";

const EngagementTab = {
const EngagementTab: Tab = {
label: "Engagement",
fields: [
{
Expand Down
3 changes: 2 additions & 1 deletion apps/roboshield/src/payload/globals/Site/GeneralTab.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { Tab } from "payload/types";
import image from "../../fields/image";
import richText from "../../fields/richText";

const GeneralTab = {
const GeneralTab: Tab = {
label: "General",
fields: [
{
Expand Down
3 changes: 2 additions & 1 deletion apps/roboshield/src/payload/globals/Site/InitiativeTab.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Tab } from "payload/types";
import image from "../../fields/image";
import link from "../../fields/links/link";
import richText from "../../fields/richText";

const PartnersTab = {
const PartnersTab: Tab = {
label: "Initiative",
fields: [
{
Expand Down
3 changes: 2 additions & 1 deletion apps/roboshield/src/payload/globals/Site/NavigationTab.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Tab } from "payload/types";
import link from "../../fields/links/link";
import linkArray from "../../fields/links/linkArray";
import { socialMediaOptions } from "../../fields/socialLinks";
Expand All @@ -6,7 +7,7 @@ const linkField = link({
disableOpenInNewTab: true,
});

const NavigationTab = {
const NavigationTab: Tab = {
label: "Navigation",
fields: [
{
Expand Down
3 changes: 2 additions & 1 deletion apps/roboshield/src/payload/globals/Site/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import EngagementTab from "./EngagementTab";
import GeneralTab from "./GeneralTab";
import NavigationTab from "./NavigationTab";
import InitiativeTab from "./InitiativeTab";
import { GlobalConfig } from "payload/types";

const Site = {
const Site: GlobalConfig = {
slug: "settings-site",
label: "Site",
access: {
Expand Down

0 comments on commit fca4657

Please sign in to comment.