|
|
@@ -32,7 +32,9 @@ export default function RangeCalendar({
|
|
|
minDate: externalMinDate,
|
|
|
maxDate: externalMaxDate,
|
|
|
initialStartDate,
|
|
|
- initialEndDate
|
|
|
+ initialEndDate,
|
|
|
+ initialYear,
|
|
|
+ initialMonth
|
|
|
}: {
|
|
|
isModalVisible: boolean;
|
|
|
closeModal: (startDate?: string | null, endDate?: string | null) => void;
|
|
|
@@ -45,6 +47,8 @@ export default function RangeCalendar({
|
|
|
maxDate?: string | Date | dayjs.Dayjs;
|
|
|
initialStartDate?: string | null;
|
|
|
initialEndDate?: string | null;
|
|
|
+ initialYear?: number;
|
|
|
+ initialMonth?: number;
|
|
|
}) {
|
|
|
const [selectedStartDate, setSelectedStartDate] = useState<string | null>(null);
|
|
|
const [selectedEndDate, setSelectedEndDate] = useState<string | null>(null);
|
|
|
@@ -53,7 +57,6 @@ export default function RangeCalendar({
|
|
|
const [endDate, setEndDate] = useState<DateType>(undefined);
|
|
|
const [currentMonth, setCurrentMonth] = useState<number | undefined>(undefined);
|
|
|
const [currentYear, setCurrentYear] = useState<number | undefined>(undefined);
|
|
|
- const [toolTipVisible, setToolTipVisible] = useState<boolean>(false);
|
|
|
|
|
|
const computedMinDate = externalMinDate
|
|
|
? dayjs(externalMinDate)
|
|
|
@@ -68,6 +71,8 @@ export default function RangeCalendar({
|
|
|
: undefined;
|
|
|
|
|
|
useEffect(() => {
|
|
|
+ if (!isModalVisible) return;
|
|
|
+
|
|
|
if (allowRangeSelection) {
|
|
|
if (initialStartDate) {
|
|
|
const startDateObj = dayjs(initialStartDate);
|
|
|
@@ -75,6 +80,14 @@ export default function RangeCalendar({
|
|
|
setStartDate(startDateObj);
|
|
|
setCurrentMonth(startDateObj.month());
|
|
|
setCurrentYear(startDateObj.year());
|
|
|
+ } else {
|
|
|
+ if (typeof initialYear === 'number' && initialYear !== 1) {
|
|
|
+ setCurrentYear(initialYear);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (typeof initialMonth === 'number') {
|
|
|
+ setCurrentMonth(initialMonth - 1);
|
|
|
+ }
|
|
|
}
|
|
|
if (initialEndDate) {
|
|
|
setSelectedEndDate(initialEndDate);
|
|
|
@@ -87,7 +100,15 @@ export default function RangeCalendar({
|
|
|
setCurrentMonth(dateObj.month());
|
|
|
setCurrentYear(dateObj.year());
|
|
|
}
|
|
|
- }, [isModalVisible, initialStartDate, initialEndDate, selectedDate, allowRangeSelection]);
|
|
|
+ }, [
|
|
|
+ isModalVisible,
|
|
|
+ initialStartDate,
|
|
|
+ initialEndDate,
|
|
|
+ selectedDate,
|
|
|
+ allowRangeSelection,
|
|
|
+ initialYear,
|
|
|
+ initialMonth
|
|
|
+ ]);
|
|
|
|
|
|
const getDisabledDates = (date: DateType) => {
|
|
|
const dateString = dayjs(date).format('YYYY-MM-DD');
|