|
|
@@ -133,7 +133,10 @@ export const validateTimeLeaveRecord = ( |
|
|
|
} |
|
|
|
}); |
|
|
|
|
|
|
|
return Object.keys(errors).length > 0 ? errors : undefined; |
|
|
|
const hasErrors = Object.keys(errors).length > 0; |
|
|
|
const temporarilySaveable = isTemporarilySaveable(records, errors, holidays); |
|
|
|
|
|
|
|
return !temporarilySaveable && hasErrors ? errors : undefined; |
|
|
|
}; |
|
|
|
|
|
|
|
export const checkTotalHours = ( |
|
|
@@ -180,3 +183,35 @@ export const checkTotalHours = ( |
|
|
|
|
|
|
|
export const DAILY_NORMAL_MAX_HOURS = 8; |
|
|
|
export const TIMESHEET_DAILY_MAX_HOURS = 20; |
|
|
|
|
|
|
|
export const isTemporarilySaveable = ( |
|
|
|
records: RecordTimeLeaveInput, |
|
|
|
errors: { [date: string]: string }, |
|
|
|
holidays: Set<string>, |
|
|
|
): boolean => { |
|
|
|
const filledDates = Object.keys(records) |
|
|
|
.reduce<{ date: string; hasFilled: boolean }[]>((acc, date) => { |
|
|
|
const dayJsObj = dayjs(date); |
|
|
|
const isHoliday = |
|
|
|
holidays.has(date) || dayJsObj.day() === 0 || dayJsObj.day() === 6; |
|
|
|
if (isHoliday) { |
|
|
|
return acc; |
|
|
|
} |
|
|
|
return [...acc, { date, hasFilled: !Boolean(errors[date]) }]; |
|
|
|
}, []) |
|
|
|
.sort((a, b) => dayjs(a.date).diff(dayjs(b.date))); |
|
|
|
|
|
|
|
const isConsecutivelyFilled = filledDates.every((currentDate, index) => { |
|
|
|
if (index === 0) { |
|
|
|
return true; |
|
|
|
} |
|
|
|
|
|
|
|
if (currentDate.hasFilled && !filledDates[index - 1].hasFilled) { |
|
|
|
return false; |
|
|
|
} |
|
|
|
|
|
|
|
return true; |
|
|
|
}); |
|
|
|
|
|
|
|
return isConsecutivelyFilled; |
|
|
|
}; |