67 lines
2.5 KiB
TypeScript
67 lines
2.5 KiB
TypeScript
|
|
import type { CollectionConfig } from 'payload'
|
||
|
|
import { independentDocListFilter } from '@/payload/admin/localized-list-filter'
|
||
|
|
import { getDocLocaleDefault, resolveDocLocale, syncDocLocaleWithRequestLocale } from '@/payload/doc-locale-hook'
|
||
|
|
|
||
|
|
const statusField = {
|
||
|
|
name: 'status',
|
||
|
|
type: 'select' as const,
|
||
|
|
localized: true,
|
||
|
|
defaultValue: 'draft',
|
||
|
|
options: ['draft', 'review', 'published', 'archived'],
|
||
|
|
required: true,
|
||
|
|
}
|
||
|
|
|
||
|
|
export const ProductReviews: CollectionConfig = {
|
||
|
|
slug: 'productReviews',
|
||
|
|
hooks: {
|
||
|
|
beforeChange: [syncDocLocaleWithRequestLocale],
|
||
|
|
beforeValidate: [syncDocLocaleWithRequestLocale],
|
||
|
|
},
|
||
|
|
admin: {
|
||
|
|
baseFilter: independentDocListFilter('title'),
|
||
|
|
defaultColumns: ['title', 'docLocale', 'product', 'sourceName', 'sortOrder', 'status', 'updatedAt'],
|
||
|
|
description:
|
||
|
|
'Editorial reviews, quotes, thumbnails, and outbound links associated with products. Homepage review quotes are also sourced from this collection, and English/Chinese entries are maintained as separate documents.',
|
||
|
|
group: { en: 'Catalog', zh: '产品' },
|
||
|
|
useAsTitle: 'title',
|
||
|
|
},
|
||
|
|
labels: {
|
||
|
|
plural: { en: 'Product Reviews', zh: '外部评测' },
|
||
|
|
singular: { en: 'Product Review', zh: '外部评测' },
|
||
|
|
},
|
||
|
|
access: {
|
||
|
|
read: ({ req }) => {
|
||
|
|
const locale = resolveDocLocale(req)
|
||
|
|
if (!locale) return true
|
||
|
|
return { docLocale: { equals: locale } }
|
||
|
|
},
|
||
|
|
},
|
||
|
|
fields: [
|
||
|
|
{
|
||
|
|
name: 'docLocale',
|
||
|
|
type: 'select',
|
||
|
|
required: true,
|
||
|
|
defaultValue: getDocLocaleDefault,
|
||
|
|
options: [
|
||
|
|
{ label: 'English Doc', value: 'en' },
|
||
|
|
{ label: '中文 Doc', value: 'zh' },
|
||
|
|
],
|
||
|
|
admin: {
|
||
|
|
position: 'sidebar',
|
||
|
|
description: 'Independent document language for this review entry.',
|
||
|
|
},
|
||
|
|
},
|
||
|
|
{ name: 'title', type: 'text', localized: true, required: true },
|
||
|
|
{ name: 'product', type: 'relationship', relationTo: 'products', required: true },
|
||
|
|
{ name: 'sourceName', type: 'text', localized: true },
|
||
|
|
{ name: 'reviewUrl', type: 'text', required: true, localized: true },
|
||
|
|
{ name: 'thumbnail', type: 'upload', relationTo: 'media', localized: true },
|
||
|
|
{ name: 'excerpt', type: 'textarea', localized: true },
|
||
|
|
{ name: 'quote', type: 'textarea', localized: true },
|
||
|
|
{ name: 'publishedAt', type: 'date', localized: true },
|
||
|
|
{ name: 'sortOrder', type: 'number', defaultValue: 0, localized: true },
|
||
|
|
{ name: 'legacySourceUrl', type: 'text', localized: true },
|
||
|
|
statusField,
|
||
|
|
],
|
||
|
|
}
|