달력
This commit is contained in:
@@ -15,7 +15,7 @@ interface NiceCalendarProps {
|
||||
endMonth?: string;
|
||||
singleMonth?: string;
|
||||
calendarType: CalendarType;
|
||||
setNewMonth: (month: string) => void;
|
||||
setNewMonth: (month: string, calendarType: CalendarType) => void;
|
||||
searchPeriod?: number;
|
||||
periodType?: 'year' | 'month';
|
||||
};
|
||||
@@ -37,8 +37,28 @@ const NiceCalendarMonth = ({
|
||||
const [valueMonth, setValueMonth] = useState<Date | undefined>();
|
||||
const [minMonth, setMinMonth] = useState<Date | undefined>();
|
||||
const [maxMonth, setMaxMonth] = useState<Date | undefined>();
|
||||
|
||||
const [calendarSearchPeriod, setCalendatSearchPeriod] = useState<number>(searchPeriod || 2);
|
||||
const [calendarPeriodType, setCalendarPeriodType] = useState<'year' | 'month'>(periodType || 'year');
|
||||
|
||||
const onChangeToMonth = (selectedMonth: any) => {
|
||||
setNewMonth(moment(selectedMonth).format('YYYY.MM'));
|
||||
if(calendarType === CalendarType.Start){
|
||||
if(endMonth){
|
||||
let newEndDateLimit = moment(selectedMonth).add(calendarSearchPeriod, calendarPeriodType).format('YYYYMM');
|
||||
if(moment(endMonth).format('YYYYMM') > newEndDateLimit){
|
||||
setNewMonth(moment(newEndDateLimit).format('YYYY.MM'), CalendarType.End);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(calendarType === CalendarType.End){
|
||||
if(startMonth){
|
||||
let newStartDateLimit = moment(selectedMonth).subtract(calendarSearchPeriod, calendarPeriodType).format('YYYYMM');
|
||||
if(moment(startMonth).format('YYYYMM') < newStartDateLimit){
|
||||
setNewMonth(moment(newStartDateLimit).format('YYYY.MM'), CalendarType.Start);
|
||||
}
|
||||
}
|
||||
}
|
||||
setNewMonth(moment(selectedMonth).format('YYYY.MM'), calendarType);
|
||||
setCalendarOpen(false);
|
||||
};
|
||||
|
||||
@@ -47,19 +67,8 @@ const NiceCalendarMonth = ({
|
||||
};
|
||||
const setMinMaxValueDate = () => {
|
||||
if(calendarType === CalendarType.Start){
|
||||
if(!searchPeriod){
|
||||
searchPeriod = 3;
|
||||
}
|
||||
if(!periodType){
|
||||
periodType = 'year';
|
||||
}
|
||||
if(periodType && searchPeriod && searchPeriod > 0){
|
||||
const endDate = moment(endMonth, ['YYYY.MM', 'YYYYMM'], true);
|
||||
setMinMonth(moment(endDate, 'YYYY.MM.DD').subtract(searchPeriod, periodType).toDate());
|
||||
}
|
||||
// setMinMonth(undefined);
|
||||
setMinMonth(undefined);
|
||||
if(!!endMonth){
|
||||
// Parse endMonth with moment, handling both YYYY.MM and YYYYMM formats
|
||||
const endDate = moment(endMonth, ['YYYY.MM', 'YYYYMM'], true);
|
||||
if(endDate.isValid()){
|
||||
setMaxMonth(endDate.toDate());
|
||||
@@ -70,7 +79,8 @@ const NiceCalendarMonth = ({
|
||||
if (startDate.isValid()) {
|
||||
setValueMonth(startDate.toDate());
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else{
|
||||
setValueMonth(undefined);
|
||||
}
|
||||
}
|
||||
@@ -88,7 +98,8 @@ const NiceCalendarMonth = ({
|
||||
if(endDate.isValid()){
|
||||
setValueMonth(endDate.toDate());
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else{
|
||||
setValueMonth(undefined);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,9 +65,7 @@ export const FilterCalendarMonth = ({
|
||||
}
|
||||
};
|
||||
|
||||
const setNewMonth = (month: string) => {
|
||||
console.log(month)
|
||||
// month is already in 'YYYY.MM' format from NiceCalendarMonth
|
||||
const setNewMonth = (month: string, calendarType: CalendarType) => {
|
||||
const parsedMonth = moment(month, 'YYYY.MM', true);
|
||||
if (parsedMonth.isValid()) {
|
||||
if(calendarType === CalendarType.Start){
|
||||
|
||||
Reference in New Issue
Block a user