mirror of
https://github.com/vercel/commerce.git
synced 2025-07-23 04:36:49 +00:00
Fixed preview support for sanity/next
This commit is contained in:
@@ -33,10 +33,4 @@ export const COMPONENT_REFERENCES = [
|
||||
|
||||
// API version to use when using the Sanity client within the studio
|
||||
// https://www.sanity.io/help/studio-client-specify-api-version
|
||||
export const SANITY_API_VERSION = '2022-10-25'
|
||||
|
||||
// Project preview URLs
|
||||
export const localStorefrontUrl = 'http://localhost:3000';
|
||||
export const localStorefrontPreviewUrl = 'http://localhost:3000/api/preview';
|
||||
export const publicStorefrontUrl = 'https://km-storefront.vercel.app';
|
||||
export const publicStorefrontPreviewUrl = 'https://km-storefront.vercel.app/api/preview';
|
||||
export const SANITY_API_VERSION = '2022-10-25'
|
@@ -1,9 +1,8 @@
|
||||
import {ListItemBuilder} from 'sanity/desk'
|
||||
import defineStructure from '../utils/define-structure'
|
||||
import { iframeOptions } from '@/sanity.config'
|
||||
import { EyeOpenIcon, MasterDetailIcon } from '@sanity/icons'
|
||||
import Iframe from 'sanity-plugin-iframe-pane'
|
||||
import {SanityDocument} from 'sanity'
|
||||
import {EyeOpenIcon, MasterDetailIcon} from '@sanity/icons'
|
||||
import getPreviewUrl from '../utils/get-preview-url'
|
||||
import { ListItemBuilder } from 'sanity/desk'
|
||||
import defineStructure from '../utils/define-structure'
|
||||
|
||||
export default defineStructure<ListItemBuilder>((S) =>
|
||||
S.listItem()
|
||||
@@ -16,16 +15,8 @@ export default defineStructure<ListItemBuilder>((S) =>
|
||||
.schemaType("category")
|
||||
.id(id)
|
||||
.views([
|
||||
S.view
|
||||
.form()
|
||||
.icon(MasterDetailIcon),
|
||||
S.view
|
||||
.component(Iframe)
|
||||
.icon(EyeOpenIcon)
|
||||
.options({
|
||||
url: (doc: SanityDocument) => getPreviewUrl(doc),
|
||||
})
|
||||
.title('Preview')
|
||||
S.view.form().icon(MasterDetailIcon),
|
||||
S.view.component(Iframe).icon(EyeOpenIcon).options(iframeOptions).title('Preview')
|
||||
])
|
||||
)
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
import { iframeOptions } from '@/sanity.config'
|
||||
import { EyeOpenIcon, MasterDetailIcon } from '@sanity/icons'
|
||||
import { SanityDocument } from 'sanity'
|
||||
import Iframe from 'sanity-plugin-iframe-pane'
|
||||
import { ListItemBuilder } from 'sanity/desk'
|
||||
import defineStructure from '../utils/define-structure'
|
||||
import getPreviewUrl from '../utils/get-preview-url'
|
||||
|
||||
export default defineStructure<ListItemBuilder>((S) =>
|
||||
S.listItem()
|
||||
@@ -18,16 +17,8 @@ export default defineStructure<ListItemBuilder>((S) =>
|
||||
.schemaType("home")
|
||||
.id(id)
|
||||
.views([
|
||||
S.view
|
||||
.form()
|
||||
.icon(MasterDetailIcon),
|
||||
S.view
|
||||
.component(Iframe)
|
||||
.icon(EyeOpenIcon)
|
||||
.options({
|
||||
url: (doc: SanityDocument) => getPreviewUrl(doc),
|
||||
})
|
||||
.title('Preview')
|
||||
S.view.form().icon(MasterDetailIcon),
|
||||
S.view.component(Iframe).icon(EyeOpenIcon).options(iframeOptions).title('Preview')
|
||||
])
|
||||
)
|
||||
)
|
||||
|
@@ -1,9 +1,8 @@
|
||||
import { iframeOptions } from '@/sanity.config'
|
||||
import { DocumentsIcon, EyeOpenIcon, MasterDetailIcon } from '@sanity/icons'
|
||||
import { SanityDocument } from 'sanity'
|
||||
import Iframe from 'sanity-plugin-iframe-pane'
|
||||
import { ListItemBuilder } from 'sanity/desk'
|
||||
import defineStructure from '../utils/define-structure'
|
||||
import getPreviewUrl from '../utils/get-preview-url'
|
||||
|
||||
export default defineStructure<ListItemBuilder>((S) =>
|
||||
S.listItem()
|
||||
@@ -17,16 +16,8 @@ export default defineStructure<ListItemBuilder>((S) =>
|
||||
.schemaType("page")
|
||||
.id(id)
|
||||
.views([
|
||||
S.view
|
||||
.form()
|
||||
.icon(MasterDetailIcon),
|
||||
S.view
|
||||
.component(Iframe)
|
||||
.icon(EyeOpenIcon)
|
||||
.options({
|
||||
url: (doc: SanityDocument) => getPreviewUrl(doc),
|
||||
})
|
||||
.title('Preview')
|
||||
S.view.form().icon(MasterDetailIcon),
|
||||
S.view.component(Iframe).icon(EyeOpenIcon).options(iframeOptions).title('Preview')
|
||||
])
|
||||
)
|
||||
|
||||
|
@@ -1,9 +1,8 @@
|
||||
import {ListItemBuilder} from 'sanity/desk'
|
||||
import defineStructure from '../utils/define-structure'
|
||||
import { iframeOptions } from '@/sanity.config'
|
||||
import { EyeOpenIcon, MasterDetailIcon } from '@sanity/icons'
|
||||
import Iframe from 'sanity-plugin-iframe-pane'
|
||||
import {SanityDocument} from 'sanity'
|
||||
import {EyeOpenIcon, MasterDetailIcon} from '@sanity/icons'
|
||||
import getPreviewUrl from '../utils/get-preview-url'
|
||||
import { ListItemBuilder } from 'sanity/desk'
|
||||
import defineStructure from '../utils/define-structure'
|
||||
|
||||
export default defineStructure<ListItemBuilder>((S) =>
|
||||
S.listItem()
|
||||
@@ -16,58 +15,10 @@ export default defineStructure<ListItemBuilder>((S) =>
|
||||
.schemaType("product")
|
||||
.id(id)
|
||||
.views([
|
||||
S.view
|
||||
.form()
|
||||
.icon(MasterDetailIcon),
|
||||
S.view
|
||||
.component(Iframe)
|
||||
.icon(EyeOpenIcon)
|
||||
.options({
|
||||
url: (doc: SanityDocument) => getPreviewUrl(doc),
|
||||
})
|
||||
.title('Preview')
|
||||
S.view.form().icon(MasterDetailIcon),
|
||||
S.view.component(Iframe).icon(EyeOpenIcon).options(iframeOptions).title('Preview')
|
||||
])
|
||||
)
|
||||
|
||||
)
|
||||
)
|
||||
|
||||
// @TODO - FIX THIS STRUCTURE.
|
||||
// export default defineStructure<ListItemBuilder>((S) =>
|
||||
// S.listItem()
|
||||
// .title('Products')
|
||||
// .schemaType('product')
|
||||
// .child(
|
||||
// S.documentTypeList('product')
|
||||
// // .defaultLayout('detail')
|
||||
// .child(async (id) =>
|
||||
// S.list()
|
||||
// .title('Product')
|
||||
// .items([
|
||||
// // Details
|
||||
// S.listItem()
|
||||
// .title('Details')
|
||||
// .icon(InfoOutlineIcon)
|
||||
// .child(S.document().schemaType('product').documentId(id)),
|
||||
// // Product variants
|
||||
// S.listItem()
|
||||
// .title('Variants')
|
||||
// .schemaType('productVariant')
|
||||
// .child(
|
||||
// S.documentList()
|
||||
// .title('Variants')
|
||||
// .schemaType('productVariant')
|
||||
// .filter(
|
||||
// `
|
||||
// _type == "productVariant"
|
||||
// && store.productId == $productId
|
||||
// `
|
||||
// )
|
||||
// .params({
|
||||
// productId: Number(id.replace('shopifyProduct-', '')),
|
||||
// })
|
||||
// ),
|
||||
// ])
|
||||
// )
|
||||
// )
|
||||
// )
|
||||
)
|
@@ -1,9 +1,8 @@
|
||||
import { iframeOptions } from '@/sanity.config'
|
||||
import { EyeOpenIcon, MasterDetailIcon } from '@sanity/icons'
|
||||
import { SanityDocument } from 'sanity'
|
||||
import Iframe from 'sanity-plugin-iframe-pane'
|
||||
import { ListItemBuilder } from 'sanity/desk'
|
||||
import defineStructure from '../utils/define-structure'
|
||||
import getPreviewUrl from '../utils/get-preview-url'
|
||||
|
||||
export default defineStructure<ListItemBuilder>((S) =>
|
||||
S.listItem()
|
||||
@@ -18,16 +17,8 @@ export default defineStructure<ListItemBuilder>((S) =>
|
||||
.schemaType("search")
|
||||
.id(id)
|
||||
.views([
|
||||
S.view
|
||||
.form()
|
||||
.icon(MasterDetailIcon),
|
||||
S.view
|
||||
.component(Iframe)
|
||||
.icon(EyeOpenIcon)
|
||||
.options({
|
||||
url: (doc: SanityDocument) => getPreviewUrl(doc),
|
||||
})
|
||||
.title('Preview')
|
||||
S.view.form().icon(MasterDetailIcon),
|
||||
S.view.component(Iframe).icon(EyeOpenIcon).options(iframeOptions).title('Preview')
|
||||
])
|
||||
)
|
||||
)
|
||||
|
@@ -1,25 +0,0 @@
|
||||
// @ts-nocheck
|
||||
import { isDev, SanityDocument } from 'sanity'
|
||||
import { localStorefrontPreviewUrl, publicStorefrontPreviewUrl } from '../constants'
|
||||
|
||||
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) {
|
||||
|
||||
if (isDev) {
|
||||
// Home page have no slugs.
|
||||
if (!doc.slug) {
|
||||
return `${localStorefrontPreviewUrl}?locale=${doc.language}&type=${doc._type}&secret=${SANITY_STUDIO_API_READ_TOKEN}`
|
||||
}
|
||||
|
||||
return `${localStorefrontPreviewUrl}?slug=${doc.slug.current}&locale=${doc.language}&type=${doc._type}&secret=${SANITY_STUDIO_API_READ_TOKEN}`
|
||||
} else {
|
||||
// Home page have no slugs.
|
||||
if (!doc.slug) {
|
||||
return `${publicStorefrontPreviewUrl}?locale=${doc.language}&type=${doc._type}&secret=${SANITY_STUDIO_API_READ_TOKEN}`
|
||||
}
|
||||
|
||||
return `${publicStorefrontPreviewUrl}?slug=${doc.slug.current}&locale=${doc.language}&type=${doc._type}&secret=${SANITY_STUDIO_API_READ_TOKEN}`
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user