generated from Bjorn86/cra-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathslice.js
80 lines (75 loc) · 2.32 KB
/
slice.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
79
80
import { createSlice, createSelector } from '@reduxjs/toolkit';
import { userRegisters } from 'features/auth/register/model/user-registers';
import { userLogsOut } from 'features/auth/logout/model/user-logs-out';
import { userLogsIn } from 'features/auth/login/model/user-logs-in';
const initialState = {
userRegisters: {
isLoading: false,
error: null,
},
userLogsIn: {
isLoading: false,
error: null,
},
userLogsOut: {
isLoading: false,
error: null,
},
};
export const authSlice = createSlice({
name: '@@auth',
initialState,
reducers: {},
extraReducers: (builder) => {
builder.addCase(userRegisters.pending, (state) => {
state.userRegisters.isLoading = true;
state.userRegisters.error = null;
});
builder.addCase(userRegisters.rejected, (state, action) => {
state.userRegisters.isLoading = false;
state.userRegisters.error = action.payload || action.meta.error;
});
builder.addCase(userRegisters.fulfilled, (state) => {
state.userRegisters.isLoading = false;
});
builder.addCase(userLogsIn.pending, (state) => {
state.userLogsIn.isLoading = true;
state.userLogsIn.error = null;
});
builder.addCase(userLogsIn.rejected, (state, action) => {
state.userLogsIn.isLoading = false;
state.userLogsIn.error = action.payload || action.meta.error;
});
builder.addCase(userLogsIn.fulfilled, (state) => {
state.userLogsIn.isLoading = false;
});
builder.addCase(userLogsOut.pending, (state) => {
state.userLogsOut.isLoading = true;
state.userLogsOut.error = null;
});
builder.addCase(userLogsOut.rejected, (state, action) => {
state.userLogsOut.isLoading = false;
state.userLogsOut.error = action.payload || action.meta.error;
});
builder.addCase(userLogsOut.fulfilled, (state) => {
state.userLogsOut.isLoading = false;
});
},
});
export const authReducer = authSlice.reducer;
export const selectRegisterInfo = createSelector(
(state) => state.auth.userRegisters.isLoading,
(state) => state.auth.userRegisters.error,
(isLoading, error) => ({
isLoading,
error,
}),
);
export const selectLoginInfo = createSelector(
(state) => state.auth.userLogsIn.isLoading,
(state) => state.auth.userLogsIn.error,
(isLoading, error) => ({
isLoading,
error,
}),
);