// @flow import React from 'react'; import { FormField } from 'component/common/form'; import DateTimePicker from 'react-datetime-picker'; import moment from 'moment'; function linuxTimestampToDate(linuxTimestamp: number) { return new Date(linuxTimestamp * 1000); } function dateToLinuxTimestamp(date: Date) { return Number(Math.round(date.getTime() / 1000)); } type Props = { releaseTime: ?number, updatePublishForm: ({}) => void, }; const PublishStreamReleaseDate = (props: Props) => { const { releaseTime, updatePublishForm } = props; const [date, setDate] = React.useState(releaseTime ? linuxTimestampToDate(releaseTime) : 'DEFAULT'); const [publishLater, setPublishLater] = React.useState(Boolean(releaseTime)); const handleToggle = () => { const shouldPublishLater = !publishLater; setPublishLater(shouldPublishLater); onDateTimePickerChanged( shouldPublishLater ? moment().add('1', 'hour').add('30', 'minutes').startOf('hour').toDate() : 'DEFAULT' ); }; const onDateTimePickerChanged = (value) => { if (value === 'DEFAULT') { setDate(undefined); updatePublishForm({ releaseTimeEdited: undefined }); } else { setDate(value); updatePublishForm({ releaseTimeEdited: dateToLinuxTimestamp(value) }); } }; const helpText = !publishLater ? __( 'Confirmation process takes a few minutes, but then you can go live anytime. The stream is not shown anywhere until you are broadcasting.' ) : __( 'Your scheduled streams will appear on your channel page and for your followers. Chat will not be active until 5 minutes before the start time.' ); return (
{publishLater && (
)}

{helpText}

); }; export default PublishStreamReleaseDate;