2026-04-23 01:08:18 +08:00
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' ,
2026-04-23 10:15:15 +08:00
label : { en : 'Status' , zh : '状态' },
2026-04-23 01:08:18 +08:00
type : 'select' as const ,
localized : true ,
defaultValue : 'draft' ,
2026-04-23 10:15:15 +08:00
options : [
{ label : 'Draft / 草稿' , value : 'draft' },
{ label : 'Review / 待审核' , value : 'review' },
{ label : 'Published / 已发布' , value : 'published' },
{ label : 'Archived / 已归档' , value : 'archived' },
],
2026-04-23 01:08:18 +08:00
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' ,
2026-04-23 10:15:15 +08:00
label : { en : 'Doc Locale' , zh : '文档语言' },
2026-04-23 01:08:18 +08:00
type : 'select' ,
required : true ,
defaultValue : getDocLocaleDefault ,
options : [
2026-04-23 10:15:15 +08:00
{ label : 'English / 英文' , value : 'en' },
{ label : '简体中文' , value : 'zh' },
2026-04-23 01:08:18 +08:00
],
admin : {
position : 'sidebar' ,
description : 'Independent document language for this review entry.' ,
},
},
2026-04-23 10:15:15 +08:00
{ name : 'title' , label : { en : 'Title' , zh : '标题' }, type : 'text' , localized : true , required : true },
{ name : 'product' , label : { en : 'Product' , zh : '关联产品' }, type : 'relationship' , relationTo : 'products' , required : true },
{ name : 'sourceName' , label : { en : 'Source Name' , zh : '来源名称' }, type : 'text' , localized : true },
{ name : 'reviewUrl' , label : { en : 'Review URL' , zh : '评测链接' }, type : 'text' , required : true , localized : true },
{ name : 'thumbnail' , label : { en : 'Thumbnail' , zh : '缩略图' }, type : 'upload' , relationTo : 'media' , localized : true },
{ name : 'excerpt' , label : { en : 'Excerpt' , zh : '摘要' }, type : 'textarea' , localized : true },
{ name : 'quote' , label : { en : 'Quote' , zh : '引用语' }, type : 'textarea' , localized : true },
{ name : 'publishedAt' , label : { en : 'Published At' , zh : '发布时间' }, type : 'date' , localized : true },
{ name : 'sortOrder' , label : { en : 'Sort Order' , zh : '排序' }, type : 'number' , defaultValue : 0 , localized : true },
{ name : 'legacySourceUrl' , label : { en : 'Legacy Source URL' , zh : '旧站来源链接' }, type : 'text' , localized : true },
2026-04-23 01:08:18 +08:00
statusField ,
],
}