From bb6c7495eeb6891ec572e16bbf63e41b836c4e43 Mon Sep 17 00:00:00 2001 From: Dmytro Muzyka <47075277+Mich47@users.noreply.github.com> Date: Thu, 4 May 2023 21:52:51 +0300 Subject: [PATCH] added isLoading selector --- src/redux/auth/auth.selectors.js | 1 + src/redux/auth/auth.slice.js | 9 ++++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/redux/auth/auth.selectors.js b/src/redux/auth/auth.selectors.js index 2d4d085..be59ccd 100644 --- a/src/redux/auth/auth.selectors.js +++ b/src/redux/auth/auth.selectors.js @@ -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; diff --git a/src/redux/auth/auth.slice.js b/src/redux/auth/auth.slice.js index 62c3f94..acc3b23 100644 --- a/src/redux/auth/auth.slice.js +++ b/src/redux/auth/auth.slice.js @@ -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 => { @@ -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; }); },