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 14, 2024
1 parent d732ce2 commit 0fc83c8
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 4 deletions.
2 changes: 2 additions & 0 deletions apps/sanity/schema/Components.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import FeatureAccordionSection from "./components/FeatureAccordionSection";
import CtaSectionWithShapedImage from "./components/CtaSectionWithShapedImage";
import ServicesOverview from "./components/ServicesOverview";
import MetricsSection from "./components/MetricsSection";
import Faq from "./components/Faq";

export default defineType({
name: 'components',
Expand All @@ -19,6 +20,7 @@ export default defineType({
CtaSectionWithShapedImage,
ServicesOverview,
MetricsSection,
Faq,
],
options: {
insertMenu: {
Expand Down
63 changes: 63 additions & 0 deletions apps/sanity/schema/components/Faq.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { defineField } from 'sanity';
import { toPlainText } from '../../utils/to-plain-text';

const name = 'Faq';
const title = 'Sekcja 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: 'items',
type: 'array',
title: 'Items',
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 {}
}
}
}),
],
validation: Rule => Rule.required().unique(),
}),
defineField({
name: 'img',
type: 'image',
title: 'Image',
validation: Rule => Rule.required(),
}),
],
preview: {
select: {
heading: 'heading',
media: 'img',
},
prepare: ({ heading, media }) => ({
title: title,
subtitle: toPlainText(heading),
media: media || icon,
}),
},
});
2 changes: 1 addition & 1 deletion apps/sanity/schema/components/ServicesOverview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineField } from 'sanity';
import { toPlainText } from '../../utils/to-plain-text';

const name = 'ServicesOverview';
const title = 'Przegląd usług';
const title = 'Sekcja z przeglądem usług';
const icon = () => '🛠️';

export default defineField({
Expand Down
2 changes: 1 addition & 1 deletion apps/sanity/schema/components/SimpleCtaSection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { defineField } from 'sanity';
import { toPlainText } from '../../utils/to-plain-text';

const name = 'SimpleCtaSection';
const title = 'Prosta sekcja z wezwaniem do działania';
const title = 'Prosta sekcja z CTA';
const icon = () => '📞';

export default defineField({
Expand Down
Binary file added apps/sanity/static/Faq.webp
Binary file not shown.
4 changes: 2 additions & 2 deletions apps/sanity/structure/schema-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ const components = [
// UI Components
import cta from '../schema/ui/cta';
import seo from '../schema/ui/seo';
import PortableText from '../schema/ui/PortableText';
import Heading from '../schema/ui/PortableText/Heading';
import PortableText from '../schema/ui/portable-text';
import Heading from '../schema/ui/portable-text/Heading';

const ui = [
cta,
Expand Down

0 comments on commit 0fc83c8

Please sign in to comment.