Skip to content

Commit a6f7cc4

Browse files
committed
fix: period picker
1 parent 725923b commit a6f7cc4

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

apps/frontend/src/components/questionnaire/PeriodForm.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@ export function PeriodForm({ onSave, actionLabel, period }: PeriodFormProps) {
2626

2727
const f = useForm<PeriodFormValues>({
2828
initialValues: period,
29-
onValuesChange({ range: [newStart, newEnd] }, { range: [prevStart, prevEnd] }) {
29+
mode: "uncontrolled",
30+
onValuesChange(newValues, prevValues) {
31+
const [newStart, newEnd] = newValues.range ?? [];
32+
const [prevStart, prevEnd] = prevValues.range ?? [];
33+
3034
if ((!prevStart || !prevEnd) && newStart && newEnd) {
3135
f.setFieldValue("title", t.defaultTitle({ start: formatDate(newStart, "M/YY"), end: formatDate(newEnd, "M/YY") }));
3236
}

libs/ui/src/components/MonthPicker.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export function MonthPicker<Type extends DatePickerType = "default">({ selectEnd
1919
const onChange: MonthPickerProps<Type>["onChange"] = (date) => {
2020
if (rest.type === "range" && isRangeValue(date) && selectEndOfMonth) {
2121
const [start, end] = date;
22-
const newDate = [start, dayjs(end).utc().endOf("month").toDate()];
22+
const newDate = [start, end ? dayjs(end).utc().endOf("month").toDate() : undefined];
2323
date = newDate as typeof date;
2424
}
2525
rest.onChange!(date);

0 commit comments

Comments
 (0)