Gwk-Cultural-Park/schemas/page/page_faq.ts
2024-09-07 08:40:25 +07:00

75 lines
1.7 KiB
TypeScript

import { format, parseISO } from 'date-fns'
import { IoDocumentOutline } from 'react-icons/io5'
import { defineField, defineType } from 'sanity'
import authorType from '../author'
//pagebuilder schema
import faqTopic from './page_faq_topic'
export default defineType({
name: 'pagefaq',
title: 'FAQ',
icon: IoDocumentOutline,
type: 'document',
fields: [
defineField({
name: 'title',
title: 'Title',
description: 'Judul pertanyaan FAQ',
type: 'string',
validation: (rule) => rule.required(),
}),
defineField({
name: 'slug',
title: 'Slug',
type: 'slug',
options: {
source: 'title',
maxLength: 96,
isUnique: (value, context) => context.defaultIsUnique(value, context),
},
}),
defineField({
name: 'content',
title: 'Content',
description: 'Keterangan/penjelasan FAQ',
type: 'text',
}),
defineField({
name: 'date',
title: 'Date',
type: 'datetime',
initialValue: () => new Date().toISOString(),
}),
defineField({
name: 'faqTopic',
title: 'FAQ Topic',
type: 'reference',
to: [{ type: faqTopic.name }],
}),
defineField({
name: 'author',
title: 'Author',
type: 'reference',
to: [{ type: authorType.name }],
}),
],
preview: {
select: {
title: 'title',
author: 'author.name',
date: 'date',
media: 'coverImage',
},
prepare({ title, media, author, date }) {
const subtitles = [
author && `by ${author}`,
date && `on ${format(parseISO(date), 'LLL d, yyyy')}`,
].filter(Boolean)
return { title, media, subtitle: subtitles.join(' ') }
},
},
})