Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
Size: Mime:
'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _regenerator = require('babel-runtime/regenerator');

var _regenerator2 = _interopRequireDefault(_regenerator);

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

exports.getAccessToken = getAccessToken;
exports.getUserData = getUserData;
exports.onNewPasswordSave = onNewPasswordSave;
exports.onNewEmailSave = onNewEmailSave;
exports.onUserSave = onUserSave;
exports.onAccountDelete = onAccountDelete;
exports.onThirdPartyDelete = onThirdPartyDelete;
exports.onFetchPremiums = onFetchPremiums;
exports.onSaveBranding = onSaveBranding;
exports.onLogoUpload = onLogoUpload;
exports.onLogoRemove = onLogoRemove;
exports.onBackgroundUpload = onBackgroundUpload;
exports.onBackgroundRemove = onBackgroundRemove;
exports.onSaveTileBackground = onSaveTileBackground;
exports.onSaveBackgroundColor = onSaveBackgroundColor;
exports.onLogout = onLogout;
exports.onDeleteCalendar = onDeleteCalendar;
exports.onGetDoodleFeed = onGetDoodleFeed;
exports.onConnectDoodleFeed = onConnectDoodleFeed;
exports.onResetDoodleFeed = onResetDoodleFeed;
exports.onDeleteAddressBook = onDeleteAddressBook;
exports.onLogoutApps = onLogoutApps;
exports.onGetApps = onGetApps;
exports.onSaveAvatar = onSaveAvatar;
exports.onDeleteAvatar = onDeleteAvatar;
exports.watchSaveNewPassword = watchSaveNewPassword;
exports.watchSaveEmail = watchSaveEmail;
exports.watchSaveUser = watchSaveUser;
exports.watchDeleteAccount = watchDeleteAccount;
exports.watchDeleteThirdParty = watchDeleteThirdParty;
exports.watchFetchPremiums = watchFetchPremiums;
exports.watchSaveBranding = watchSaveBranding;
exports.watchLogoUpload = watchLogoUpload;
exports.watchLogoRemove = watchLogoRemove;
exports.watchBackgroundUpload = watchBackgroundUpload;
exports.watchBackgroundRemove = watchBackgroundRemove;
exports.watchLogout = watchLogout;
exports.watchDeleteCalendar = watchDeleteCalendar;
exports.watchGetDoodleFeed = watchGetDoodleFeed;
exports.watchConnectDoodleFeed = watchConnectDoodleFeed;
exports.watchResetDoodleFeed = watchResetDoodleFeed;
exports.watchDeleteAddressBook = watchDeleteAddressBook;
exports.watchLogoutApps = watchLogoutApps;
exports.watchGetApps = watchGetApps;
exports.watchSaveAvatar = watchSaveAvatar;
exports.watchDeleteAvatar = watchDeleteAvatar;
exports.watchSaveTileBackground = watchSaveTileBackground;
exports.watchSaveBackgroundColor = watchSaveBackgroundColor;
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(onUserSave),
    _marked4 = /*#__PURE__*/_regenerator2.default.mark(onAccountDelete),
    _marked5 = /*#__PURE__*/_regenerator2.default.mark(onThirdPartyDelete),
    _marked6 = /*#__PURE__*/_regenerator2.default.mark(onFetchPremiums),
    _marked7 = /*#__PURE__*/_regenerator2.default.mark(onSaveBranding),
    _marked8 = /*#__PURE__*/_regenerator2.default.mark(onLogoUpload),
    _marked9 = /*#__PURE__*/_regenerator2.default.mark(onLogoRemove),
    _marked10 = /*#__PURE__*/_regenerator2.default.mark(onBackgroundUpload),
    _marked11 = /*#__PURE__*/_regenerator2.default.mark(onBackgroundRemove),
    _marked12 = /*#__PURE__*/_regenerator2.default.mark(onSaveTileBackground),
    _marked13 = /*#__PURE__*/_regenerator2.default.mark(onSaveBackgroundColor),
    _marked14 = /*#__PURE__*/_regenerator2.default.mark(onLogout),
    _marked15 = /*#__PURE__*/_regenerator2.default.mark(onDeleteCalendar),
    _marked16 = /*#__PURE__*/_regenerator2.default.mark(onGetDoodleFeed),
    _marked17 = /*#__PURE__*/_regenerator2.default.mark(onConnectDoodleFeed),
    _marked18 = /*#__PURE__*/_regenerator2.default.mark(onResetDoodleFeed),
    _marked19 = /*#__PURE__*/_regenerator2.default.mark(onDeleteAddressBook),
    _marked20 = /*#__PURE__*/_regenerator2.default.mark(onLogoutApps),
    _marked21 = /*#__PURE__*/_regenerator2.default.mark(onGetApps),
    _marked22 = /*#__PURE__*/_regenerator2.default.mark(onSaveAvatar),
    _marked23 = /*#__PURE__*/_regenerator2.default.mark(onDeleteAvatar),
    _marked24 = /*#__PURE__*/_regenerator2.default.mark(watchSaveNewPassword),
    _marked25 = /*#__PURE__*/_regenerator2.default.mark(watchSaveEmail),
    _marked26 = /*#__PURE__*/_regenerator2.default.mark(watchSaveUser),
    _marked27 = /*#__PURE__*/_regenerator2.default.mark(watchDeleteAccount),
    _marked28 = /*#__PURE__*/_regenerator2.default.mark(watchDeleteThirdParty),
    _marked29 = /*#__PURE__*/_regenerator2.default.mark(watchFetchPremiums),
    _marked30 = /*#__PURE__*/_regenerator2.default.mark(watchSaveBranding),
    _marked31 = /*#__PURE__*/_regenerator2.default.mark(watchLogoUpload),
    _marked32 = /*#__PURE__*/_regenerator2.default.mark(watchLogoRemove),
    _marked33 = /*#__PURE__*/_regenerator2.default.mark(watchBackgroundUpload),
    _marked34 = /*#__PURE__*/_regenerator2.default.mark(watchBackgroundRemove),
    _marked35 = /*#__PURE__*/_regenerator2.default.mark(watchLogout),
    _marked36 = /*#__PURE__*/_regenerator2.default.mark(watchDeleteCalendar),
    _marked37 = /*#__PURE__*/_regenerator2.default.mark(watchGetDoodleFeed),
    _marked38 = /*#__PURE__*/_regenerator2.default.mark(watchConnectDoodleFeed),
    _marked39 = /*#__PURE__*/_regenerator2.default.mark(watchResetDoodleFeed),
    _marked40 = /*#__PURE__*/_regenerator2.default.mark(watchDeleteAddressBook),
    _marked41 = /*#__PURE__*/_regenerator2.default.mark(watchLogoutApps),
    _marked42 = /*#__PURE__*/_regenerator2.default.mark(watchGetApps),
    _marked43 = /*#__PURE__*/_regenerator2.default.mark(watchSaveAvatar),
    _marked44 = /*#__PURE__*/_regenerator2.default.mark(watchDeleteAvatar),
    _marked45 = /*#__PURE__*/_regenerator2.default.mark(watchSaveTileBackground),
    _marked46 = /*#__PURE__*/_regenerator2.default.mark(watchSaveBackgroundColor),
    _marked47 = /*#__PURE__*/_regenerator2.default.mark(settingsSaga);

