Skip to content

Commit

Permalink
added isLoading selector
Browse files Browse the repository at this point in the history
  • Loading branch information
Mich47 committed May 4, 2023
1 parent 6384852 commit bb6c749
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/redux/auth/auth.selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ export const selectUserPhone = state => state.auth.user.phone;
export const selectUserTelegram = state => state.auth.user.telegram;
export const selectUserAvatarURL = state => state.auth.user.avatarURL;
export const selectUserBirthday = state => state.auth.user.birthday;
export const selectIsLoading = state => state.auth.isLoading;
9 changes: 8 additions & 1 deletion src/redux/auth/auth.slice.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,19 @@ const authSlice = createSlice({
state.user = payload.user;
state.token = payload.token;
state.isLoggedIn = true;
state.error = null;
})
.addCase(authLogin.pending, state => {
state.isLoading = true;
})
.addCase(authLogin.fulfilled, (state, { payload }) => {
state.error = null;
state.isLoading = false;
state.user = payload.user;
state.token = payload.token;
})
.addCase(authLogin.rejected, (state, { payload }) => {
state.isLoading = false;
state.error = payload;
})
.addCase(authLogout.pending, state => {
Expand All @@ -56,13 +59,17 @@ const authSlice = createSlice({
})
.addCase(refreshUser.rejected, () => authInitState)

.addCase(userForm.pending, (state, _) => state)
.addCase(userForm.pending, (state, _) => {
state.isLoading = true;
})
.addCase(userForm.fulfilled, (state, { payload }) => {
state.isLoading = false;
state.error = null;
state.user = payload.user;
state.token = payload.token;
})
.addCase(userForm.rejected, (state, { payload }) => {
state.isLoading = false;
state.error = payload;
});
},
Expand Down

0 comments on commit bb6c749

Please sign in to comment.