Repository URL to install this package:
|
Version:
0.3.11 ▾
|
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
var _regenerator = require('babel-runtime/regenerator');
var _regenerator2 = _interopRequireDefault(_regenerator);
exports.default = settingsSaga;
var _effects = require('redux-saga/effects');
var _settings = require('../actions/settings');
var _actions = require('../actions');
var _settingsApi = require('./settingsApi');
var _settingsApi2 = _interopRequireDefault(_settingsApi);
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
var _marked = /*#__PURE__*/_regenerator2.default.mark(onNewPasswordSave),
_marked2 = /*#__PURE__*/_regenerator2.default.mark(onNewEmailSave),
_marked3 = /*#__PURE__*/_regenerator2.default.mark(onAccountSave),
_marked4 = /*#__PURE__*/_regenerator2.default.mark(onAccountDelete),
_marked5 = /*#__PURE__*/_regenerator2.default.mark(onThirdPartyDelete),
_marked6 = /*#__PURE__*/_regenerator2.default.mark(onFetchPremiums),
_marked7 = /*#__PURE__*/_regenerator2.default.mark(onLogout),
_marked8 = /*#__PURE__*/_regenerator2.default.mark(onDeleteCalendar),
_marked9 = /*#__PURE__*/_regenerator2.default.mark(onGetDoodleFeed),
_marked10 = /*#__PURE__*/_regenerator2.default.mark(onConnectDoodleFeed),
_marked11 = /*#__PURE__*/_regenerator2.default.mark(onResetDoodleFeed),
_marked12 = /*#__PURE__*/_regenerator2.default.mark(onDeleteAddressBook),
_marked13 = /*#__PURE__*/_regenerator2.default.mark(watchSaveNewPassword),
_marked14 = /*#__PURE__*/_regenerator2.default.mark(watchSaveEmail),
_marked15 = /*#__PURE__*/_regenerator2.default.mark(watchSaveAccount),
_marked16 = /*#__PURE__*/_regenerator2.default.mark(watchDeleteAccount),
_marked17 = /*#__PURE__*/_regenerator2.default.mark(watchDeleteThirdParty),
_marked18 = /*#__PURE__*/_regenerator2.default.mark(watchFetchPremiums),
_marked19 = /*#__PURE__*/_regenerator2.default.mark(watchLogout),
_marked20 = /*#__PURE__*/_regenerator2.default.mark(watchDeleteCalendar),
_marked21 = /*#__PURE__*/_regenerator2.default.mark(watchGetDoodleFeed),
_marked22 = /*#__PURE__*/_regenerator2.default.mark(watchConnectDoodleFeed),
_marked23 = /*#__PURE__*/_regenerator2.default.mark(watchResetDoodleFeed),
_marked24 = /*#__PURE__*/_regenerator2.default.mark(watchDeleteAddressBook),
_marked25 = /*#__PURE__*/_regenerator2.default.mark(settingsSaga);
function onNewPasswordSave(options, action) {
var _action$payload, newPassword, currentPassword, token;
return _regenerator2.default.wrap(function onNewPasswordSave$(_context) {
while (1) {
switch (_context.prev = _context.next) {
case 0:
_context.prev = 0;
_action$payload = action.payload, newPassword = _action$payload.newPassword, currentPassword = _action$payload.currentPassword;
_context.next = 4;
return (0, _effects.select)(function (state) {
return state.user.data.accessToken;
});
case 4:
token = _context.sent;
_context.next = 7;
return (0, _effects.call)(_settingsApi2.default.updateUser, { newPassword: newPassword, password: currentPassword }, token, options);
case 7:
_context.next = 9;
return (0, _effects.put)((0, _settings.saveNewPasswordSuccess)());
case 9:
_context.next = 15;
break;
case 11:
_context.prev = 11;
_context.t0 = _context['catch'](0);
_context.next = 15;
return (0, _effects.put)((0, _settings.saveNewPasswordError)(_context.t0));
case 15:
case 'end':
return _context.stop();
}
}
}, _marked, this, [[0, 11]]);
}
function onNewEmailSave(options, action) {
var token, newEmail;
return _regenerator2.default.wrap(function onNewEmailSave$(_context2) {
while (1) {
switch (_context2.prev = _context2.next) {
case 0:
_context2.prev = 0;
_context2.next = 3;
return (0, _effects.select)(function (state) {
return state.user.data.accessToken;
});
case 3:
token = _context2.sent;
newEmail = action.newEmail;
_context2.next = 7;
return (0, _effects.call)(_settingsApi2.default.updateUser, { newEmail: newEmail }, token, options);
case 7:
_context2.next = 9;
return (0, _effects.put)((0, _settings.saveNewEmailSuccess)());
case 9:
_context2.next = 15;
break;
case 11:
_context2.prev = 11;
_context2.t0 = _context2['catch'](0);
_context2.next = 15;
return (0, _effects.put)((0, _settings.saveNewEmailError)(_context2.t0));
case 15:
case 'end':
return _context2.stop();
}
}
}, _marked2, this, [[0, 11]]);
}
function onAccountSave(options, action) {
var token;
return _regenerator2.default.wrap(function onAccountSave$(_context3) {
while (1) {
switch (_context3.prev = _context3.next) {
case 0:
_context3.prev = 0;
_context3.next = 3;
return (0, _effects.select)(function (state) {
return state.user.data.accessToken;
});
case 3:
token = _context3.sent;
_context3.next = 6;
return (0, _effects.call)(_settingsApi2.default.updateUser, action.data, token, options);
case 6:
_context3.next = 8;
return (0, _effects.put)((0, _settings.saveAccountSuccess)());
case 8:
_context3.next = 14;
break;
case 10:
_context3.prev = 10;
_context3.t0 = _context3['catch'](0);
_context3.next = 14;
return (0, _effects.put)((0, _settings.saveAccountError)(_context3.t0));
case 14:
case 'end':
return _context3.stop();
}
}
}, _marked3, this, [[0, 10]]);
}
function onAccountDelete(options, action) {
var password, token;
return _regenerator2.default.wrap(function onAccountDelete$(_context4) {
while (1) {
switch (_context4.prev = _context4.next) {
case 0:
_context4.prev = 0;
password = action.password;
_context4.next = 4;
return (0, _effects.select)(function (state) {
return state.user.data.accessToken;
});
case 4:
token = _context4.sent;
_context4.next = 7;
return (0, _effects.call)(_settingsApi2.default.deleteAccount, token, { password: password }, options);
case 7:
_context4.next = 9;
return (0, _effects.put)((0, _settings.deleteAccountSuccess)());
case 9:
_context4.next = 15;
break;
case 11:
_context4.prev = 11;
_context4.t0 = _context4['catch'](0);
_context4.next = 15;
return (0, _effects.put)((0, _settings.deleteAccountError)(_context4.t0));
case 15:
case 'end':
return _context4.stop();
}
}
}, _marked4, this, [[0, 11]]);
}
function onThirdPartyDelete(options, action) {
var id, token;
return _regenerator2.default.wrap(function onThirdPartyDelete$(_context5) {
while (1) {
switch (_context5.prev = _context5.next) {
case 0:
_context5.prev = 0;
id = action.id;
_context5.next = 4;
return (0, _effects.select)(function (state) {
return state.user.data.accessToken;
});
case 4:
token = _context5.sent;
_context5.next = 7;
return (0, _effects.call)(_settingsApi2.default.deleteThirdParty, token, id, options);
case 7:
_context5.next = 9;
return (0, _effects.put)((0, _settings.deleteThirdPartySuccess)());
case 9:
_context5.next = 11;
return (0, _effects.put)((0, _actions.loadUser)());
case 11:
_context5.next = 17;
break;
case 13:
_context5.prev = 13;
_context5.t0 = _context5['catch'](0);
_context5.next = 17;
return (0, _effects.put)((0, _settings.deleteThirdPartyError)(_context5.t0));
case 17:
case 'end':
return _context5.stop();
}
}
}, _marked5, this, [[0, 13]]);
}
function onFetchPremiums(options) {
var token, premiums;
return _regenerator2.default.wrap(function onFetchPremiums$(_context6) {
while (1) {
switch (_context6.prev = _context6.next) {
case 0:
_context6.prev = 0;
_context6.next = 3;
return (0, _effects.select)(function (state) {
return state.user.data.accessToken;
});
case 3:
token = _context6.sent;
_context6.next = 6;
return (0, _effects.call)(_settingsApi2.default.fetchPremiums, token, options);
case 6:
premiums = _context6.sent;
_context6.next = 9;
return (0, _effects.put)((0, _settings.fetchPremiumsSuccess)(premiums));
case 9:
_context6.next = 15;
break;
case 11:
_context6.prev = 11;
_context6.t0 = _context6['catch'](0);
_context6.next = 15;
return (0, _effects.put)((0, _settings.fetchPremiumsError)(_context6.t0));
case 15:
case 'end':
return _context6.stop();
}
}
}, _marked6, this, [[0, 11]]);
}
function onLogout(options) {
return _regenerator2.default.wrap(function onLogout$(_context7) {
while (1) {
switch (_context7.prev = _context7.next) {
case 0:
_context7.next = 2;
return (0, _effects.put)((0, _settings.resetNags)());
case 2:
case 'end':
return _context7.stop();
}
}
}, _marked7, this);
}
function onDeleteCalendar(options, action) {
var id, token;
return _regenerator2.default.wrap(function onDeleteCalendar$(_context8) {
while (1) {
switch (_context8.prev = _context8.next) {
case 0:
_context8.prev = 0;
id = action.id;
_context8.next = 4;
return (0, _effects.select)(function (state) {
return state.user.data.accessToken;
});
case 4:
token = _context8.sent;
_context8.next = 7;
return (0, _effects.call)(_settingsApi2.default.deleteCalendar, token, id, options);
case 7:
_context8.next = 9;
return (0, _effects.put)((0, _settings.deleteCalendarSuccess)());
case 9:
_context8.next = 11;
return (0, _effects.put)((0, _actions.loadUser)());
case 11:
_context8.next = 17;
break;
case 13:
_context8.prev = 13;
_context8.t0 = _context8['catch'](0);
_context8.next = 17;
return (0, _effects.put)((0, _settings.deleteCalendarError)(_context8.t0));
case 17:
case 'end':
return _context8.stop();
}
}
}, _marked8, this, [[0, 13]]);
}
function onGetDoodleFeed(options) {
var token, feed;
return _regenerator2.default.wrap(function onGetDoodleFeed$(_context9) {
while (1) {
switch (_context9.prev = _context9.next) {
case 0:
_context9.prev = 0;
_context9.next = 3;
return (0, _effects.select)(function (state) {
return state.user.data.accessToken;
});
case 3:
token = _context9.sent;
_context9.next = 6;
return (0, _effects.call)(_settingsApi2.default.getDoodleFeed, token, options);
case 6:
feed = _context9.sent;
_context9.next = 9;
return (0, _effects.put)((0, _settings.getDoodleFeedSuccess)(feed.url));
case 9:
_context9.next = 15;
break;
case 11:
_context9.prev = 11;
_context9.t0 = _context9['catch'](0);
_context9.next = 15;
return (0, _effects.put)((0, _settings.getDoodleFeedError)(_context9.t0));
case 15:
case 'end':
return _context9.stop();
}
}
}, _marked9, this, [[0, 11]]);
}
function onConnectDoodleFeed(options, action) {
var url, token;
return _regenerator2.default.wrap(function onConnectDoodleFeed$(_context10) {
while (1) {
switch (_context10.prev = _context10.next) {
case 0:
_context10.prev = 0;
url = action.url;
_context10.next = 4;
return (0, _effects.select)(function (state) {
return state.user.data.accessToken;
});
case 4:
token = _context10.sent;
_context10.next = 7;
return (0, _effects.call)(_settingsApi2.default.connectDoodleFeed, token, { url: url }, options);
case 7:
_context10.next = 9;
return (0, _effects.put)((0, _settings.connectDoodleFeedSuccess)());
case 9:
_context10.next = 11;
return (0, _effects.put)((0, _actions.loadUser)());
case 11:
_context10.next = 17;
break;
case 13:
_context10.prev = 13;
_context10.t0 = _context10['catch'](0);
_context10.next = 17;
return (0, _effects.put)((0, _settings.connectDoodleFeedError)(_context10.t0));
case 17:
case 'end':
return _context10.stop();
}
}
}, _marked10, this, [[0, 13]]);
}
function onResetDoodleFeed(options) {
var token, feed;
return _regenerator2.default.wrap(function onResetDoodleFeed$(_context11) {
while (1) {
switch (_context11.prev = _context11.next) {
case 0:
_context11.prev = 0;
_context11.next = 3;
return (0, _effects.select)(function (state) {
return state.user.data.accessToken;
});
case 3:
token = _context11.sent;
_context11.next = 6;
return (0, _effects.call)(_settingsApi2.default.resetDoodleFeed, token, options);
case 6:
feed = _context11.sent;
_context11.next = 9;
return (0, _effects.put)((0, _settings.resetDoodleFeedSuccess)(feed.url));
case 9:
_context11.next = 15;
break;
case 11:
_context11.prev = 11;
_context11.t0 = _context11['catch'](0);
_context11.next = 15;
return (0, _effects.put)((0, _settings.resetDoodleFeedError)(_context11.t0));
case 15:
case 'end':
return _context11.stop();
}
}
}, _marked11, this, [[0, 11]]);
}
function onDeleteAddressBook(options, action) {
var id, token;
return _regenerator2.default.wrap(function onDeleteAddressBook$(_context12) {
while (1) {
switch (_context12.prev = _context12.next) {
case 0:
_context12.prev = 0;
id = action.id;
_context12.next = 4;
return (0, _effects.select)(function (state) {
return state.user.data.accessToken;
});
case 4:
token = _context12.sent;
_context12.next = 7;
return (0, _effects.call)(_settingsApi2.default.deleteAddressBook, token, id, options);
case 7:
_context12.next = 9;
return (0, _effects.put)((0, _settings.deleteAddressBookSuccess)());
case 9:
_context12.next = 11;
return (0, _effects.put)((0, _actions.loadUser)());
case 11:
_context12.next = 17;
break;
case 13:
_context12.prev = 13;
_context12.t0 = _context12['catch'](0);
_context12.next = 17;
return (0, _effects.put)((0, _settings.deleteAddressBookError)(_context12.t0));
case 17:
case 'end':
return _context12.stop();
}
}
}, _marked12, this, [[0, 13]]);
}
function watchSaveNewPassword(options) {
return _regenerator2.default.wrap(function watchSaveNewPassword$(_context13) {
while (1) {
switch (_context13.prev = _context13.next) {
case 0:
_context13.next = 2;
return (0, _effects.takeLatest)(_settings.SettingsActionTypes.SAVE_NEW_PASSWORD, onNewPasswordSave, options);
case 2:
case 'end':
return _context13.stop();
}
}
}, _marked13, this);
}
function watchSaveEmail(options) {
return _regenerator2.default.wrap(function watchSaveEmail$(_context14) {
while (1) {
switch (_context14.prev = _context14.next) {
case 0:
_context14.next = 2;
return (0, _effects.takeLatest)(_settings.SettingsActionTypes.SAVE_NEW_EMAIL, onNewEmailSave, options);
case 2:
case 'end':
return _context14.stop();
}
}
}, _marked14, this);
}
function watchSaveAccount(options) {
return _regenerator2.default.wrap(function watchSaveAccount$(_context15) {
while (1) {
switch (_context15.prev = _context15.next) {
case 0:
_context15.next = 2;
return (0, _effects.takeLatest)(_settings.SettingsActionTypes.SAVE_ACCOUNT, onAccountSave, options);
case 2:
case 'end':
return _context15.stop();
}
}
}, _marked15, this);
}
function watchDeleteAccount(options) {
return _regenerator2.default.wrap(function watchDeleteAccount$(_context16) {
while (1) {
switch (_context16.prev = _context16.next) {
case 0:
_context16.next = 2;
return (0, _effects.takeLatest)(_settings.SettingsActionTypes.DELETE_ACCOUNT, onAccountDelete, options);
case 2:
case 'end':
return _context16.stop();
}
}
}, _marked16, this);
}
function watchDeleteThirdParty(options) {
return _regenerator2.default.wrap(function watchDeleteThirdParty$(_context17) {
while (1) {
switch (_context17.prev = _context17.next) {
case 0:
_context17.next = 2;
return (0, _effects.takeLatest)(_settings.SettingsActionTypes.DELETE_THIRD_PARTY, onThirdPartyDelete, options);
case 2:
case 'end':
return _context17.stop();
}
}
}, _marked17, this);
}
function watchFetchPremiums(options) {
return _regenerator2.default.wrap(function watchFetchPremiums$(_context18) {
while (1) {
switch (_context18.prev = _context18.next) {
case 0:
_context18.next = 2;
return (0, _effects.takeLatest)(_settings.SettingsActionTypes.FETCH_PREMIUMS, onFetchPremiums, options);
case 2:
case 'end':
return _context18.stop();
}
}
}, _marked18, this);
}
function watchLogout(options) {
return _regenerator2.default.wrap(function watchLogout$(_context19) {
while (1) {
switch (_context19.prev = _context19.next) {
case 0:
_context19.next = 2;
return (0, _effects.takeLatest)(_actions.ActionTypes.LOGOUT, onLogout, options);
case 2:
case 'end':
return _context19.stop();
}
}
}, _marked19, this);
}
function watchDeleteCalendar(options) {
return _regenerator2.default.wrap(function watchDeleteCalendar$(_context20) {
while (1) {
switch (_context20.prev = _context20.next) {
case 0:
_context20.next = 2;
return (0, _effects.takeLatest)(_settings.SettingsActionTypes.DELETE_CALENDAR, onDeleteCalendar, options);
case 2:
case 'end':
return _context20.stop();
}
}
}, _marked20, this);
}
function watchGetDoodleFeed(options) {
return _regenerator2.default.wrap(function watchGetDoodleFeed$(_context21) {
while (1) {
switch (_context21.prev = _context21.next) {
case 0:
_context21.next = 2;
return (0, _effects.takeLatest)(_settings.SettingsActionTypes.GET_DOODLE_FEED, onGetDoodleFeed, options);
case 2:
case 'end':
return _context21.stop();
}
}
}, _marked21, this);
}
function watchConnectDoodleFeed(options) {
return _regenerator2.default.wrap(function watchConnectDoodleFeed$(_context22) {
while (1) {
switch (_context22.prev = _context22.next) {
case 0:
_context22.next = 2;
return (0, _effects.takeLatest)(_settings.SettingsActionTypes.CONNECT_DOODLE_FEED, onConnectDoodleFeed, options);
case 2:
case 'end':
return _context22.stop();
}
}
}, _marked22, this);
}
function watchResetDoodleFeed(options) {
return _regenerator2.default.wrap(function watchResetDoodleFeed$(_context23) {
while (1) {
switch (_context23.prev = _context23.next) {
case 0:
_context23.next = 2;
return (0, _effects.takeLatest)(_settings.SettingsActionTypes.RESET_DOODLE_FEED, onResetDoodleFeed, options);
case 2:
case 'end':
return _context23.stop();
}
}
}, _marked23, this);
}
function watchDeleteAddressBook(options) {
return _regenerator2.default.wrap(function watchDeleteAddressBook$(_context24) {
while (1) {
switch (_context24.prev = _context24.next) {
case 0:
_context24.next = 2;
return (0, _effects.takeLatest)(_settings.SettingsActionTypes.DELETE_ADDRESS_BOOK, onDeleteAddressBook, options);
case 2:
case 'end':
return _context24.stop();
}
}
}, _marked24, this);
}
function settingsSaga() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
return _regenerator2.default.wrap(function settingsSaga$(_context25) {
while (1) {
switch (_context25.prev = _context25.next) {
case 0:
_context25.next = 2;
return (0, _effects.all)([(0, _effects.call)(watchSaveNewPassword, options), (0, _effects.call)(watchSaveAccount, options), (0, _effects.call)(watchSaveEmail, options), (0, _effects.call)(watchDeleteAccount, options), (0, _effects.call)(watchDeleteThirdParty, options), (0, _effects.call)(watchFetchPremiums, options), (0, _effects.call)(watchLogout, options), (0, _effects.call)(watchDeleteCalendar, options), (0, _effects.call)(watchGetDoodleFeed, options), (0, _effects.call)(watchConnectDoodleFeed, options), (0, _effects.call)(watchResetDoodleFeed, options), (0, _effects.call)(watchDeleteAddressBook, options)]);
case 2:
case 'end':
return _context25.stop();
}
}
}, _marked25, this);
}