function getAccessToken(state) {
  return state.user.data.accessToken;
}

function getUserData(state) {
  return state.user.data;
}

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.saveUser, token, { newPassword: newPassword, password: currentPassword }, 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.saveUser, token, { newEmail: newEmail }, 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 onUserSave(options, action) {
  var token;
  return _regenerator2.default.wrap(function onUserSave$(_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.saveUser, token, action.data, options);

        case 6:
          _context3.next = 8;
          return (0, _effects.put)((0, _settings.saveUserSuccess)());

        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.saveUserError)(_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, thirdPartyAccounts, account;
  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.select)(function (state) {
            return state.user.data.thirdPartyAccounts;
          });

        case 7:
          thirdPartyAccounts = _context5.sent;
          account = thirdPartyAccounts.find(function (anAccount) {
            return anAccount.id === id;
          });
          _context5.next = 11;
          return (0, _effects.call)(_settingsApi2.default.deleteThirdParty, token, id, options);

        case 11:
          _context5.next = 13;
          return (0, _effects.put)((0, _settings.deleteThirdPartySuccess)(account));

        case 13:
          _context5.next = 15;
          return (0, _effects.put)((0, _actions.loadUser)());

        case 15:
          _context5.next = 21;
          break;

        case 17:
          _context5.prev = 17;
          _context5.t0 = _context5['catch'](0);
          _context5.next = 21;
          return (0, _effects.put)((0, _settings.deleteThirdPartyError)(_context5.t0));

        case 21:
        case 'end':
          return _context5.stop();
      }
    }
  }, _marked5, this, [[0, 17]]);
}

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 onSaveBranding(options, action) {
  var userData, token, data, branding;
  return _regenerator2.default.wrap(function onSaveBranding$(_context7) {
    while (1) {
      switch (_context7.prev = _context7.next) {
        case 0:
          _context7.prev = 0;
          _context7.next = 3;
          return (0, _effects.select)(getUserData);

        case 3:
          userData = _context7.sent;
          token = userData.accessToken;
          data = action.data;
          _context7.next = 8;
          return (0, _effects.call)(_settingsApi2.default.saveBranding, token, data, options);

        case 8:
          branding = _context7.sent;
          _context7.next = 11;
          return (0, _effects.put)((0, _settings.saveBrandingSuccess)(branding));

        case 11:
          _context7.next = 17;
          break;

        case 13:
          _context7.prev = 13;
          _context7.t0 = _context7['catch'](0);
          _context7.next = 17;
          return (0, _effects.put)((0, _settings.saveBrandingError)(_context7.t0));

        case 17:
        case 'end':
          return _context7.stop();
      }
    }
  }, _marked7, this, [[0, 13]]);
}

