-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathreducers.js
78 lines (74 loc) · 1.88 KB
/
reducers.js
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
import { createSlice } from '@reduxjs/toolkit';
const initialState = {
authenticated: false,
resetPasswordInitiate: false,
resetPasswordInvalid: false,
emailVerificationInitiate: false,
emailVerificationTokenState: null,
cookieConsent: false
};
const userSlice = createSlice({
name: 'user',
initialState,
reducers: {
authUser: (state, action) => {
const { user } = action.payload;
return {
...user,
authenticated: true
};
},
unauthUser: (state, action) => ({
authenticated: false
}),
authError: (state, action) => ({
authenticated: false
}),
resetPasswordInitiate: (state, action) => ({
...state,
resetPasswordInitiate: true
}),
resetPasswordReset: (state, action) => ({
...state,
resetPasswordInitiate: false
}),
invalidResetPasswordToken: (state, action) => ({
...state,
resetPasswordInvalid: true
}),
emailVerificationInitiate: (state, action) => ({
...state,
emailVerificationInitiate: true
}),
emailVerificationVerify: (state, action) => ({
...state,
emailVerificationTokenState: 'checking'
}),
emailVerificationVerified: (state, action) => ({
...state,
emailVerificationTokenState: 'verified'
}),
emailVerificationInvalid: (state, action) => ({
...state,
emailVerificationTokenState: 'invalid'
}),
settingsUpdated: (state, action) => ({
...state,
...action.payload.user
}),
apiKeyRemoved: (state, action) => ({
...state,
...action.payload.user
}),
apiKeyCreated: (state, action) => ({
...state,
...action.payload.user
}),
setCookieConsent: (state, action) => ({
...state,
cookieConsent: action.payload.cookieConsent
})
}
});
export const userActions = userSlice.actions;
export default userSlice.reducer;