UNPKG

payload-plugin-scheduler

Version:
44 lines (43 loc) 1.75 kB
'use client'; import React from 'react'; import { useDocumentInfo } from '@payloadcms/ui'; import { formatDateTime } from '../../util.js'; import { text } from '../styles.js'; import Icon from '../Icon.js'; const AfterInputClient = ({ scheduledAt, path, currentFormValue, status })=>{ const { initialData } = useDocumentInfo(); const initialFormValue = initialData?.[path]; const currentPublishDate = currentFormValue ? new Date(currentFormValue) : null; const isFuture = currentPublishDate && currentPublishDate > new Date(); const isScheduled = scheduledAt && new Date(scheduledAt) > new Date() && status === 'draft'; const isSchedulePending = currentPublishDate && currentPublishDate > new Date() && currentFormValue !== scheduledAt && currentFormValue !== initialFormValue; const error = isFuture && !isSchedulePending && !isScheduled; let color = undefined; let message = undefined; if (isScheduled) { color = 'var(--color-warning-650)'; message = `Scheduled for ${formatDateTime(new Date(scheduledAt))}`; } if (isSchedulePending) { color = 'var(--color-blue-650)'; message = `Save to schedule for ${formatDateTime(currentPublishDate)}`; } if (error) { color = 'var(--color-error-650)'; message = `Error scheduling document`; } const style = { ...text, color }; return /*#__PURE__*/ React.createElement("div", null, isFuture && /*#__PURE__*/ React.createElement("p", { style: style }, /*#__PURE__*/ React.createElement(Icon, { color: color, style: { marginBottom: 0 } }), message)); }; export default AfterInputClient; //# sourceMappingURL=client.js.map