UNPKG

@sanity/scheduled-publishing

Version:

> [!IMPORTANT] > As of [v3.39.0](https://www.sanity.io/changelog/e6013ee5-8214-4e03-9593-f7b19124b8a3) of Sanity Studio, this plugin has been deprecated and the Scheduled Publishing functionality has been moved into the core studio package. > Read more an

33 lines (28 loc) 850 B
import {useCallback, useState} from 'react' import {Schedule, ScheduleFormData} from '../types' // eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types export default function useScheduleForm(schedule?: Schedule) { const [isDirty, setIsDirty] = useState(false) const [formData, setFormData] = useState<ScheduleFormData | null>( schedule && schedule?.executeAt ? { date: schedule.executeAt, } : null ) const handleFormChange = useCallback( (form: ScheduleFormData) => { const equalDates = schedule?.executeAt && new Date(schedule.executeAt).getTime() === new Date(form?.date).getTime() setFormData(form) setIsDirty(!equalDates) }, [schedule?.executeAt] ) return { formData, isDirty, onFormChange: handleFormChange, } }