2019-12-08 00:32:00 +05:30
|
|
|
import { OauthAppResponse } from 'app/services/api/oauth';
|
2019-06-30 19:02:50 +05:30
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
import { Action } from './actions';
|
2018-03-26 00:46:45 +05:30
|
|
|
|
2019-12-07 16:58:52 +05:30
|
|
|
export interface Apps {
|
2020-01-18 02:07:52 +05:30
|
|
|
available: Array<OauthAppResponse>;
|
2019-12-07 16:58:52 +05:30
|
|
|
}
|
2018-03-26 00:46:45 +05:30
|
|
|
|
|
|
|
const defaults: Apps = {
|
2019-11-27 14:33:32 +05:30
|
|
|
available: [],
|
2018-03-26 00:46:45 +05:30
|
|
|
};
|
|
|
|
|
2019-11-27 14:33:32 +05:30
|
|
|
export default function apps(state: Apps = defaults, action: Action): Apps {
|
|
|
|
switch (action.type) {
|
|
|
|
case 'apps:setAvailable':
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
available: action.payload,
|
|
|
|
};
|
|
|
|
|
|
|
|
case 'apps:addApp': {
|
|
|
|
const { payload } = action;
|
|
|
|
const available = [...state.available];
|
2020-05-20 22:05:52 +05:30
|
|
|
let index = available.findIndex(
|
|
|
|
(app) => app.clientId === payload.clientId,
|
|
|
|
);
|
2019-11-27 14:33:32 +05:30
|
|
|
|
|
|
|
if (index === -1) {
|
|
|
|
index = available.length;
|
|
|
|
}
|
|
|
|
|
|
|
|
available[index] = action.payload;
|
|
|
|
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
available,
|
|
|
|
};
|
2018-03-26 00:46:45 +05:30
|
|
|
}
|
2019-11-27 14:33:32 +05:30
|
|
|
|
|
|
|
case 'apps:deleteApp':
|
|
|
|
return {
|
|
|
|
...state,
|
|
|
|
available: state.available.filter(
|
2020-05-20 22:05:52 +05:30
|
|
|
(app) => app.clientId !== action.payload,
|
2019-11-27 14:33:32 +05:30
|
|
|
),
|
|
|
|
};
|
|
|
|
}
|
2019-12-07 16:58:52 +05:30
|
|
|
|
|
|
|
return state;
|
2018-03-26 00:46:45 +05:30
|
|
|
}
|