Last active
April 12, 2021 16:17
-
-
Save runeb/354d42cb5751c3d1638400be7556f2c2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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, {useState} from "react" | |
import { PublishAction } from 'part:@sanity/base/document-actions'; | |
const ConfirmDialog = ({onClick, onCancel}) => { | |
return ( | |
<> | |
<button onClick={onClick}>Yes</button> | |
<button onClick={onCancel}>Cancel</button> | |
</> | |
) | |
} | |
export default function CornfirmPublish(props) { | |
const [showDialog, setShowDialog] = useState(false) | |
const publishAction = PublishAction(props) | |
const onConfirm = () => { | |
publishAction.onHandle() | |
setShowDialog(false) | |
} | |
return { | |
// If built-in publish is enabled, we are enabled | |
disabled: publishAction.disabled, | |
dialog: showDialog && { | |
type: 'popover', | |
content: <ConfirmDialog onClick={onConfirm} onCancel={() => setShowDialog(false)}/>, | |
}, | |
label: "Confirm publish", | |
onHandle: () => setShowDialog(true), | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment