feat: Add more snooze options (#7344)
This commit is contained in:
66
app/javascript/dashboard/helper/snoozeHelpers.js
Normal file
66
app/javascript/dashboard/helper/snoozeHelpers.js
Normal file
@@ -0,0 +1,66 @@
|
||||
import {
|
||||
getUnixTime,
|
||||
format,
|
||||
add,
|
||||
startOfWeek,
|
||||
addWeeks,
|
||||
startOfMonth,
|
||||
isMonday,
|
||||
isToday,
|
||||
setHours,
|
||||
} from 'date-fns';
|
||||
import wootConstants from 'dashboard/constants/globals';
|
||||
|
||||
const SNOOZE_OPTIONS = wootConstants.SNOOZE_OPTIONS;
|
||||
|
||||
export const findStartOfNextWeek = currentDate => {
|
||||
const startOfNextWeek = startOfWeek(addWeeks(currentDate, 1));
|
||||
return isMonday(startOfNextWeek)
|
||||
? startOfNextWeek
|
||||
: add(startOfNextWeek, {
|
||||
days: (8 - startOfNextWeek.getDay()) % 7,
|
||||
});
|
||||
};
|
||||
|
||||
export const findStartOfNextMonth = currentDate => {
|
||||
const startOfNextMonth = startOfMonth(add(currentDate, { months: 1 }));
|
||||
return isMonday(startOfNextMonth)
|
||||
? startOfNextMonth
|
||||
: add(startOfNextMonth, {
|
||||
days: (8 - startOfNextMonth.getDay()) % 7,
|
||||
});
|
||||
};
|
||||
|
||||
export const findNextDay = currentDate => {
|
||||
return add(currentDate, { days: 1 });
|
||||
};
|
||||
|
||||
export const setHoursToNine = date => {
|
||||
return setHours(date, 9, 0, 0);
|
||||
};
|
||||
|
||||
export const findSnoozeTime = (snoozeType, currentDate = new Date()) => {
|
||||
let parsedDate = null;
|
||||
if (snoozeType === SNOOZE_OPTIONS.AN_HOUR_FROM_NOW) {
|
||||
parsedDate = add(currentDate, { hours: 1 });
|
||||
} else if (snoozeType === SNOOZE_OPTIONS.UNTIL_TOMORROW) {
|
||||
parsedDate = setHoursToNine(findNextDay(currentDate));
|
||||
} else if (snoozeType === SNOOZE_OPTIONS.UNTIL_NEXT_WEEK) {
|
||||
parsedDate = setHoursToNine(findStartOfNextWeek(currentDate));
|
||||
} else if (snoozeType === SNOOZE_OPTIONS.UNTIL_NEXT_MONTH) {
|
||||
parsedDate = setHoursToNine(findStartOfNextMonth(currentDate));
|
||||
}
|
||||
|
||||
return parsedDate ? getUnixTime(parsedDate) : null;
|
||||
};
|
||||
export const conversationReopenTime = snoozedUntil => {
|
||||
if (!snoozedUntil) {
|
||||
return null;
|
||||
}
|
||||
const date = new Date(snoozedUntil);
|
||||
|
||||
if (isToday(date)) {
|
||||
return format(date, 'h.mmaaa');
|
||||
}
|
||||
return snoozedUntil ? format(date, 'd MMM, h.mmaaa') : null;
|
||||
};
|
||||
Reference in New Issue
Block a user