function onLogoUpload(options, action) {
  var _action$payload2, file, fileType, token, response;

  return _regenerator2.default.wrap(function onLogoUpload$(_context8) {
    while (1) {
      switch (_context8.prev = _context8.next) {
        case 0:
          _context8.prev = 0;
          _action$payload2 = action.payload, file = _action$payload2.file, fileType = _action$payload2.fileType;
          _context8.next = 4;
          return (0, _effects.select)(getAccessToken);

        case 4:
          token = _context8.sent;
          _context8.next = 7;
          return (0, _effects.call)(_settingsApi2.default.uploadLogo, token, file, fileType, options);

        case 7:
          response = _context8.sent;
          _context8.next = 10;
          return (0, _effects.put)((0, _settings.uploadLogoSuccess)(response));

        case 10:
          _context8.next = 16;
          break;

        case 12:
          _context8.prev = 12;
          _context8.t0 = _context8['catch'](0);
          _context8.next = 16;
          return (0, _effects.put)((0, _settings.uploadLogoError)(_context8.t0));

        case 16:
        case 'end':
          return _context8.stop();
      }
    }
  }, _marked8, this, [[0, 12]]);
}

function onLogoRemove(options) {
  var token;
  return _regenerator2.default.wrap(function onLogoRemove$(_context9) {
    while (1) {
      switch (_context9.prev = _context9.next) {
        case 0:
          _context9.prev = 0;
          _context9.next = 3;
          return (0, _effects.select)(getAccessToken);

        case 3:
          token = _context9.sent;
          _context9.next = 6;
          return (0, _effects.call)(_settingsApi2.default.removeLogo, token, options);

        case 6:
          _context9.next = 8;
          return (0, _effects.put)((0, _settings.removeLogoSuccess)());

        case 8:
          _context9.next = 14;
          break;

        case 10:
          _context9.prev = 10;
          _context9.t0 = _context9['catch'](0);
          _context9.next = 14;
          return (0, _effects.put)((0, _settings.removeLogoError)(_context9.t0));

        case 14:
        case 'end':
          return _context9.stop();
      }
    }
  }, _marked9, this, [[0, 10]]);
}

function onBackgroundUpload(options, action) {
  var _action$payload3, file, fileType, token, response;

  return _regenerator2.default.wrap(function onBackgroundUpload$(_context10) {
    while (1) {
      switch (_context10.prev = _context10.next) {
        case 0:
          _context10.prev = 0;
          _action$payload3 = action.payload, file = _action$payload3.file, fileType = _action$payload3.fileType;
          _context10.next = 4;
          return (0, _effects.select)(getAccessToken);

        case 4:
          token = _context10.sent;
          _context10.next = 7;
          return (0, _effects.call)(_settingsApi2.default.uploadBackground, token, file, fileType, options);

        case 7:
          response = _context10.sent;
          _context10.next = 10;
          return (0, _effects.put)((0, _settings.uploadBackgroundSuccess)(response));

        case 10:
          _context10.next = 16;
          break;

        case 12:
          _context10.prev = 12;
          _context10.t0 = _context10['catch'](0);
          _context10.next = 16;
          return (0, _effects.put)((0, _settings.uploadBackgroundError)(_context10.t0));

        case 16:
        case 'end':
          return _context10.stop();
      }
    }
  }, _marked10, this, [[0, 12]]);
}

function onBackgroundRemove(options) {
  var token;
  return _regenerator2.default.wrap(function onBackgroundRemove$(_context11) {
    while (1) {
      switch (_context11.prev = _context11.next) {
        case 0:
          _context11.prev = 0;
          _context11.next = 3;
          return (0, _effects.select)(getAccessToken);

        case 3:
          token = _context11.sent;
          _context11.next = 6;
          return (0, _effects.call)(_settingsApi2.default.removeBackground, token, options);

        case 6:
          _context11.next = 8;
          return (0, _effects.put)((0, _settings.removeBackgroundSuccess)());

        case 8:
          _context11.next = 14;
          break;

        case 10:
          _context11.prev = 10;
          _context11.t0 = _context11['catch'](0);
          _context11.next = 14;
          return (0, _effects.put)((0, _settings.removeBackgroundError)(_context11.t0));

        case 14:
        case 'end':
          return _context11.stop();
      }
    }
  }, _marked11, this, [[0, 10]]);
}

function onSaveTileBackground(options, action) {
  var userData, token, data, branding;
  return _regenerator2.default.wrap(function onSaveTileBackground$(_context12) {
    while (1) {
      switch (_context12.prev = _context12.next) {
        case 0:
          _context12.prev = 0;
          _context12.next = 3;
          return (0, _effects.select)(getUserData);

        case 3:
          userData = _context12.sent;
          token = userData.accessToken;
          data = action.data;
          _context12.next = 8;
          return (0, _effects.call)(_settingsApi2.default.saveBranding, token, data, options);

        case 8:
          branding = _context12.sent;
          _context12.next = 11;
          return (0, _effects.put)((0, _settings.saveTileBackgroundSuccess)(branding));

        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.saveTileBackgroundError)(_context12.t0));

        case 17:
        case 'end':
          return _context12.stop();
      }
    }
  }, _marked12, this, [[0, 13]]);
}

