-
-
Save ndimatteo/f0b9f0620caf775d4d5f6750acfc343a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react' | |
import defaultResolve, { | |
PublishAction, | |
DiscardChangesAction | |
} from 'part:@sanity/base/document-actions' | |
import { Eye } from 'phosphor-react' | |
const remoteURL = 'https://xxx.vercel.app' | |
const localURL = 'http://localhost:3000' | |
const frontendURL = | |
window.location.hostname === 'localhost' ? localURL : remoteURL | |
const singletons = [ | |
'generalSettings', | |
'cookieSettings', | |
'headerSettings', | |
'footerSettings', | |
'seoSettings' | |
] | |
const previews = ['page', 'program'] | |
const PreviewAction = props => { | |
const slug = props.draft | |
? props.draft.slug?.current | |
: props.published?.slug?.current | |
return { | |
label: 'Open Preview', | |
icon: () => <Eye weight="light" data-sanity-icon="eye" />, | |
onHandle: () => { | |
window.open( | |
`${frontendURL}/api/preview?token=YYY&type=${ | |
props.type | |
}&slug=${slug || ''}` | |
) | |
} | |
} | |
} | |
export default function resolveDocumentActions(props) { | |
const isSingle = singletons.indexOf(props.type) > -1 | |
const canPreview = previews.indexOf(props.type) > -1 | |
if (isSingle) { | |
return [ | |
PublishAction, | |
DiscardChangesAction, | |
...(canPreview ? [PreviewAction] : []) | |
] | |
} | |
return [...defaultResolve(props), ...(canPreview ? [PreviewAction] : [])] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment