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

117 lines
2.7 KiB
TypeScript

// import { BookIcon } from '@sanity/icons'
import { format, parseISO } from 'date-fns'
import { TiCalendarOutline } from 'react-icons/ti'
import { defineField, defineType } from 'sanity'
import authorType from './author'
export default defineType({
name: 'career',
title: 'Career Main Page',
icon: TiCalendarOutline,
type: 'document',
fields: [
defineField({
name: 'title',
title: 'Title',
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),
},
//validation: (rule) => rule.required(),
}),
defineField({
name: 'content',
title: 'Text / Job',
type: 'array',
of: [{ type: 'block' }],
}),
defineField({
name: 'jobplatformurl',
title: 'Job detail page (eksternal)',
type: 'url',
description: 'Paste URL loker di platform (Ex: jobstreet) di sini',
validation: (rule) => rule.required(),
}),
defineField({
title: 'Job type',
name: 'jobtype',
type: 'string',
options: {
list: [
{ title: 'Fulltime', value: 'Fulltime' },
{ title: 'Freelance', value: 'Freelance' },
{ title: 'Contract Base', value: 'Contract Base' },
],
layout: 'radio',
direction: 'horizontal',
},
}),
// defineField({
// name: 'excerpt',
// title: 'Excerpt',
// type: 'text',
// }),
defineField({
name: 'coverImage',
title: 'Thumbnail',
type: 'image',
options: {
hotspot: true,
},
fields: [
{
type: 'string',
title: 'Alternative text',
name: 'alt',
},
],
}),
defineField({
name: 'posterImage',
title: 'Poster',
type: 'image',
options: {
hotspot: true,
},
}),
defineField({
name: 'date',
title: 'Date',
type: 'datetime',
initialValue: () => new Date().toISOString(),
}),
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(' ') }
},
},
})