import { h } from 'preact'; import PropTypes from 'prop-types'; import moment from 'moment'; import { Dropdown, ButtonNew as Button } from '@crayons'; import CogIcon from '@images/cog.svg'; /** * Component comprising a trigger button and dropdown with additional post options. * * @param {Object} props * @param {Object} props.passedData The current post options data * @param {Function} props.onSaveDraft Callback for when the post draft is saved * @param {Function} props.onConfigChange Callback for when the config options have changed */ export const Options = ({ passedData: { published = false, publishedAtDate = '', publishedAtTime = '', publishedAtWas = '', timezone = Intl.DateTimeFormat().resolvedOptions().timeZone, allSeries = [], canonicalUrl = '', series = '', }, schedulingEnabled, onSaveDraft, onConfigChange, previewLoading, }) => { let publishedField = ''; let existingSeries = ''; let publishedAtField = ''; const wasScheduled = publishedAtWas && moment(publishedAtWas) > moment(); // allow to edit published at if it was not set earlier or if it's in the future const editablePublishedAt = !publishedAtWas || wasScheduled; if (allSeries.length > 0) { const seriesNames = allSeries.map((name, index) => { return ( ); }); existingSeries = (
Existing series: {` `}
); } if (published) { if (wasScheduled) { publishedField = (
); } else { publishedField = (
Danger Zone
); } } if (schedulingEnabled && editablePublishedAt) { const currentDate = moment().format('YYYY-MM-DD'); publishedAtField = (
); } return (
); }; Options.propTypes = { passedData: PropTypes.shape({ published: PropTypes.bool.isRequired, publishedAtDate: PropTypes.string.isRequired, publishedAtTime: PropTypes.string.isRequired, publishedAtWas: PropTypes.string.isRequired, timezone: PropTypes.string.isRequired, allSeries: PropTypes.array.isRequired, canonicalUrl: PropTypes.string.isRequired, series: PropTypes.string.isRequired, }).isRequired, schedulingEnabled: PropTypes.bool.isRequired, onSaveDraft: PropTypes.func.isRequired, onConfigChange: PropTypes.func.isRequired, previewLoading: PropTypes.bool.isRequired, }; Options.displayName = 'Options';