Merged in fix/datepicker-select-first-of-month (pull request #2497)

fix: able to select 1st of month on the 1st of each month

* fix: able to select 1st of month on the 1st of each month


Approved-by: Anton Gunnarsson
This commit is contained in:
Joakim Jäderberg
2025-07-01 13:33:11 +00:00
parent f2b81b8c7a
commit 3169bd892b
4 changed files with 26 additions and 8 deletions

View File

@@ -33,10 +33,14 @@ export default function DatePickerRangeDesktop({
/** English is default language and doesn't need to be imported */
const locale = lang === Lang.en ? undefined : locales[lang]
const currentDate = dt().toDate()
const lastDayOfPreviousMonth = dt(currentDate)
.set("date", 1)
.subtract(1, "day")
.toDate()
const yesterday = dt(currentDate).subtract(1, "day").toDate()
// Max future date allowed to book kept same as of existing prod.
const endDate = dt().add(395, "day").toDate()
const endDate = dt(currentDate).add(395, "day").toDate()
const endOfLastMonth = dt(endDate).endOf("month").toDate()
function handleMonthChange(selected: Date) {
@@ -63,7 +67,7 @@ export default function DatePickerRangeDesktop({
button_previous: `${classNames.button_previous} ${styles.button_previous}`,
}}
disabled={[
{ from: undefined, to: yesterday },
{ from: lastDayOfPreviousMonth, to: yesterday },
{ from: endDate, to: endOfLastMonth },
]}
excludeDisabled

View File

@@ -33,7 +33,13 @@ export default function DatePickerRangeMobile({
const [autoScrollEnabled, setAutoScrollEnabled] = useState(true)
const currentDate = dt().toDate()
const lastDayOfPreviousMonth = dt(currentDate)
.set("date", 1)
.subtract(1, "day")
.toDate()
const yesterday = dt(currentDate).subtract(1, "day").toDate()
useEffect(() => {
if (!monthsRef.current || !selectedRange?.from || !autoScrollEnabled) return
@@ -57,7 +63,7 @@ export default function DatePickerRangeMobile({
}
// Max future date allowed to book kept same as of existing prod.
const endDate = dt().add(395, "day").toDate()
const endDate = dt(currentDate).add(395, "day").toDate()
const endOfLastMonth = dt(endDate).endOf("month").toDate()
return (
<div className={styles.container} ref={monthsRef}>
@@ -83,7 +89,7 @@ export default function DatePickerRangeMobile({
weekday: `${classNames.weekday} ${styles.weekDay}`,
}}
disabled={[
{ from: undefined, to: yesterday },
{ from: lastDayOfPreviousMonth, to: yesterday },
{ from: endDate, to: endOfLastMonth },
]}
endMonth={endDate}

View File

@@ -34,10 +34,14 @@ export default function DatePickerSingleDesktop({
/** English is default language and doesn't need to be imported */
const locale = lang === Lang.en ? undefined : locales[lang]
const currentDate = dt().toDate()
const lastDayOfPreviousMonth = dt(currentDate)
.set("date", 1)
.subtract(1, "day")
.toDate()
const yesterday = dt(currentDate).subtract(1, "day").toDate()
// Max future date allowed to book kept same as of existing prod.
const endDate = dt().add(395, "day").toDate()
const endDate = dt(currentDate).add(395, "day").toDate()
const endOfLastMonth = dt(endDate).endOf("month").toDate()
function handleMonthChange(selected: Date) {
@@ -65,7 +69,7 @@ export default function DatePickerSingleDesktop({
button_previous: `${classNames.button_previous} ${styles.button_previous}`,
}}
disabled={[
{ from: undefined, to: yesterday },
{ from: lastDayOfPreviousMonth, to: yesterday },
{ from: endDate, to: endOfLastMonth },
]}
footer

View File

@@ -29,10 +29,14 @@ export default function DatePickerSingleMobile({
/** English is default language and doesn't need to be imported */
const locale = lang === Lang.en ? undefined : locales[lang]
const currentDate = dt().toDate()
const lastDayOfPreviousMonth = dt(currentDate)
.set("date", 1)
.subtract(1, "day")
.toDate()
const yesterday = dt(currentDate).subtract(1, "day").toDate()
// Max future date allowed to book kept same as of existing prod.
const endDate = dt().add(395, "day").toDate()
const endDate = dt(currentDate).add(395, "day").toDate()
const endOfLastMonth = dt(endDate).endOf("month").toDate()
return (
@@ -51,7 +55,7 @@ export default function DatePickerSingleMobile({
weekday: `${classNames.weekday} ${styles.weekDay}`,
}}
disabled={[
{ from: undefined, to: yesterday },
{ from: lastDayOfPreviousMonth, to: yesterday },
{ from: endDate, to: endOfLastMonth },
]}
endMonth={endDate}