Skip to content

Commit

Permalink
enhancement: Set initial configurations for Payload live preview
Browse files Browse the repository at this point in the history
  • Loading branch information
m453h committed Jul 15, 2024
1 parent d06032b commit aa387c5
Show file tree
Hide file tree
Showing 5 changed files with 172 additions and 548 deletions.
1 change: 1 addition & 0 deletions apps/roboshield/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"@next/env": "^14.2.4",
"@payloadcms/bundler-webpack": "^1.0.7",
"@payloadcms/db-mongodb": "^1.5.2",
"@payloadcms/live-preview-react": "^0.2.0",
"@payloadcms/plugin-cloud-storage": "^1.1.3",
"@payloadcms/plugin-nested-docs": "^1.0.12",
"@payloadcms/plugin-sentry": "^0.0.6",
Expand Down
73 changes: 40 additions & 33 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 @@ -53,7 +53,7 @@ export interface Page {
subtitle: string;
id?: string | null;
blockName?: string | null;
blockType: 'page-header';
blockType: "page-header";
}
| SiteHero
| {
Expand All @@ -65,30 +65,30 @@ export interface Page {
}[];
id?: string | null;
blockName?: string | null;
blockType: 'richtext';
blockType: "richtext";
}
| {
image: string | Media;
id?: string | null;
blockName?: string | null;
blockType: 'mediaBlock';
blockType: "mediaBlock";
}
| {
externalEmbedFields?: {
embedType?: ('url' | 'code') | null;
embedType?: ("url" | "code") | null;
url?: string | null;
caption?: string | null;
code?: string | null;
};
id?: string | null;
blockName?: string | null;
blockType: 'externalEmbed';
blockType: "externalEmbed";
}
)[]
| null;
id?: string | null;
blockName?: string | null;
blockType: 'content';
blockType: "content";
}
| {
title: string;
Expand All @@ -105,7 +105,7 @@ export interface Page {
| null;
id?: string | null;
blockName?: string | null;
blockType: 'statistics';
blockType: "statistics";
}
| {
steps?:
Expand All @@ -124,7 +124,7 @@ export interface Page {
fetch: string;
id?: string | null;
blockName?: string | null;
blockType: 'existing-robots-txt';
blockType: "existing-robots-txt";
}
| {
title: string;
Expand All @@ -147,7 +147,7 @@ export interface Page {
};
id?: string | null;
blockName?: string | null;
blockType: 'delays';
blockType: "delays";
}
| {
title: string;
Expand All @@ -170,7 +170,7 @@ export interface Page {
};
id?: string | null;
blockName?: string | null;
blockType: 'paths';
blockType: "paths";
}
| {
title: string;
Expand All @@ -189,7 +189,7 @@ export interface Page {
};
id?: string | null;
blockName?: string | null;
blockType: 'block-bots';
blockType: "block-bots";
}
| {
title: string;
Expand All @@ -201,7 +201,7 @@ export interface Page {
placeholder: string;
id?: string | null;
blockName?: string | null;
blockType: 'site-maps';
blockType: "site-maps";
}
| {
title: string;
Expand All @@ -213,7 +213,7 @@ export interface Page {
placeholder: string;
id?: string | null;
blockName?: string | null;
blockType: 'finish';
blockType: "finish";
}
)[]
| null;
Expand All @@ -227,7 +227,7 @@ export interface Page {
};
id?: string | null;
blockName?: string | null;
blockType: 'robots-txt-generator';
blockType: "robots-txt-generator";
}
)[]
| null;
Expand All @@ -247,7 +247,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 @@ -256,7 +256,7 @@ export interface Page {
export interface SiteHero {
heroHeaders?:
| {
headingType?: ('largeHeading' | 'subHeading' | 'rotatingText') | null;
headingType?: ("largeHeading" | "subHeading" | "rotatingText") | null;
title?: string | null;
id?: string | null;
}[]
Expand All @@ -267,7 +267,7 @@ export interface SiteHero {
heroCallToAction?: string | null;
id?: string | null;
blockName?: string | null;
blockType: 'page-hero';
blockType: "page-hero";
}
/**
* This interface was referenced by `Config`'s JSON-Schema
Expand All @@ -277,7 +277,7 @@ export interface User {
id: string;
firstName: string;
lastName: string;
roles: ('admin' | 'editor')[];
roles: ("admin" | "editor")[];
updatedAt: string;
createdAt: string;
email: string;
Expand All @@ -298,7 +298,7 @@ export interface User {
export interface PayloadPreference {
id: string;
user: {
relationTo: 'users';
relationTo: "users";
value: string | User;
};
key?: string | null;
Expand Down Expand Up @@ -341,25 +341,27 @@ 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 @@ -372,7 +374,13 @@ 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 @@ -392,9 +400,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 @@ -407,7 +415,6 @@ export interface SettingsSite {
createdAt?: string | null;
}


declare module 'payload' {
declare module "payload" {
export interface GeneratedTypes extends Config {}
}
}
10 changes: 10 additions & 0 deletions apps/roboshield/payload.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ export default buildConfig({
: undefined),
admin: {
user: Users.slug,
livePreview: {
breakpoints: [
{
label: "Mobile",
name: "mobile",
width: 375,
height: 667,
},
],
},
webpack: (config) => ({
...config,
resolve: {
Expand Down
4 changes: 4 additions & 0 deletions apps/roboshield/src/payload/collections/Pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ const Pages: CollectionConfig = {
group: "Publication",
useAsTitle: "title",
preview: (doc) => formatDraftUrl("pages", doc),
livePreview: {
url: ({ data }) =>
`${process.env.PAYLOAD_PUBLIC_APP_URL}${data.slug !== "home" ? `/${data.slug}` : ""}`,
},
},
fields: [
{
Expand Down
Loading

0 comments on commit aa387c5

Please sign in to comment.