Skip to content

Commit

Permalink
fix: creating new release allows for scheduled time to be set
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanl17 committed Jan 17, 2025
1 parent bc92a49 commit 357eb9a
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import {format, isValid} from 'date-fns'
import {useCallback, useState} from 'react'

import {MONTH_PICKER_VARIANT} from '../../../../ui-components/inputs/DateInputs/calendar/Calendar'
import {DatePicker} from '../../../../ui-components/inputs/DateInputs/DatePicker'
import {LazyTextInput} from '../../../../ui-components/inputs/DateInputs/LazyTextInput'

type ScheduledTimePickerProps = {
initialValue?: Date
onChange: (date: string) => void
}

export const ScheduledTimePicker: React.FC<ScheduledTimePickerProps> = ({
initialValue,
onChange,
}) => {
const [inputValue, setInputValue] = useState<Date | undefined>(initialValue)

const handleInputChange = useCallback((event: React.FocusEvent<HTMLInputElement>) => {
const parsedDate = new Date(event.currentTarget.value)

if (isValid(parsedDate)) {
setInputValue(parsedDate)

onChange(parsedDate.toISOString())
}
}, [])

return (
<>
<LazyTextInput
value={inputValue ? format(inputValue, 'PPp') : undefined}
onChange={handleInputChange}
readOnly
/>

<DatePicker
ref={datePickerRef}
monthPickerVariant={MONTH_PICKER_VARIANT.carousel}
calendarLabels={calendarLabels}
selectTime
padding={0}
value={inputValue}
onChange={handleBundlePublishAtChange}
showTimezone
/>
</>
)
}
41 changes: 20 additions & 21 deletions packages/sanity/src/core/releases/tool/detail/ReleaseTypePicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ import {isEqual} from 'lodash'
import {useCallback, useEffect, useMemo, useRef, useState} from 'react'

import {Button, Popover, Tab} from '../../../../ui-components'
import {MONTH_PICKER_VARIANT} from '../../../../ui-components/inputs/DateInputs/calendar/Calendar'
import {type CalendarLabels} from '../../../../ui-components/inputs/DateInputs/calendar/types'
import {DatePicker} from '../../../../ui-components/inputs/DateInputs/DatePicker'
import {LazyTextInput} from '../../../../ui-components/inputs/DateInputs/LazyTextInput'
import {getCalendarLabels} from '../../../form/inputs/DateInputs/utils'
import {useTranslation} from '../../../i18n/hooks/useTranslation'
import useTimeZone from '../../../scheduledPublishing/hooks/useTimeZone'
Expand All @@ -18,6 +15,7 @@ import {type ReleaseDocument, type ReleaseType} from '../../store'
import {useReleaseOperations} from '../../store/useReleaseOperations'
import {getReleaseTone} from '../../util/getReleaseTone'
import {getPublishDateFromRelease, isReleaseScheduledOrScheduling} from '../../util/util'
import {ScheduledTimePicker} from '../components/ScheduledTimePicker'

export function ReleaseTypePicker(props: {release: ReleaseDocument}): React.JSX.Element {
const {release} = props
Expand Down Expand Up @@ -179,24 +177,25 @@ export function ReleaseTypePicker(props: {release: ReleaseDocument}): React.JSX.
/>
</TabList>
{dateInputOpen && (
<>
<LazyTextInput
value={inputValue ? format(inputValue, 'PPp') : undefined}
onChange={handleInputChange}
readOnly
/>

<DatePicker
ref={datePickerRef}
monthPickerVariant={MONTH_PICKER_VARIANT.carousel}
calendarLabels={calendarLabels}
selectTime
padding={0}
value={inputValue}
onChange={handleBundlePublishAtChange}
showTimezone
/>
</>
<ScheduledTimePicker initialValue={inputValue} />
// <>
// <LazyTextInput
// value={inputValue ? format(inputValue, 'PPp') : undefined}
// onChange={handleInputChange}
// readOnly
// />

// <DatePicker
// ref={datePickerRef}
// monthPickerVariant={MONTH_PICKER_VARIANT.carousel}
// calendarLabels={calendarLabels}
// selectTime
// padding={0}
// value={inputValue}
// onChange={handleBundlePublishAtChange}
// showTimezone
// />
// </>
)}
</Stack>
)
Expand Down

0 comments on commit 357eb9a

Please sign in to comment.