47 lines
1.1 KiB
TypeScript
Raw Normal View History

import { OauthAppResponse } from 'app/services/api/oauth';
2019-12-07 13:28:52 +02:00
import { Action } from './actions';
export interface State {
2020-05-24 02:08:24 +03:00
available: Array<OauthAppResponse>;
2019-12-07 13:28:52 +02:00
}
const defaults: State = {
2020-05-24 02:08:24 +03:00
available: [],
};
export default function apps(state: State = defaults, action: Action): State {
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),
};
}
2020-05-24 02:08:24 +03:00
return state;
}