Plop user data into the store when loading up the base component

This commit is contained in:
Dane Everitt 2019-06-22 17:07:28 -07:00
parent 328347fab7
commit e20a768182
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
5 changed files with 87 additions and 28 deletions

View file

@ -1,16 +1,11 @@
import { action, createStore } from 'easy-peasy';
import { createStore } from 'easy-peasy';
import { ApplicationState } from '@/state/types';
import flashes from '@/state/models/flashes';
import user from '@/state/models/user';
const state: ApplicationState = {
flashes: {
items: [],
addFlash: action((state, payload) => {
state.items.push(payload);
}),
clearFlashes: action(state => {
state.items = [];
}),
},
flashes,
user,
};
export const store = createStore(state);

View file

@ -0,0 +1,14 @@
import { action } from 'easy-peasy';
import { FlashState } from '@/state/types';
const flashes: FlashState = {
items: [],
addFlash: action((state, payload) => {
state.items.push(payload);
}),
clearFlashes: action(state => {
state.items = [];
}),
};
export default flashes;

View file

@ -0,0 +1,11 @@
import { UserState } from '@/state/types';
import { action } from 'easy-peasy';
const user: UserState = {
data: undefined,
setUserData: action((state, payload) => {
state.data = payload;
}),
};
export default user;

View file

@ -3,6 +3,7 @@ import { Action } from 'easy-peasy';
export interface ApplicationState {
flashes: FlashState;
user: UserState;
}
export interface FlashState {
@ -11,6 +12,22 @@ export interface FlashState {
clearFlashes: Action<FlashState>;
}
export interface UserState {
data?: UserData;
setUserData: Action<UserState, UserData>;
}
export interface UserData {
uuid: string;
username: string;
email: string;
language: string;
rootAdmin: boolean;
useTotp: boolean;
createdAt: Date;
updatedAt: Date;
}
export interface FlashMessage {
id?: string;
type: FlashMessageType;