function onSaveBackgroundColor(options, action) {
  var userData, token, data, branding;
  return _regenerator2.default.wrap(function onSaveBackgroundColor$(_context13) {
    while (1) {
      switch (_context13.prev = _context13.next) {
        case 0:
          _context13.prev = 0;
          _context13.next = 3;
          return (0, _effects.select)(getUserData);

        case 3:
          userData = _context13.sent;
          token = userData.accessToken;
          data = action.data;
          _context13.next = 8;
          return (0, _effects.call)(_settingsApi2.default.saveBranding, token, data, options);

        case 8:
          branding = _context13.sent;
          _context13.next = 11;
          return (0, _effects.put)((0, _settings.saveBackgroundColorSuccess)(branding));

        case 11:
          _context13.next = 17;
          break;

        case 13:
          _context13.prev = 13;
          _context13.t0 = _context13['catch'](0);
          _context13.next = 17;
          return (0, _effects.put)((0, _settings.saveBackgroundColorError)(_context13.t0));

        case 17:
        case 'end':
          return _context13.stop();
      }
    }
  }, _marked13, this, [[0, 13]]);
}

function onLogout(options) {
  return _regenerator2.default.wrap(function onLogout$(_context14) {
    while (1) {
      switch (_context14.prev = _context14.next) {
        case 0:
          _context14.next = 2;
          return (0, _effects.put)((0, _settings.resetNags)());

        case 2:
        case 'end':
          return _context14.stop();
      }
    }
  }, _marked14, this);
}

function onDeleteCalendar(options, action) {
  var id, token, connectedCalendars, calendar;
  return _regenerator2.default.wrap(function onDeleteCalendar$(_context15) {
    while (1) {
      switch (_context15.prev = _context15.next) {
        case 0:
          _context15.prev = 0;
          id = action.id;
          _context15.next = 4;
          return (0, _effects.select)(function (state) {
            return state.user.data.accessToken;
          });

        case 4:
          token = _context15.sent;
          _context15.next = 7;
          return (0, _effects.select)(function (state) {
            return state.user.data.calendarAccounts;
          });

        case 7:
          connectedCalendars = _context15.sent;
          calendar = connectedCalendars.find(function (aCalendar) {
            return aCalendar.id === id;
          });
          _context15.next = 11;
          return (0, _effects.call)(_settingsApi2.default.deleteCalendar, token, id, options);

        case 11:
          _context15.next = 13;
          return (0, _effects.put)((0, _settings.deleteCalendarSuccess)(calendar));

        case 13:
          _context15.next = 15;
          return (0, _effects.put)((0, _actions.loadUser)());

        case 15:
          _context15.next = 21;
          break;

        case 17:
          _context15.prev = 17;
          _context15.t0 = _context15['catch'](0);
          _context15.next = 21;
          return (0, _effects.put)((0, _settings.deleteCalendarError)(_context15.t0));

        case 21:
        case 'end':
          return _context15.stop();
      }
    }
  }, _marked15, this, [[0, 17]]);
}

function onGetDoodleFeed(options) {
  var token, feed;
  return _regenerator2.default.wrap(function onGetDoodleFeed$(_context16) {
    while (1) {
      switch (_context16.prev = _context16.next) {
        case 0:
          _context16.prev = 0;
          _context16.next = 3;
          return (0, _effects.select)(function (state) {
            return state.user.data.accessToken;
          });

        case 3:
          token = _context16.sent;
          _context16.next = 6;
          return (0, _effects.call)(_settingsApi2.default.getDoodleFeed, token, options);

        case 6:
          feed = _context16.sent;
          _context16.next = 9;
          return (0, _effects.put)((0, _settings.getDoodleFeedSuccess)(feed.url));

        case 9:
          _context16.next = 15;
          break;

        case 11:
          _context16.prev = 11;
          _context16.t0 = _context16['catch'](0);
          _context16.next = 15;
          return (0, _effects.put)((0, _settings.getDoodleFeedError)(_context16.t0));

        case 15:
        case 'end':
          return _context16.stop();
      }
    }
  }, _marked16, this, [[0, 11]]);
}

function onConnectDoodleFeed(options, action) {
  var url, token;
  return _regenerator2.default.wrap(function onConnectDoodleFeed$(_context17) {
    while (1) {
      switch (_context17.prev = _context17.next) {
        case 0:
          _context17.prev = 0;
          url = action.url;
          _context17.next = 4;
          return (0, _effects.select)(function (state) {
            return state.user.data.accessToken;
          });

        case 4:
          token = _context17.sent;
          _context17.next = 7;
          return (0, _effects.call)(_settingsApi2.default.connectDoodleFeed, token, { url: url }, options);

        case 7:
          _context17.next = 9;
          return (0, _effects.put)((0, _settings.connectDoodleFeedSuccess)());

        case 9:
          _context17.next = 11;
          return (0, _effects.put)((0, _actions.loadUser)());

        case 11:
          _context17.next = 17;
          break;

        case 13:
          _context17.prev = 13;
          _context17.t0 = _context17['catch'](0);
          _context17.next = 17;
          return (0, _effects.put)((0, _settings.connectDoodleFeedError)(_context17.t0));

        case 17:
        case 'end':
          return _context17.stop();
      }
    }
  }, _marked17, this, [[0, 13]]);
}

