Move the construction of the rule object out to it's own function

This commit is contained in:
mabashian
2020-03-27 09:25:33 -04:00
parent d9b613ccb3
commit 0c26734d7d

View File

@@ -26,8 +26,7 @@ function ScheduleAdd({ i18n, createSchedule }) {
const { pathname } = location; const { pathname } = location;
const pathRoot = pathname.substr(0, pathname.indexOf('schedules')); const pathRoot = pathname.substr(0, pathname.indexOf('schedules'));
const handleSubmit = async values => { const buildRuleObj = values => {
try {
const [startDate, startTime] = values.startDateTime.split('T'); const [startDate, startTime] = values.startDateTime.split('T');
// Dates are formatted like "YYYY-MM-DD" // Dates are formatted like "YYYY-MM-DD"
const [startYear, startMonth, startDay] = startDate.split('-'); const [startYear, startMonth, startDay] = startDate.split('-');
@@ -112,9 +111,7 @@ function ScheduleAdd({ i18n, createSchedule }) {
case 'onDate': { case 'onDate': {
const [endDate, endTime] = values.endDateTime.split('T'); const [endDate, endTime] = values.endDateTime.split('T');
const [endYear, endMonth, endDay] = endDate.split('-'); const [endYear, endMonth, endDay] = endDate.split('-');
const [endHour = 0, endMinute = 0, endSecond = 0] = endTime.split( const [endHour = 0, endMinute = 0, endSecond = 0] = endTime.split(':');
':'
);
ruleObj.until = new Date( ruleObj.until = new Date(
Date.UTC( Date.UTC(
endYear, endYear,
@@ -131,7 +128,12 @@ function ScheduleAdd({ i18n, createSchedule }) {
throw new Error(i18n._(t`End did not match an expected value`)); throw new Error(i18n._(t`End did not match an expected value`));
} }
const rule = new RRule(ruleObj); return ruleObj;
};
const handleSubmit = async values => {
try {
const rule = new RRule(buildRuleObj(values));
const { const {
data: { id: scheduleId }, data: { id: scheduleId },
} = await createSchedule({ } = await createSchedule({