Skip to content

Commit

Permalink
add Faq section schema
Browse files Browse the repository at this point in the history
  • Loading branch information
milewskibogumil committed Oct 16, 2024
1 parent 43bd539 commit e593a72
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apps/sanity/schema/Components.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { defineType } from "sanity";
import SimpleCtaSection from "./components/SimpleCtaSection";
import Faq from "./components/Faq";

export default defineType({
name: 'components',
type: 'array',
title: 'Components',
of: [
SimpleCtaSection,
Faq,
],
options: {
insertMenu: {
Expand Down
57 changes: 57 additions & 0 deletions apps/sanity/schema/components/Faq.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { defineField } from 'sanity';
import sectionId from '../ui/sectionId';
import { toPlainText } from '../../utils/to-plain-text';

const name = 'Faq';
const title = 'FAQ';
const icon = () => '❓';

export default defineField({
name,
type: 'object',
title,
icon,
fields: [
defineField({
name: 'heading',
type: 'Heading',
title: 'Heading',
validation: Rule => Rule.required(),
}),
defineField({
name: 'list',
type: 'array',
of: [
defineField({
name: 'item',
type: 'reference',
to: [{ type: 'Faq_Collection' }],
options: {
filter: ({ parent }) => {
const selectedIds = (parent as { _ref?: string }[])?.filter(item => item._ref).map(item => item._ref) || [];
if (selectedIds.length > 0) {
return {
filter: '!(_id in $selectedIds)',
params: { selectedIds }
}
}
return {}
}
}
}),
],
title: 'List',
validation: Rule => Rule.required().unique(),
}),
...sectionId,
],
preview: {
select: {
heading: 'heading',
},
prepare: ({ heading }) => ({
title: title,
subtitle: toPlainText(heading),
}),
},
});
Binary file added apps/sanity/static/Faq.webp
Binary file not shown.

0 comments on commit e593a72

Please sign in to comment.