function onResetDoodleFeed(options) {
  var token, feed;
  return _regenerator2.default.wrap(function onResetDoodleFeed$(_context18) {
    while (1) {
      switch (_context18.prev = _context18.next) {
        case 0:
          _context18.prev = 0;
          _context18.next = 3;
          return (0, _effects.select)(function (state) {
            return state.user.data.accessToken;
          });

        case 3:
          token = _context18.sent;
          _context18.next = 6;
          return (0, _effects.call)(_settingsApi2.default.resetDoodleFeed, token, options);

        case 6:
          feed = _context18.sent;
          _context18.next = 9;
          return (0, _effects.put)((0, _settings.resetDoodleFeedSuccess)(feed.url));

        case 9:
          _context18.next = 15;
          break;

        case 11:
          _context18.prev = 11;
          _context18.t0 = _context18['catch'](0);
          _context18.next = 15;
          return (0, _effects.put)((0, _settings.resetDoodleFeedError)(_context18.t0));

        case 15:
        case 'end':
          return _context18.stop();
      }
    }
  }, _marked18, this, [[0, 11]]);
}

function findAddressBookById(addressBooks, id) {
  var provider = void 0;
  var addressBook = void 0;

  for (var i = 0; i < addressBooks.length; i += 1) {
    provider = addressBooks[i];
    for (var j = 0; j < addressBooks.length; j += 1) {
      addressBook = provider.addressBooks[j];
      if (addressBook.id === id) {
        return _extends({
          accountType: provider.accountType
        }, addressBook);
      }
    }
  }
}

function onDeleteAddressBook(options, action) {
  var id, token, connectedBooks, addressBook;
  return _regenerator2.default.wrap(function onDeleteAddressBook$(_context19) {
    while (1) {
      switch (_context19.prev = _context19.next) {
        case 0:
          _context19.prev = 0;
          id = action.id;
          _context19.next = 4;
          return (0, _effects.select)(function (state) {
            return state.user.data.accessToken;
          });

        case 4:
          token = _context19.sent;
          _context19.next = 7;
          return (0, _effects.select)(function (state) {
            return state.user.data.addressBooks;
          });

        case 7:
          connectedBooks = _context19.sent;
          addressBook = findAddressBookById(connectedBooks, id);
          _context19.next = 11;
          return (0, _effects.call)(_settingsApi2.default.deleteAddressBook, token, id, options);

        case 11:
          _context19.next = 13;
          return (0, _effects.put)((0, _settings.deleteAddressBookSuccess)(addressBook));

        case 13:
          _context19.next = 15;
          return (0, _effects.put)((0, _actions.loadUser)());

        case 15:
          _context19.next = 21;
          break;

        case 17:
          _context19.prev = 17;
          _context19.t0 = _context19['catch'](0);
          _context19.next = 21;
          return (0, _effects.put)((0, _settings.deleteAddressBookError)(_context19.t0));

        case 21:
        case 'end':
          return _context19.stop();
      }
    }
  }, _marked19, this, [[0, 17]]);
}

function onLogoutApps(options) {
  var token;
  return _regenerator2.default.wrap(function onLogoutApps$(_context20) {
    while (1) {
      switch (_context20.prev = _context20.next) {
        case 0:
          _context20.prev = 0;
          _context20.next = 3;
          return (0, _effects.select)(function (state) {
            return state.user.data.accessToken;
          });

        case 3:
          token = _context20.sent;
          _context20.next = 6;
          return (0, _effects.call)(_settingsApi2.default.logoutApps, token, options);

        case 6:
          _context20.next = 8;
          return (0, _effects.put)((0, _settings.logoutAppsSuccess)());

        case 8:
          _context20.next = 10;
          return (0, _effects.put)((0, _actions.logout)());

        case 10:
          _context20.next = 16;
          break;

        case 12:
          _context20.prev = 12;
          _context20.t0 = _context20['catch'](0);
          _context20.next = 16;
          return (0, _effects.put)((0, _settings.logoutAppsError)(_context20.t0));

        case 16:
        case 'end':
          return _context20.stop();
      }
    }
  }, _marked20, this, [[0, 12]]);
}

