import { Fragment, useState, ChangeEvent } from "react"; import * as Pages from "../../types/Pages"; import LabelledField from "../LabelledField"; import DateTimeSelect from "../DateTimeSelect"; import { errorsOn } from "./utils"; import usePageFormContext from "./usePageFormContext"; type Props = { authors: Pages.Author[]; statuses: Pages.StatusLabels; }; export default function Options({ authors, statuses }: Props) { const { state, dispatch } = usePageFormContext(); const { page, locale, templates } = state; const [showAdvanced, setShowAdvanced] = useState(false); const published = page.status == 2; const autopublish = published && page.published_at > new Date(); const url = page.urls[locale]; const handleChange = (attr: string) => (evt: ChangeEvent | ChangeEvent) => { dispatch({ type: "update", payload: { [attr]: evt.target.value } }); }; const handleChecked = (attr: string) => (evt: ChangeEvent) => { dispatch({ type: "update", payload: { [attr]: evt.target.checked } }); }; const changePublishedAt = (value: Date) => { dispatch({ type: "update", payload: { published_at: value } }); }; const toggleAdvanced = (evt: React.MouseEvent) => { evt.preventDefault(); setShowAdvanced(!showAdvanced); }; const toggleSkipIndex = (evt: React.ChangeEvent) => { dispatch({ type: "update", payload: { skip_index: evt.target.checked } }); }; return (
{published && (
{autopublish &&

This page will publish later

}
)}

Advanced options

{showAdvanced && ( )} {url && ( {url} )}
); }