2021-08-31 05:08:57 -04:00
|
|
|
import Vue from 'vue';
|
2020-07-29 02:09:49 -04:00
|
|
|
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
|
2022-09-28 02:08:11 -04:00
|
|
|
import { formatTimezone } from '~/lib/utils/datetime_utility';
|
2020-07-17 14:09:20 -04:00
|
|
|
import * as types from './mutation_types';
|
|
|
|
|
2021-08-31 05:08:57 -04:00
|
|
|
const formatTimezoneName = (freezePeriod, timezoneList) => {
|
|
|
|
const tz = timezoneList.find((timezone) => timezone.identifier === freezePeriod.cron_timezone);
|
|
|
|
return convertObjectPropsToCamelCase({
|
2020-07-29 02:09:49 -04:00
|
|
|
...freezePeriod,
|
2021-03-16 17:11:53 -04:00
|
|
|
cron_timezone: {
|
2022-09-28 02:08:11 -04:00
|
|
|
formattedTimezone: tz && formatTimezone(tz),
|
2021-05-11 02:10:29 -04:00
|
|
|
identifier: freezePeriod.cron_timezone,
|
2021-03-16 17:11:53 -04:00
|
|
|
},
|
2020-07-29 02:09:49 -04:00
|
|
|
});
|
2021-08-31 05:08:57 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
const setFreezePeriodIsDeleting = (state, id, isDeleting) => {
|
|
|
|
const freezePeriod = state.freezePeriods.find((f) => f.id === id);
|
|
|
|
|
|
|
|
if (!freezePeriod) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vue.set(freezePeriod, 'isDeleting', isDeleting);
|
|
|
|
};
|
2020-07-29 02:09:49 -04:00
|
|
|
|
2020-07-17 14:09:20 -04:00
|
|
|
export default {
|
|
|
|
[types.REQUEST_FREEZE_PERIODS](state) {
|
|
|
|
state.isLoading = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
[types.RECEIVE_FREEZE_PERIODS_SUCCESS](state, freezePeriods) {
|
|
|
|
state.isLoading = false;
|
2020-12-23 16:10:24 -05:00
|
|
|
state.freezePeriods = freezePeriods.map((freezePeriod) =>
|
2020-07-29 02:09:49 -04:00
|
|
|
formatTimezoneName(freezePeriod, state.timezoneData),
|
|
|
|
);
|
2020-07-17 14:09:20 -04:00
|
|
|
},
|
|
|
|
|
|
|
|
[types.REQUEST_ADD_FREEZE_PERIOD](state) {
|
|
|
|
state.isLoading = true;
|
|
|
|
},
|
|
|
|
|
|
|
|
[types.RECEIVE_ADD_FREEZE_PERIOD_SUCCESS](state) {
|
|
|
|
state.isLoading = false;
|
|
|
|
},
|
|
|
|
|
|
|
|
[types.RECEIVE_ADD_FREEZE_PERIOD_ERROR](state, error) {
|
|
|
|
state.isLoading = false;
|
|
|
|
state.error = error;
|
|
|
|
},
|
|
|
|
|
|
|
|
[types.SET_SELECTED_TIMEZONE](state, timezone) {
|
|
|
|
state.selectedTimezone = timezone.formattedTimezone;
|
|
|
|
state.selectedTimezoneIdentifier = timezone.identifier;
|
|
|
|
},
|
|
|
|
|
|
|
|
[types.SET_FREEZE_START_CRON](state, freezeStartCron) {
|
|
|
|
state.freezeStartCron = freezeStartCron;
|
|
|
|
},
|
|
|
|
|
|
|
|
[types.SET_FREEZE_END_CRON](state, freezeEndCron) {
|
|
|
|
state.freezeEndCron = freezeEndCron;
|
|
|
|
},
|
|
|
|
|
2021-03-16 17:11:53 -04:00
|
|
|
[types.SET_SELECTED_ID](state, id) {
|
|
|
|
state.selectedId = id;
|
|
|
|
},
|
|
|
|
|
2021-08-31 05:08:57 -04:00
|
|
|
[types.REQUEST_DELETE_FREEZE_PERIOD](state, id) {
|
|
|
|
setFreezePeriodIsDeleting(state, id, true);
|
|
|
|
},
|
|
|
|
|
|
|
|
[types.RECEIVE_DELETE_FREEZE_PERIOD_SUCCESS](state, id) {
|
|
|
|
state.freezePeriods = state.freezePeriods.filter((f) => f.id !== id);
|
|
|
|
},
|
|
|
|
|
|
|
|
[types.RECEIVE_DELETE_FREEZE_PERIOD_ERROR](state, id) {
|
|
|
|
setFreezePeriodIsDeleting(state, id, false);
|
|
|
|
},
|
|
|
|
|
2020-07-17 14:09:20 -04:00
|
|
|
[types.RESET_MODAL](state) {
|
|
|
|
state.freezeStartCron = '';
|
|
|
|
state.freezeEndCron = '';
|
|
|
|
state.selectedTimezone = '';
|
|
|
|
state.selectedTimezoneIdentifier = '';
|
2021-03-16 17:11:53 -04:00
|
|
|
state.selectedId = '';
|
2020-07-17 14:09:20 -04:00
|
|
|
},
|
|
|
|
};
|