function onGetApps(options) {
  var token, apps;
  return _regenerator2.default.wrap(function onGetApps$(_context21) {
    while (1) {
      switch (_context21.prev = _context21.next) {
        case 0:
          _context21.prev = 0;
          _context21.next = 3;
          return (0, _effects.select)(function (state) {
            return state.user.data.accessToken;
          });

        case 3:
          token = _context21.sent;
          _context21.next = 6;
          return (0, _effects.call)(_settingsApi2.default.getApps, token, options);

        case 6:
          apps = _context21.sent;
          _context21.next = 9;
          return (0, _effects.put)((0, _settings.getAppsSuccess)(apps));

        case 9:
          _context21.next = 15;
          break;

        case 11:
          _context21.prev = 11;
          _context21.t0 = _context21['catch'](0);
          _context21.next = 15;
          return (0, _effects.put)((0, _settings.getAppsError)(_context21.t0));

        case 15:
        case 'end':
          return _context21.stop();
      }
    }
  }, _marked21, this, [[0, 11]]);
}

function onSaveAvatar(options, action) {
  var _action$payload4, file, fileType, token;

  return _regenerator2.default.wrap(function onSaveAvatar$(_context22) {
    while (1) {
      switch (_context22.prev = _context22.next) {
        case 0:
          _context22.prev = 0;
          _action$payload4 = action.payload, file = _action$payload4.file, fileType = _action$payload4.fileType;
          _context22.next = 4;
          return (0, _effects.select)(function (state) {
            return state.user.data.accessToken;
          });

        case 4:
          token = _context22.sent;
          _context22.next = 7;
          return (0, _effects.call)(_settingsApi2.default.saveAvatar, token, file, fileType, options);

        case 7:
          _context22.next = 9;
          return (0, _effects.put)((0, _settings.saveAvatarSuccess)());

        case 9:
          _context22.next = 15;
          break;

        case 11:
          _context22.prev = 11;
          _context22.t0 = _context22['catch'](0);
          _context22.next = 15;
          return (0, _effects.put)((0, _settings.saveAvatarError)(_context22.t0));

        case 15:
        case 'end':
          return _context22.stop();
      }
    }
  }, _marked22, this, [[0, 11]]);
}

function onDeleteAvatar(options) {
  var token;
  return _regenerator2.default.wrap(function onDeleteAvatar$(_context23) {
    while (1) {
      switch (_context23.prev = _context23.next) {
        case 0:
          _context23.prev = 0;
          _context23.next = 3;
          return (0, _effects.select)(function (state) {
            return state.user.data.accessToken;
          });

        case 3:
          token = _context23.sent;
          _context23.next = 6;
          return (0, _effects.call)(_settingsApi2.default.deleteAvatar, token, options);

        case 6:
          _context23.next = 8;
          return (0, _effects.put)((0, _settings.deleteAvatarSuccess)());

        case 8:
          _context23.next = 14;
          break;

        case 10:
          _context23.prev = 10;
          _context23.t0 = _context23['catch'](0);
          _context23.next = 14;
          return (0, _effects.put)((0, _settings.deleteAvatarError)(_context23.t0));

        case 14:
        case 'end':
          return _context23.stop();
      }
    }
  }, _marked23, this, [[0, 10]]);
}

function watchSaveNewPassword(options) {
  return _regenerator2.default.wrap(function watchSaveNewPassword$(_context24) {
    while (1) {
      switch (_context24.prev = _context24.next) {
        case 0:
          _context24.next = 2;
          return (0, _effects.takeLatest)(_settings.SettingsActionTypes.SAVE_NEW_PASSWORD, onNewPasswordSave, options);

        case 2:
        case 'end':
          return _context24.stop();
      }
    }
  }, _marked24, this);
}

function watchSaveEmail(options) {
  return _regenerator2.default.wrap(function watchSaveEmail$(_context25) {
    while (1) {
      switch (_context25.prev = _context25.next) {
        case 0:
          _context25.next = 2;
          return (0, _effects.takeLatest)(_settings.SettingsActionTypes.SAVE_NEW_EMAIL, onNewEmailSave, options);

        case 2:
        case 'end':
          return _context25.stop();
      }
    }
  }, _marked25, this);
}

function watchSaveUser(options) {
  return _regenerator2.default.wrap(function watchSaveUser$(_context26) {
    while (1) {
      switch (_context26.prev = _context26.next) {
        case 0:
          _context26.next = 2;
          return (0, _effects.takeLatest)(_settings.SettingsActionTypes.SAVE_USER, onUserSave, options);

        case 2:
        case 'end':
          return _context26.stop();
      }
    }
  }, _marked26, this);
}

function watchDeleteAccount(options) {
  return _regenerator2.default.wrap(function watchDeleteAccount$(_context27) {
    while (1) {
      switch (_context27.prev = _context27.next) {
        case 0:
          _context27.next = 2;
          return (0, _effects.takeLatest)(_settings.SettingsActionTypes.DELETE_ACCOUNT, onAccountDelete, options);

        case 2:
        case 'end':
          return _context27.stop();
      }
    }
  }, _marked27, this);
}

function watchDeleteThirdParty(options) {
  return _regenerator2.default.wrap(function watchDeleteThirdParty$(_context28) {
    while (1) {
      switch (_context28.prev = _context28.next) {
        case 0:
          _context28.next = 2;
          return (0, _effects.takeLatest)(_settings.SettingsActionTypes.DELETE_THIRD_PARTY, onThirdPartyDelete, options);

        case 2:
        case 'end':
          return _context28.stop();
      }
    }
  }, _marked28, this);
}

