fix: SW-710 Updated max allowed booking dates as today
This commit is contained in:
@@ -34,7 +34,7 @@ export default function DatePickerDesktop({
|
|||||||
const currentDate = dt().toDate()
|
const currentDate = dt().toDate()
|
||||||
const startOfMonth = dt(currentDate).set("date", 1).toDate()
|
const startOfMonth = dt(currentDate).set("date", 1).toDate()
|
||||||
const yesterday = dt(currentDate).subtract(1, "day").toDate()
|
const yesterday = dt(currentDate).subtract(1, "day").toDate()
|
||||||
const endDate = dt().add(365, "day").toDate()
|
const endDate = dt().add(395, "day").toDate()
|
||||||
const endOfLastMonth = dt(endDate).endOf("month").toDate()
|
const endOfLastMonth = dt(endDate).endOf("month").toDate()
|
||||||
|
|
||||||
function handleMonthChange(selected: Date) {
|
function handleMonthChange(selected: Date) {
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ export default function DatePickerMobile({
|
|||||||
const startOfCurrentMonth = dt(currentDate).set("date", 1).toDate()
|
const startOfCurrentMonth = dt(currentDate).set("date", 1).toDate()
|
||||||
const yesterday = dt(currentDate).subtract(1, "day").toDate()
|
const yesterday = dt(currentDate).subtract(1, "day").toDate()
|
||||||
|
|
||||||
const endDate = dt().add(365, "day").toDate()
|
const endDate = dt().add(395, "day").toDate()
|
||||||
const endOfLastMonth = dt(endDate).endOf("month").toDate()
|
const endOfLastMonth = dt(endDate).endOf("month").toDate()
|
||||||
return (
|
return (
|
||||||
<DayPicker
|
<DayPicker
|
||||||
|
|||||||
@@ -42,8 +42,8 @@ export default function DatePickerForm({ name = "date" }: DatePickerFormProps) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function handleSelectDate(selected: Date) {
|
function handleSelectDate(selected: Date) {
|
||||||
// Handle Enter key press on any other input fields trigger day click update
|
/* check if selected date is not before todays date,
|
||||||
// Daypicker triggers onDayClick for a previous date on enter
|
which happens when "Enter" key is pressed in any other input field of the form */
|
||||||
if (!dt(selected).isBefore(dt(), "day")) {
|
if (!dt(selected).isBefore(dt(), "day")) {
|
||||||
if (isSelectingFrom) {
|
if (isSelectingFrom) {
|
||||||
setValue(name, {
|
setValue(name, {
|
||||||
@@ -84,24 +84,28 @@ export default function DatePickerForm({ name = "date" }: DatePickerFormProps) {
|
|||||||
setIsOpen(false)
|
setIsOpen(false)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[setIsOpen, setValue, setIsSelectingFrom, selectedDate, name]
|
[setIsOpen, setValue, setIsSelectingFrom, selectedDate, name, ref]
|
||||||
)
|
)
|
||||||
|
|
||||||
function closeOnBlur(evt: FocusEvent) {
|
function closeOnBlur(evt: FocusEvent) {
|
||||||
const target = evt.relatedTarget as HTMLElement
|
if (isOpen) {
|
||||||
closeIfOutside(target)
|
const target = evt.relatedTarget as HTMLElement
|
||||||
|
closeIfOutside(target)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
function handleClickOutside(evt: Event) {
|
function handleClickOutside(evt: Event) {
|
||||||
const target = evt.target as HTMLElement
|
if (isOpen) {
|
||||||
closeIfOutside(target)
|
const target = evt.target as HTMLElement
|
||||||
|
closeIfOutside(target)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
document.body.addEventListener("click", handleClickOutside)
|
document.body.addEventListener("click", handleClickOutside)
|
||||||
return () => {
|
return () => {
|
||||||
document.body.removeEventListener("click", handleClickOutside)
|
document.body.removeEventListener("click", handleClickOutside)
|
||||||
}
|
}
|
||||||
}, [closeIfOutside])
|
}, [closeIfOutside, isOpen])
|
||||||
|
|
||||||
const selectedFromDate = dt(selectedDate.fromDate)
|
const selectedFromDate = dt(selectedDate.fromDate)
|
||||||
.locale(lang)
|
.locale(lang)
|
||||||
|
|||||||
Reference in New Issue
Block a user