2016-02-13 20:58:47 +05:30
|
|
|
import { combineReducers } from 'redux';
|
|
|
|
|
2016-11-13 02:01:44 +05:30
|
|
|
import {
|
|
|
|
ERROR,
|
|
|
|
SET_CLIENT,
|
|
|
|
SET_OAUTH,
|
|
|
|
SET_OAUTH_RESULT,
|
|
|
|
SET_SCOPES,
|
|
|
|
SET_LOADING_STATE,
|
|
|
|
REQUIRE_PERMISSIONS_ACCEPT,
|
2016-11-13 20:17:56 +05:30
|
|
|
SET_LOGIN,
|
|
|
|
SET_SWITCHER
|
2016-11-13 02:01:44 +05:30
|
|
|
} from './actions';
|
2016-02-13 20:58:47 +05:30
|
|
|
|
|
|
|
export default combineReducers({
|
2016-11-13 02:01:44 +05:30
|
|
|
login,
|
2016-02-23 11:27:16 +05:30
|
|
|
error,
|
2016-04-02 16:28:54 +05:30
|
|
|
isLoading,
|
2016-11-13 20:17:56 +05:30
|
|
|
isSwitcherEnabled,
|
2016-02-27 16:23:58 +05:30
|
|
|
client,
|
2016-02-29 23:46:33 +05:30
|
|
|
oauth,
|
|
|
|
scopes
|
2016-02-13 20:58:47 +05:30
|
|
|
});
|
|
|
|
|
|
|
|
function error(
|
|
|
|
state = null,
|
|
|
|
{type, payload = null, error = false}
|
|
|
|
) {
|
|
|
|
switch (type) {
|
|
|
|
case ERROR:
|
|
|
|
if (!error) {
|
|
|
|
throw new Error('Expected payload with error');
|
|
|
|
}
|
2016-11-13 02:01:44 +05:30
|
|
|
|
|
|
|
return payload;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function login(
|
|
|
|
state = null,
|
|
|
|
{type, payload = null}
|
|
|
|
) {
|
|
|
|
switch (type) {
|
|
|
|
case SET_LOGIN:
|
|
|
|
if (payload !== null && typeof payload !== 'string') {
|
|
|
|
throw new Error('Expected payload with login string or null');
|
|
|
|
}
|
|
|
|
|
2016-02-13 20:58:47 +05:30
|
|
|
return payload;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
2016-02-23 11:27:16 +05:30
|
|
|
|
2016-11-13 20:17:56 +05:30
|
|
|
function isSwitcherEnabled(
|
|
|
|
state = true,
|
|
|
|
{type, payload = false}
|
|
|
|
) {
|
|
|
|
switch (type) {
|
|
|
|
case SET_SWITCHER:
|
|
|
|
if (typeof payload !== 'boolean') {
|
|
|
|
throw new Error('Expected payload of boolean type');
|
|
|
|
}
|
|
|
|
|
|
|
|
return payload;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
2016-04-02 16:28:54 +05:30
|
|
|
|
|
|
|
function isLoading(
|
|
|
|
state = false,
|
|
|
|
{type, payload = null}
|
|
|
|
) {
|
|
|
|
switch (type) {
|
|
|
|
case SET_LOADING_STATE:
|
|
|
|
return !!payload;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-02-23 11:27:16 +05:30
|
|
|
function client(
|
|
|
|
state = null,
|
|
|
|
{type, payload = {}}
|
|
|
|
) {
|
|
|
|
switch (type) {
|
|
|
|
case SET_CLIENT:
|
|
|
|
return {
|
|
|
|
id: payload.id,
|
|
|
|
name: payload.name,
|
|
|
|
description: payload.description
|
|
|
|
};
|
|
|
|
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
2016-02-27 16:23:58 +05:30
|
|
|
|
|
|
|
function oauth(
|
|
|
|
state = null,
|
|
|
|
{type, payload = {}}
|
|
|
|
) {
|
|
|
|
switch (type) {
|
|
|
|
case SET_OAUTH:
|
|
|
|
return {
|
|
|
|
clientId: payload.clientId,
|
|
|
|
redirectUrl: payload.redirectUrl,
|
|
|
|
responseType: payload.responseType,
|
|
|
|
scope: payload.scope,
|
2016-11-19 20:11:15 +05:30
|
|
|
prompt: payload.prompt,
|
|
|
|
loginHint: payload.loginHint,
|
2016-02-27 16:23:58 +05:30
|
|
|
state: payload.state
|
|
|
|
};
|
|
|
|
|
2016-03-15 12:06:13 +05:30
|
|
|
case SET_OAUTH_RESULT:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
success: payload.success,
|
|
|
|
code: payload.code,
|
|
|
|
displayCode: payload.displayCode
|
|
|
|
};
|
|
|
|
|
2016-04-15 01:24:35 +05:30
|
|
|
case REQUIRE_PERMISSIONS_ACCEPT:
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
acceptRequired: true
|
|
|
|
};
|
|
|
|
|
2016-02-27 16:23:58 +05:30
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|
2016-02-29 23:46:33 +05:30
|
|
|
|
|
|
|
function scopes(
|
|
|
|
state = [],
|
|
|
|
{type, payload = []}
|
|
|
|
) {
|
|
|
|
switch (type) {
|
|
|
|
case SET_SCOPES:
|
|
|
|
return payload;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
}
|