134 lines
3.9 KiB
TypeScript
134 lines
3.9 KiB
TypeScript
import { payloadCloudPlugin } from '@payloadcms/payload-cloud'
|
|
import { multiTenantPlugin } from '@payloadcms/plugin-multi-tenant'
|
|
import { formBuilderPlugin } from '@payloadcms/plugin-form-builder'
|
|
import { nestedDocsPlugin } from '@payloadcms/plugin-nested-docs'
|
|
import { redirectsPlugin } from '@payloadcms/plugin-redirects'
|
|
import { seoPlugin } from '@payloadcms/plugin-seo'
|
|
import { searchPlugin } from '@payloadcms/plugin-search'
|
|
import { Plugin } from 'payload'
|
|
import { revalidateRedirects } from '@/hooks/revalidateRedirects'
|
|
import { GenerateTitle, GenerateURL } from '@payloadcms/plugin-seo/types'
|
|
import { FixedToolbarFeature, HeadingFeature, lexicalEditor } from '@payloadcms/richtext-lexical'
|
|
import { searchFields } from '@/search/fieldOverrides'
|
|
import { beforeSyncWithSearch } from '@/search/beforeSync'
|
|
|
|
import { Config, Page, Post, User } from '@/payload-types'
|
|
import { getServerSideURL } from '@/utilities/getURL'
|
|
import { isSuperAdmin } from '@/access/isSuperAdmin'
|
|
import { getUserTenantIDs } from '@/utilities/getUserTenantIds'
|
|
|
|
const generateTitle: GenerateTitle<Post | Page> = ({ doc }) => {
|
|
return doc?.title ? `${doc.title} | Payload Website Template` : 'Payload Website Template'
|
|
}
|
|
|
|
const generateURL: GenerateURL<Post | Page> = ({ doc }) => {
|
|
const url = getServerSideURL()
|
|
|
|
return doc?.slug ? `${url}/${doc.slug}` : url
|
|
}
|
|
|
|
export const plugins: Plugin[] = [
|
|
redirectsPlugin({
|
|
collections: ['pages', 'posts'],
|
|
overrides: {
|
|
// @ts-expect-error - This is a valid override, mapped fields don't resolve to the same type
|
|
fields: ({ defaultFields }) => {
|
|
return defaultFields.map((field) => {
|
|
if ('name' in field && field.name === 'from') {
|
|
return {
|
|
...field,
|
|
admin: {
|
|
description: 'You will need to rebuild the website when changing this field.',
|
|
},
|
|
}
|
|
}
|
|
return field
|
|
})
|
|
},
|
|
hooks: {
|
|
afterChange: [revalidateRedirects],
|
|
},
|
|
},
|
|
}),
|
|
nestedDocsPlugin({
|
|
collections: ['categories'],
|
|
generateURL: (docs) => docs.reduce((url, doc) => `${url}/${doc.slug}`, ''),
|
|
}),
|
|
seoPlugin({
|
|
generateTitle,
|
|
generateURL,
|
|
}),
|
|
formBuilderPlugin({
|
|
fields: {
|
|
payment: false,
|
|
},
|
|
formOverrides: {
|
|
fields: ({ defaultFields }) => {
|
|
return defaultFields.map((field) => {
|
|
if ('name' in field && field.name === 'confirmationMessage') {
|
|
return {
|
|
...field,
|
|
editor: lexicalEditor({
|
|
features: ({ rootFeatures }) => {
|
|
return [
|
|
...rootFeatures,
|
|
FixedToolbarFeature(),
|
|
HeadingFeature({ enabledHeadingSizes: ['h1', 'h2', 'h3', 'h4'] }),
|
|
]
|
|
},
|
|
}),
|
|
}
|
|
}
|
|
return field
|
|
})
|
|
},
|
|
},
|
|
}),
|
|
searchPlugin({
|
|
collections: ['posts'],
|
|
beforeSync: beforeSyncWithSearch,
|
|
searchOverrides: {
|
|
fields: ({ defaultFields }) => {
|
|
return [...defaultFields, ...searchFields]
|
|
},
|
|
},
|
|
}),
|
|
payloadCloudPlugin(),
|
|
multiTenantPlugin<Config>({
|
|
debug: true,
|
|
enabled: true,
|
|
collections: {
|
|
pages: {},
|
|
exercises: {},
|
|
exerciseTypes: {},
|
|
muscleGroups: {},
|
|
equipments: {},
|
|
workouts: {},
|
|
workoutTypes: {},
|
|
ingredients: {},
|
|
mealItems: {},
|
|
meals: {},
|
|
habbitCategories: {},
|
|
habbits: {},
|
|
habbitEntries: {},
|
|
schedules: {},
|
|
},
|
|
tenantsArrayField: {
|
|
includeDefaultField: false,
|
|
},
|
|
userHasAccessToAllTenants: (user: User) => isSuperAdmin(user),
|
|
tenantField: {
|
|
access: {
|
|
read: () => true,
|
|
update: ({ req }) => {
|
|
if (isSuperAdmin(req.user)) {
|
|
return true
|
|
}
|
|
return getUserTenantIDs(req.user).length > 0
|
|
},
|
|
},
|
|
},
|
|
}),
|
|
]
|
|
|