Add nest endpoints and pages

This commit is contained in:
Matthew Penner 2020-12-31 17:27:16 -07:00
parent 359769244f
commit 6c85be72fa
12 changed files with 473 additions and 10 deletions

View file

@ -1,12 +1,15 @@
import { createContextStore } from 'easy-peasy';
import { composeWithDevTools } from 'redux-devtools-extension';
import nests, { AdminNestStore } from '@/state/admin/nests';
import roles, { AdminRoleStore } from '@/state/admin/roles';
interface AdminStore {
nests: AdminNestStore
roles: AdminRoleStore;
}
export const AdminContext = createContextStore<AdminStore>({
nests,
roles,
}, {
compose: composeWithDevTools({

View file

@ -0,0 +1,31 @@
import { action, Action } from 'easy-peasy';
import { Nest } from '@/api/admin/nests/getNests';
export interface AdminNestStore {
data: Nest[];
setNests: Action<AdminNestStore, Nest[]>;
appendNest: Action<AdminNestStore, Nest>;
removeNest: Action<AdminNestStore, number>;
}
const nests: AdminNestStore = {
data: [],
setNests: action((state, payload) => {
state.data = payload;
}),
appendNest: action((state, payload) => {
if (state.data.find(nest => nest.id === payload.id)) {
state.data = state.data.map(nest => nest.id === payload.id ? payload : nest);
} else {
state.data = [ ...state.data, payload ];
}
}),
removeNest: action((state, payload) => {
state.data = [ ...state.data.filter(nest => nest.id !== payload) ];
}),
};
export default nests;

View file

@ -16,8 +16,8 @@ const roles: AdminRoleStore = {
}),
appendRole: action((state, payload) => {
if (state.data.find(database => database.id === payload.id)) {
state.data = state.data.map(database => database.id === payload.id ? payload : database);
if (state.data.find(role => role.id === payload.id)) {
state.data = state.data.map(role => role.id === payload.id ? payload : role);
} else {
state.data = [ ...state.data, payload ];
}