create-nextjs-cms 0.9.7 → 0.9.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -57,7 +57,7 @@ function formatValue(date: Date | undefined, format: 'date' | 'datetime'): strin
|
|
|
57
57
|
}
|
|
58
58
|
|
|
59
59
|
export default function DateRangeFormInput({ input }: { input: DateRangeFieldClientConfig }) {
|
|
60
|
-
const { control } = useFormContext()
|
|
60
|
+
const { control, setValue } = useFormContext()
|
|
61
61
|
const [open, setOpen] = React.useState(false)
|
|
62
62
|
const minDate = resolveBound(input.minDate)
|
|
63
63
|
const maxDate = resolveBound(input.maxDate)
|
|
@@ -65,6 +65,8 @@ export default function DateRangeFormInput({ input }: { input: DateRangeFieldCli
|
|
|
65
65
|
...(minDate ? [{ before: toCalendarDay(minDate) as Date }] : []),
|
|
66
66
|
...(maxDate ? [{ after: toCalendarDay(maxDate) as Date }] : []),
|
|
67
67
|
]
|
|
68
|
+
const initialFrom = toDate(input.startValue)
|
|
69
|
+
const initialTo = toDate(input.endValue)
|
|
68
70
|
|
|
69
71
|
const {
|
|
70
72
|
field: startField,
|
|
@@ -72,7 +74,7 @@ export default function DateRangeFormInput({ input }: { input: DateRangeFieldCli
|
|
|
72
74
|
} = useController({
|
|
73
75
|
name: input.startName,
|
|
74
76
|
control,
|
|
75
|
-
defaultValue:
|
|
77
|
+
defaultValue: initialFrom,
|
|
76
78
|
})
|
|
77
79
|
|
|
78
80
|
const {
|
|
@@ -81,14 +83,30 @@ export default function DateRangeFormInput({ input }: { input: DateRangeFieldCli
|
|
|
81
83
|
} = useController({
|
|
82
84
|
name: input.endName,
|
|
83
85
|
control,
|
|
84
|
-
defaultValue:
|
|
86
|
+
defaultValue: initialTo,
|
|
85
87
|
})
|
|
86
88
|
|
|
87
89
|
const [range, setRange] = React.useState<DateRange | undefined>({
|
|
88
|
-
from:
|
|
89
|
-
to:
|
|
90
|
+
from: initialFrom,
|
|
91
|
+
to: initialTo,
|
|
90
92
|
})
|
|
91
93
|
|
|
94
|
+
React.useEffect(() => {
|
|
95
|
+
const nextFrom = toDate(input.startValue)
|
|
96
|
+
const nextTo = toDate(input.endValue)
|
|
97
|
+
const nextRange =
|
|
98
|
+
nextFrom || nextTo
|
|
99
|
+
? {
|
|
100
|
+
from: nextFrom,
|
|
101
|
+
to: nextTo,
|
|
102
|
+
}
|
|
103
|
+
: undefined
|
|
104
|
+
|
|
105
|
+
setRange(nextRange)
|
|
106
|
+
setValue(input.startName, nextFrom)
|
|
107
|
+
setValue(input.endName, nextTo)
|
|
108
|
+
}, [input.startValue, input.endValue, input.startName, input.endName, setValue])
|
|
109
|
+
|
|
92
110
|
function handleSelect(selected: DateRange | undefined) {
|
|
93
111
|
setRange(selected)
|
|
94
112
|
startField.onChange(selected?.from ?? undefined)
|