mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-05-31 14:11:58 +05:30
Create app namespace for all absolute requires of app modules. Move all packages under packages yarn workspace
This commit is contained in:
50
packages/app/components/dev/apps/reducer.ts
Normal file
50
packages/app/components/dev/apps/reducer.ts
Normal file
@@ -0,0 +1,50 @@
|
||||
import { OauthAppResponse } from 'app/services/api/oauth';
|
||||
|
||||
import { Action } from './actions';
|
||||
|
||||
export interface Apps {
|
||||
available: OauthAppResponse[];
|
||||
}
|
||||
|
||||
const defaults: Apps = {
|
||||
available: [],
|
||||
};
|
||||
|
||||
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];
|
||||
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,
|
||||
),
|
||||
};
|
||||
|
||||
default:
|
||||
}
|
||||
|
||||
return state;
|
||||
}
|
Reference in New Issue
Block a user