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