function watchFetchPremiums(options) {
  return _regenerator2.default.wrap(function watchFetchPremiums$(_context29) {
    while (1) {
      switch (_context29.prev = _context29.next) {
        case 0:
          _context29.next = 2;
          return (0, _effects.takeLatest)(_settings.SettingsActionTypes.FETCH_PREMIUMS, onFetchPremiums, options);

        case 2:
        case 'end':
          return _context29.stop();
      }
    }
  }, _marked29, this);
}

function watchSaveBranding(options) {
  return _regenerator2.default.wrap(function watchSaveBranding$(_context30) {
    while (1) {
      switch (_context30.prev = _context30.next) {
        case 0:
          _context30.next = 2;
          return (0, _effects.takeLatest)(_settings.SettingsActionTypes.SAVE_BRANDING, onSaveBranding, options);

        case 2:
        case 'end':
          return _context30.stop();
      }
    }
  }, _marked30, this);
}

function watchLogoUpload(options) {
  return _regenerator2.default.wrap(function watchLogoUpload$(_context31) {
    while (1) {
      switch (_context31.prev = _context31.next) {
        case 0:
          _context31.next = 2;
          return (0, _effects.takeLatest)(_settings.SettingsActionTypes.UPLOAD_LOGO, onLogoUpload, options);

        case 2:
        case 'end':
          return _context31.stop();
      }
    }
  }, _marked31, this);
}

function watchLogoRemove(options) {
  return _regenerator2.default.wrap(function watchLogoRemove$(_context32) {
    while (1) {
      switch (_context32.prev = _context32.next) {
        case 0:
          _context32.next = 2;
          return (0, _effects.takeLatest)(_settings.SettingsActionTypes.REMOVE_LOGO, onLogoRemove, options);

        case 2:
        case 'end':
          return _context32.stop();
      }
    }
  }, _marked32, this);
}

function watchBackgroundUpload(options) {
  return _regenerator2.default.wrap(function watchBackgroundUpload$(_context33) {
    while (1) {
      switch (_context33.prev = _context33.next) {
        case 0:
          _context33.next = 2;
          return (0, _effects.takeLatest)(_settings.SettingsActionTypes.UPLOAD_BACKGROUND, onBackgroundUpload, options);

        case 2:
        case 'end':
          return _context33.stop();
      }
    }
  }, _marked33, this);
}

function watchBackgroundRemove(options) {
  return _regenerator2.default.wrap(function watchBackgroundRemove$(_context34) {
    while (1) {
      switch (_context34.prev = _context34.next) {
        case 0:
          _context34.next = 2;
          return (0, _effects.takeLatest)(_settings.SettingsActionTypes.REMOVE_BACKGROUND, onBackgroundRemove, options);

        case 2:
        case 'end':
          return _context34.stop();
      }
    }
  }, _marked34, this);
}

function watchLogout(options) {
  return _regenerator2.default.wrap(function watchLogout$(_context35) {
    while (1) {
      switch (_context35.prev = _context35.next) {
        case 0:
          _context35.next = 2;
          return (0, _effects.takeLatest)(_actions.ActionTypes.LOGOUT, onLogout, options);

        case 2:
        case 'end':
          return _context35.stop();
      }
    }
  }, _marked35, this);
}

function watchDeleteCalendar(options) {
  return _regenerator2.default.wrap(function watchDeleteCalendar$(_context36) {
    while (1) {
      switch (_context36.prev = _context36.next) {
        case 0:
          _context36.next = 2;
          return (0, _effects.takeLatest)(_settings.SettingsActionTypes.DELETE_CALENDAR, onDeleteCalendar, options);

        case 2:
        case 'end':
          return _context36.stop();
      }
    }
  }, _marked36, this);
}

function watchGetDoodleFeed(options) {
  return _regenerator2.default.wrap(function watchGetDoodleFeed$(_context37) {
    while (1) {
      switch (_context37.prev = _context37.next) {
        case 0:
          _context37.next = 2;
          return (0, _effects.takeLatest)(_settings.SettingsActionTypes.GET_DOODLE_FEED, onGetDoodleFeed, options);

        case 2:
        case 'end':
          return _context37.stop();
      }
    }
  }, _marked37, this);
}

function watchConnectDoodleFeed(options) {
  return _regenerator2.default.wrap(function watchConnectDoodleFeed$(_context38) {
    while (1) {
      switch (_context38.prev = _context38.next) {
        case 0:
          _context38.next = 2;
          return (0, _effects.takeLatest)(_settings.SettingsActionTypes.CONNECT_DOODLE_FEED, onConnectDoodleFeed, options);

        case 2:
        case 'end':
          return _context38.stop();
      }
    }
  }, _marked38, this);
}

