mirror of
https://github.com/vercel/commerce.git
synced 2025-07-23 04:36:49 +00:00
Next and next sanity fetching and preview updates
This commit is contained in:
@@ -19,7 +19,6 @@ export const PAGE_REFERENCES = [
|
||||
{type: 'home'},
|
||||
{type: 'page'},
|
||||
{type: 'product'},
|
||||
{type: 'productVariant'},
|
||||
]
|
||||
|
||||
// Objects to include in page building arrays.
|
||||
@@ -36,11 +35,6 @@ export const COMPONENT_REFERENCES = [
|
||||
// https://www.sanity.io/help/studio-client-specify-api-version
|
||||
export const SANITY_API_VERSION = '2022-10-25'
|
||||
|
||||
// Your Shopify store ID.
|
||||
// This is your unique store URL (e.g. 'my-store-name.myshopify.com').
|
||||
// Set this to enable helper links in document status banners and shortcut links on products and collections.
|
||||
export const STORM_STORE_ID = ''
|
||||
|
||||
// Project preview URLs
|
||||
export const localStorefrontUrl = 'http://localhost:3000';
|
||||
export const localStorefrontPreviewUrl = 'http://localhost:3000/api/preview';
|
||||
|
@@ -59,16 +59,16 @@ export const structure: StructureResolver = (S, context) =>
|
||||
home(S, context),
|
||||
pages(S, context),
|
||||
S.divider(),
|
||||
products(S, context),
|
||||
categories(S, context),
|
||||
products(S, context),
|
||||
S.divider(),
|
||||
blurbs(S, context),
|
||||
usps(S, context),
|
||||
sections(S, context),
|
||||
usps(S, context),
|
||||
S.divider(),
|
||||
settings(S, context),
|
||||
search(S, context),
|
||||
navigation(S, context),
|
||||
search(S, context),
|
||||
settings(S, context),
|
||||
S.divider(),
|
||||
...S.documentTypeListItems().filter(hiddenDocTypes),
|
||||
S.divider(),
|
||||
|
@@ -7,9 +7,9 @@ import { draftMode } from 'next/headers'
|
||||
|
||||
import { revalidateSecret } from './sanity.api'
|
||||
|
||||
import { categoryQuery, homePageQuery, mainMenuQuery, pageQuery, productQuery, searchPageQuery } from './queries'
|
||||
import { categoryQuery, footerMenusQuery, homePageQuery, mainMenuQuery, pageQuery, productQuery, searchPageQuery } from './queries'
|
||||
|
||||
import { CategoryPayload, HomePagePayload, MainMenuPayload, PagePayload, ProductPayload, SearchPayload } from './sanity.types'
|
||||
import { CategoryPayload, FooterMenusPayload, HomePagePayload, MainMenuPayload, PagePayload, ProductPayload, SearchPayload } from './sanity.types'
|
||||
|
||||
export const token = process.env.SANITY_API_READ_TOKEN
|
||||
|
||||
@@ -98,4 +98,12 @@ export function getMainMenu(locale: string) {
|
||||
params: { locale },
|
||||
tags: ['menu'],
|
||||
})
|
||||
}
|
||||
|
||||
export function getFooterMenus(locale: string) {
|
||||
return sanityFetch<FooterMenusPayload | null>({
|
||||
query: footerMenusQuery,
|
||||
params: { locale },
|
||||
tags: ['menu'],
|
||||
})
|
||||
}
|
@@ -70,4 +70,10 @@ export interface MainMenuPayload {
|
||||
title?: string
|
||||
_type?: string
|
||||
items?: MenuItem[]
|
||||
}
|
||||
|
||||
export interface FooterMenusPayload {
|
||||
title?: string
|
||||
_type?: string
|
||||
menu?: MenuItem[]
|
||||
}
|
@@ -1,7 +1,7 @@
|
||||
import {CommentIcon} from '@sanity/icons'
|
||||
import {defineField} from 'sanity'
|
||||
import {languages} from '../../languages'
|
||||
import {validateImage} from '../../utils/validation'
|
||||
import { CommentIcon } from '@sanity/icons';
|
||||
import { defineField } from 'sanity';
|
||||
import { languages } from '../../languages';
|
||||
import { validateImage } from '../../utils/validation';
|
||||
|
||||
export default defineField({
|
||||
name: 'blurb',
|
||||
@@ -13,7 +13,7 @@ export default defineField({
|
||||
name: 'language',
|
||||
type: 'string',
|
||||
readOnly: true,
|
||||
description: 'Language of this document.',
|
||||
description: 'Language of this document.'
|
||||
// hidden: true,
|
||||
}),
|
||||
// Title
|
||||
@@ -22,14 +22,14 @@ export default defineField({
|
||||
title: 'Title',
|
||||
type: 'string',
|
||||
description: 'What do you want to convey?',
|
||||
validation: (Rule) => Rule.required(),
|
||||
validation: (Rule) => Rule.required()
|
||||
}),
|
||||
// Image
|
||||
defineField({
|
||||
name: 'image',
|
||||
title: 'Image',
|
||||
type: 'mainImage',
|
||||
validation: (Rule) => validateImage(Rule, true),
|
||||
validation: (Rule) => validateImage(Rule, true)
|
||||
}),
|
||||
// Text
|
||||
defineField({
|
||||
@@ -37,7 +37,7 @@ export default defineField({
|
||||
title: 'Text',
|
||||
type: 'text',
|
||||
description: 'Small text displayed below title.',
|
||||
rows: 5,
|
||||
rows: 5
|
||||
}),
|
||||
// Link
|
||||
{
|
||||
@@ -54,69 +54,69 @@ export default defineField({
|
||||
validation: (Rule) => Rule.required(),
|
||||
options: {
|
||||
list: ['internal', 'external'],
|
||||
layout: 'radio',
|
||||
},
|
||||
layout: 'radio'
|
||||
}
|
||||
},
|
||||
{
|
||||
name: 'internalLink',
|
||||
type: 'linkInternal',
|
||||
title: 'Internal link',
|
||||
hidden: ({parent}) => parent?.linkType !== 'internal',
|
||||
hidden: ({ parent }) => parent?.linkType !== 'internal',
|
||||
options: {
|
||||
collapsible: false,
|
||||
collapsible: false
|
||||
},
|
||||
validation: (Rule) =>
|
||||
Rule.custom((value: any, context: any) => {
|
||||
if (context.parent.linkType == 'internal') {
|
||||
const currentLink = value && value.reference
|
||||
const currentLink = value && value.reference;
|
||||
if (!currentLink) {
|
||||
return 'Reference is required'
|
||||
return 'Reference is required';
|
||||
}
|
||||
}
|
||||
return true
|
||||
}),
|
||||
return true;
|
||||
})
|
||||
},
|
||||
{
|
||||
name: 'externalLink',
|
||||
type: 'linkExternal',
|
||||
title: 'External link',
|
||||
hidden: ({parent}) => parent?.linkType !== 'external',
|
||||
hidden: ({ parent }) => parent?.linkType !== 'external',
|
||||
options: {
|
||||
collapsible: false,
|
||||
collapsible: false
|
||||
},
|
||||
validation: (Rule) =>
|
||||
Rule.custom((value: any, context: any) => {
|
||||
if (context.parent.linkType == 'external') {
|
||||
const currentTitle = value?.title
|
||||
const currentUrl = value?.url
|
||||
const currentTitle = value?.title;
|
||||
const currentUrl = value?.url;
|
||||
if (!currentTitle) {
|
||||
return 'Title is required'
|
||||
return 'Title is required';
|
||||
} else if (!currentUrl) {
|
||||
return 'URL is required'
|
||||
return 'URL is required';
|
||||
}
|
||||
}
|
||||
return true
|
||||
}),
|
||||
},
|
||||
],
|
||||
},
|
||||
return true;
|
||||
})
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
preview: {
|
||||
select: {
|
||||
title: 'title',
|
||||
image: 'image',
|
||||
language: 'language',
|
||||
language: 'language'
|
||||
},
|
||||
prepare(selection) {
|
||||
const {image, title, language} = selection
|
||||
const { image, title, language } = selection;
|
||||
|
||||
const currentLang = languages.find((lang) => lang.id === language)
|
||||
const currentLang = languages.find((lang) => lang.id === language);
|
||||
|
||||
return {
|
||||
media: image,
|
||||
title,
|
||||
subtitle: `${currentLang ? currentLang.title : ''}`,
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
||||
subtitle: `${currentLang ? currentLang.title : ''}`
|
||||
};
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@@ -1,30 +0,0 @@
|
||||
import {CopyIcon} from '@sanity/icons'
|
||||
import {defineField, defineType} from 'sanity'
|
||||
|
||||
export default defineType({
|
||||
name: 'productVariant',
|
||||
title: 'Product variant',
|
||||
type: 'document',
|
||||
icon: CopyIcon,
|
||||
fields: [
|
||||
// Title
|
||||
defineField({
|
||||
title: 'Title',
|
||||
name: 'title',
|
||||
type: 'string',
|
||||
description: 'Product variant title/name.'
|
||||
}),
|
||||
],
|
||||
preview: {
|
||||
select: {
|
||||
title: 'title',
|
||||
},
|
||||
prepare(selection) {
|
||||
const {title} = selection
|
||||
|
||||
return {
|
||||
title,
|
||||
}
|
||||
},
|
||||
},
|
||||
})
|
@@ -17,7 +17,6 @@ import category from './documents/category'
|
||||
import footerMenu from './documents/footerMenu'
|
||||
import page from './documents/page'
|
||||
import product from './documents/product'
|
||||
import productVariant from './documents/productVariant'
|
||||
import section from './documents/section'
|
||||
import usp from './documents/usp'
|
||||
|
||||
@@ -25,7 +24,6 @@ const documents = [
|
||||
category,
|
||||
page,
|
||||
product,
|
||||
productVariant,
|
||||
blurb,
|
||||
section,
|
||||
usp,
|
||||
|
@@ -2,7 +2,7 @@
|
||||
import { isDev, SanityDocument } from 'sanity'
|
||||
import { localStorefrontPreviewUrl, publicStorefrontPreviewUrl } from '../constants'
|
||||
|
||||
const SANITY_STUDIO_API_READ_TOKEN = "skYG2HXNga8uxSL7rFIreJEnP0SdVjCZ2nzB8rUHD4wRWxXPGceXTuR5vCVBP99mWZ9ULhghmpUyX7EtzDmJusSk6Gwvdr3nLAsdWI9ZktIWvSWUNpHbu0Xfrrt0UUaktrLglk7ToABvjXlaPHLpOIR3dnjl4MGByutPmyra0b5t20kgDrmF"
|
||||
const SANITY_STUDIO_API_READ_TOKEN = "preview.skYG2HXNga8uxSL7rFIreJEnP0SdVjCZ2nzB8rUHD4wRWxXPGceXTuR5vCVBP99mWZ9ULhghmpUyX7EtzDmJusSk6Gwvdr3nLAsdWI9ZktIWvSWUNpHbu0Xfrrt0UUaktrLglk7ToABvjXlaPHLpOIR3dnjl4MGByutPmyra0b5t20kgDrmF"
|
||||
|
||||
// Customise this function to show the correct URL based on the current document
|
||||
export default async function getPreviewUrl(doc: SanityDocument) {
|
||||
|
Reference in New Issue
Block a user