Skip to content

Commit

Permalink
add reusable modules to the cms schema
Browse files Browse the repository at this point in the history
  • Loading branch information
iamkevingreen committed Sep 24, 2023
1 parent 4d43c13 commit 6c55fa3
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 0 deletions.
6 changes: 6 additions & 0 deletions cms/desk/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const hiddenDocTypes = (listItem) => {
'media.tag',
'page',
'product',
'reusableModule',
'productVariant',
'header',
'colorType',
Expand Down Expand Up @@ -70,6 +71,11 @@ export const structure = (S, context) => {
.title('Footers')
.schemaType('footer')
.child(S.documentTypeList('footer').title('Footers')),

S.listItem()
.title('Resuable Modules')
.schemaType('reusableModule')
.child(S.documentTypeList('reusableModule').title('Resuable Modules')),
S.listItem()
.title('Carts')
.schemaType('cart')
Expand Down
6 changes: 6 additions & 0 deletions cms/schemas/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ import moduleFAQs from './objects/module/faqModule'
import moduleValueProps from './objects/module/valueProps'
import moduleBigBenefits from './objects/module/bigBenefits'
import moduleProductGrid from './objects/module/productGrid'
import moduleReusableModule from './objects/module/reusableModule'

import shopifyCollection from './objects/shopifyCollection'
import shopifyCollectionRule from './objects/shopifyCollectionRule'
Expand All @@ -113,6 +114,7 @@ const objects = [
moduleValueProps,
moduleBigBenefits,
moduleProductGrid,
moduleReusableModule,

moduleProduct,
moduleProducts,
Expand All @@ -136,14 +138,18 @@ const objects = [
// site modules
import productComponentList from './modules/productComponentList'
import pageComponentList from './modules/pageComponentList'
import reusableComponentList from './modules/reusableComponentList'
import header from './modules/header'
import footer from './modules/footer'
import reusableModule from './modules/reusableModule'
import cart from './modules/cart'

const modules = [
productComponentList,
pageComponentList,
reusableComponentList,
header,
reusableModule,
footer,
cart
]
Expand Down
1 change: 1 addition & 0 deletions cms/schemas/modules/pageComponentList.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default {
{ type: 'module.valueProps' },
{ type: 'module.faqs' },
{ type: 'module.image' },
{ type: 'module.reusableModule' },
{ type: 'module.productGrid' },
{ type: 'module.standardText' },
],
Expand Down
19 changes: 19 additions & 0 deletions cms/schemas/modules/reusableComponentList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import Emoji from 'a11y-react-emoji';

const Icon = () => <Emoji style={{fontSize: '1.5em'}} symbol="🚧" />;

export default {
name: 'reusableComponentList',
title: 'Components',
icon: Icon,
type: 'array',
of: [
{ type: 'module.hero' },
{ type: 'module.valueProps' },
{ type: 'module.faqs' },
{ type: 'module.image' },
{ type: 'module.productGrid' },
{ type: 'module.standardText' },
],
};
36 changes: 36 additions & 0 deletions cms/schemas/modules/reusableModule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import React from 'react';
import Emoji from 'a11y-react-emoji';

import { defineField } from 'sanity'

const Icon = () => <Emoji style={{fontSize: '1.5em'}} symbol="♻️" />;

export default {
name: 'reusableModule',
title: 'Reusable Module',
icon: Icon,
type: 'document',
fields: [
{
name: 'title',
title: 'Title',
type: 'string',
description: 'Only used internally in the CMS',
validation: Rule => Rule.required(),
},
defineField({
name: 'reusableComponentList',
title: 'Modules',
type: 'reusableComponentList',
}),
],
preview: {
select: {
title: 'title',
},
prepare: selection => ({
...selection,
media: <Icon />,
}),
},
};
28 changes: 28 additions & 0 deletions cms/schemas/objects/module/reusableModule.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react'
import {defineField, defineType} from 'sanity'
import {PackageIcon} from '@sanity/icons'


export default defineType({
name: 'module.reusableModule',
title: 'Reusable Module',
type: 'object',
icon: PackageIcon,
fields: [

defineField({
name: 'module',
title: 'Reusable Module',
type: 'reference',
to: { type: 'reusableModule'},
}),
],
preview: {
select: {},
prepare(selection) {
return {
title: 'Reusable Module',
}
},
},
})

0 comments on commit 6c55fa3

Please sign in to comment.