2018-03-26 00:46:45 +05:30
|
|
|
// @flow
|
|
|
|
import type { OauthAppResponse } from 'services/api/oauth';
|
2018-05-05 12:12:21 +05:30
|
|
|
import type { Action } from './actions';
|
2018-03-26 00:46:45 +05:30
|
|
|
|
|
|
|
export type Apps = {
|
|
|
|
+available: Array<OauthAppResponse>,
|
|
|
|
};
|
|
|
|
|
|
|
|
const defaults: Apps = {
|
|
|
|
available: [],
|
|
|
|
};
|
|
|
|
|
|
|
|
export default function apps(
|
|
|
|
state: Apps = defaults,
|
2018-05-05 12:12:21 +05:30
|
|
|
action: Action
|
2018-03-26 00:46:45 +05:30
|
|
|
) {
|
2018-05-05 12:12:21 +05:30
|
|
|
switch (action.type) {
|
|
|
|
case 'apps:setAvailable':
|
2018-03-26 00:46:45 +05:30
|
|
|
return {
|
|
|
|
...state,
|
2018-05-05 12:12:21 +05:30
|
|
|
available: action.payload,
|
2018-03-26 00:46:45 +05:30
|
|
|
};
|
|
|
|
|
2018-05-05 12:12:21 +05:30
|
|
|
case 'apps:addApp': {
|
|
|
|
const { payload } = action;
|
|
|
|
const available: Array<OauthAppResponse> = [...state.available];
|
|
|
|
let index = available.findIndex((app) => app.clientId === payload.clientId);
|
|
|
|
|
|
|
|
if (index === -1) {
|
|
|
|
index = available.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
available[index] = action.payload;
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
available
|
2018-03-26 00:46:45 +05:30
|
|
|
};
|
2018-05-05 12:12:21 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
case 'apps:deleteApp':
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
available: state.available.filter((app) => app.clientId !== action.payload),
|
|
|
|
};
|
|
|
|
|
|
|
|
default:
|
|
|
|
(action.type: empty);
|
|
|
|
|
|
|
|
return state;
|
2018-03-26 00:46:45 +05:30
|
|
|
}
|
|
|
|
}
|