store.js
3.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
import Vue from 'vue'
import Vuex from 'vuex'
import createPersistedState from 'vuex-persistedstate'
Vue.use(Vuex)
export default new Vuex.Store({
strict: true,
plugins: [
createPersistedState()
],
state: {
token: null,
data: null,
isUserLoggedIn: false,
id: null,
role: null,
// schoolId: null,
schoolToken: null,
schoolRole: null,
studentsData: [],
activeStudent: {},
},
getters: {
GET_STUDENTS_DATA: state => {
return state.studentsData
},
GET_ACTIVE_STUDENT: state => {
return state.activeStudent
},
GET_TOKEN: state => {
return state.token
},
},
// serve as the one and only way to change the state of the data in the state object
mutations: {
RESET_STORE(state, defaultState) {
state = defaultState
// state.isUserLoggedIn = false
},
setToken(state, token) {
state.token = token
//state.isUserLoggedIn = !!(token)
if (token != null) {
state.isUserLoggedIn = true
} else {
state.isUserLoggedIn = false
state.isSchoolLoggedIn = false
}
},
setSchoolToken(state, schoolToken) {
state.schoolToken = schoolToken
//state.isUserLoggedIn = !!(token)
if (schoolToken != null) {
state.isSchoolLoggedIn = true
} else {
state.isSchoolLoggedIn = false
}
},
setUser(state, data) {
state.data = data
},
Id(state, id) {
state.id = id
},
Role(state, role) {
state.role = role
},
setSchoolRole(state, schoolRole) {
state.schoolRole = schoolRole
},
SET_STUDENTS_DATA(state, data) {
state.studentsData = data
},
SET_ACTIVE_STUDENT(state, data) {
state.activeStudent = data
},
// SchoolId(state, schoolId) {
// state.schoolId = schoolId
// }
},
//Action methods are referred to as being "dispatched"
actions: {
RESET_STORE({
commit
}, defaultState) {
commit('RESET_STORE', defaultState)
},
setToken({
commit
}, token) {
commit('setToken', token)
},
setSchoolToken({
commit
}, schoolToken) {
commit('setSchoolToken', schoolToken)
},
setUser({
commit
}, data) {
commit('setUser', data)
},
SET_STUDENTS_DATA({
commit
}, data) {
commit('SET_STUDENTS_DATA', data)
},
SET_ACTIVE_STUDENT({
commit
}, data) {
commit('SET_ACTIVE_STUDENT', data)
},
Id({
commit
}, id) {
commit('Id', id)
},
Role({
commit
}, role) {
commit('Role', role)
},
setSchoolRole({
commit
}, schoolRole) {
commit('setSchoolRole', schoolRole)
},
// SchoolId({ commit }, schoolId) {
// commit('SchoolId', schoolId)
// }
}
})