function watchResetDoodleFeed(options) {
  return _regenerator2.default.wrap(function watchResetDoodleFeed$(_context39) {
    while (1) {
      switch (_context39.prev = _context39.next) {
        case 0:
          _context39.next = 2;
          return (0, _effects.takeLatest)(_settings.SettingsActionTypes.RESET_DOODLE_FEED, onResetDoodleFeed, options);

        case 2:
        case 'end':
          return _context39.stop();
      }
    }
  }, _marked39, this);
}

function watchDeleteAddressBook(options) {
  return _regenerator2.default.wrap(function watchDeleteAddressBook$(_context40) {
    while (1) {
      switch (_context40.prev = _context40.next) {
        case 0:
          _context40.next = 2;
          return (0, _effects.takeLatest)(_settings.SettingsActionTypes.DELETE_ADDRESS_BOOK, onDeleteAddressBook, options);

        case 2:
        case 'end':
          return _context40.stop();
      }
    }
  }, _marked40, this);
}

function watchLogoutApps(options) {
  return _regenerator2.default.wrap(function watchLogoutApps$(_context41) {
    while (1) {
      switch (_context41.prev = _context41.next) {
        case 0:
          _context41.next = 2;
          return (0, _effects.takeLatest)(_settings.SettingsActionTypes.LOGOUT_APPS, onLogoutApps, options);

        case 2:
        case 'end':
          return _context41.stop();
      }
    }
  }, _marked41, this);
}

function watchGetApps(options) {
  return _regenerator2.default.wrap(function watchGetApps$(_context42) {
    while (1) {
      switch (_context42.prev = _context42.next) {
        case 0:
          _context42.next = 2;
          return (0, _effects.takeLatest)(_settings.SettingsActionTypes.GET_APPS, onGetApps, options);

        case 2:
        case 'end':
          return _context42.stop();
      }
    }
  }, _marked42, this);
}

function watchSaveAvatar(options) {
  return _regenerator2.default.wrap(function watchSaveAvatar$(_context43) {
    while (1) {
      switch (_context43.prev = _context43.next) {
        case 0:
          _context43.next = 2;
          return (0, _effects.takeLatest)(_settings.SettingsActionTypes.SAVE_AVATAR, onSaveAvatar, options);

        case 2:
        case 'end':
          return _context43.stop();
      }
    }
  }, _marked43, this);
}

function watchDeleteAvatar(options) {
  return _regenerator2.default.wrap(function watchDeleteAvatar$(_context44) {
    while (1) {
      switch (_context44.prev = _context44.next) {
        case 0:
          _context44.next = 2;
          return (0, _effects.takeLatest)(_settings.SettingsActionTypes.DELETE_AVATAR, onDeleteAvatar, options);

        case 2:
        case 'end':
          return _context44.stop();
      }
    }
  }, _marked44, this);
}

function watchSaveTileBackground(options) {
  return _regenerator2.default.wrap(function watchSaveTileBackground$(_context45) {
    while (1) {
      switch (_context45.prev = _context45.next) {
        case 0:
          _context45.next = 2;
          return (0, _effects.takeLatest)(_settings.SettingsActionTypes.SAVE_TILE_BACKGROUND, onSaveTileBackground, options);

        case 2:
        case 'end':
          return _context45.stop();
      }
    }
  }, _marked45, this);
}

function watchSaveBackgroundColor(options) {
  return _regenerator2.default.wrap(function watchSaveBackgroundColor$(_context46) {
    while (1) {
      switch (_context46.prev = _context46.next) {
        case 0:
          _context46.next = 2;
          return (0, _effects.takeLatest)(_settings.SettingsActionTypes.SAVE_BACKGROUND_COLOR, onSaveBackgroundColor, options);

        case 2:
        case 'end':
          return _context46.stop();
      }
    }
  }, _marked46, this);
}

function settingsSaga() {
  var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
  return _regenerator2.default.wrap(function settingsSaga$(_context47) {
    while (1) {
      switch (_context47.prev = _context47.next) {
        case 0:
          _context47.next = 2;
          return (0, _effects.all)([(0, _effects.call)(watchSaveNewPassword, options), (0, _effects.call)(watchSaveUser, options), (0, _effects.call)(watchSaveEmail, options), (0, _effects.call)(watchDeleteAccount, options), (0, _effects.call)(watchDeleteThirdParty, options), (0, _effects.call)(watchFetchPremiums, options), (0, _effects.call)(watchSaveBranding, options), (0, _effects.call)(watchLogoUpload, options), (0, _effects.call)(watchLogoRemove, options), (0, _effects.call)(watchBackgroundUpload, options), (0, _effects.call)(watchBackgroundRemove, 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), (0, _effects.call)(watchSaveAvatar, options), (0, _effects.call)(watchDeleteAvatar, options), (0, _effects.call)(watchLogoutApps, options), (0, _effects.call)(watchGetApps, options), (0, _effects.call)(watchSaveTileBackground, options), (0, _effects.call)(watchSaveBackgroundColor, options)]);

        case 2:
        case 'end':
          return _context47.stop();
      }
    }
  }, _marked47, this);
}