From ab29ccbddc4d7a4b8d211e68fb360b428f53e541 Mon Sep 17 00:00:00 2001 From: gloginov Date: Fri, 27 Sep 2024 13:39:05 +0500 Subject: [PATCH] [SOK-16] *rename UserReducer to AuthReducer *rename methods in auth-reducer.ts -remove origin host from methods in auth-reducer.ts because base url set in backendApi --- packages/client/src/layouts/private-layout.tsx | 4 ++-- packages/client/src/pages/Profile/Profile.tsx | 2 +- packages/client/src/pages/SignIn/SignIn.tsx | 2 +- packages/client/src/pages/SignUp/SignUp.tsx | 2 +- packages/client/src/store/index.ts | 4 ++-- .../reducers/{user-reducer.ts => auth-reducer.ts} | 14 +++++++------- 6 files changed, 14 insertions(+), 14 deletions(-) rename packages/client/src/store/reducers/{user-reducer.ts => auth-reducer.ts} (87%) diff --git a/packages/client/src/layouts/private-layout.tsx b/packages/client/src/layouts/private-layout.tsx index 6b2091c..932c508 100644 --- a/packages/client/src/layouts/private-layout.tsx +++ b/packages/client/src/layouts/private-layout.tsx @@ -1,13 +1,13 @@ import { useSelector } from 'react-redux' import { Outlet } from 'react-router-dom' import { RootState } from '@/store' -import { getUser, UserType } from '@/store/reducers/user-reducer' +import { getUser, UserType } from '@/store/reducers/auth-reducer' import { useEffect } from 'react' import { useAppDispatch } from '@/store' export default function PrivateLayout() { // get user from store - const user = useSelector(state => state.UserReducer.user) + const user = useSelector(state => state.AuthReducer.user) const dispatch = useAppDispatch() useEffect(() => { diff --git a/packages/client/src/pages/Profile/Profile.tsx b/packages/client/src/pages/Profile/Profile.tsx index 84fd01e..f20e3d4 100644 --- a/packages/client/src/pages/Profile/Profile.tsx +++ b/packages/client/src/pages/Profile/Profile.tsx @@ -1,4 +1,4 @@ -import { logoutUser } from '@/store/reducers/user-reducer' +import { logoutUser } from '@/store/reducers/auth-reducer' import { useAppDispatch } from '@/store' export const Profile = () => { diff --git a/packages/client/src/pages/SignIn/SignIn.tsx b/packages/client/src/pages/SignIn/SignIn.tsx index dbc3c1b..292bea7 100644 --- a/packages/client/src/pages/SignIn/SignIn.tsx +++ b/packages/client/src/pages/SignIn/SignIn.tsx @@ -1,6 +1,6 @@ import { useState } from 'react' import { useAppDispatch } from '@/store' -import { signInUser } from '@/store/reducers/user-reducer' +import { signInUser } from '@/store/reducers/auth-reducer' import { Button } from '@/components/ui/Button/Button' import { useSearchParams } from 'react-router-dom' diff --git a/packages/client/src/pages/SignUp/SignUp.tsx b/packages/client/src/pages/SignUp/SignUp.tsx index 1ce849e..37d1bd5 100644 --- a/packages/client/src/pages/SignUp/SignUp.tsx +++ b/packages/client/src/pages/SignUp/SignUp.tsx @@ -1,5 +1,5 @@ import { useState } from 'react' -import { signUpUser } from '@/store/reducers/user-reducer' +import { signUpUser } from '@/store/reducers/auth-reducer' import { useAppDispatch } from '@/store' export const SignUp = () => { diff --git a/packages/client/src/store/index.ts b/packages/client/src/store/index.ts index 1af12dc..fff2154 100644 --- a/packages/client/src/store/index.ts +++ b/packages/client/src/store/index.ts @@ -1,11 +1,11 @@ import { configureStore } from '@reduxjs/toolkit' -import UserReducer from '@/store/reducers/user-reducer' +import AuthReducer from '@/store/reducers/auth-reducer' import { useDispatch } from 'react-redux' import { combineReducers } from '@reduxjs/toolkit' const rootReducer = combineReducers({ - UserReducer, + AuthReducer, }) export const store = configureStore({ reducer: rootReducer, diff --git a/packages/client/src/store/reducers/user-reducer.ts b/packages/client/src/store/reducers/auth-reducer.ts similarity index 87% rename from packages/client/src/store/reducers/user-reducer.ts rename to packages/client/src/store/reducers/auth-reducer.ts index 97c1219..402600a 100644 --- a/packages/client/src/store/reducers/user-reducer.ts +++ b/packages/client/src/store/reducers/auth-reducer.ts @@ -18,7 +18,7 @@ const initialState = { } const slice = createSlice({ - name: 'UserReducer', + name: 'AuthReducer', initialState, reducers: { setUser(state, actions) { @@ -27,13 +27,13 @@ const slice = createSlice({ }, }) -const UserReducer = slice.reducer +const AuthReducer = slice.reducer export const { actions } = slice export const getUser = () => async (dispatch: AppDispatch) => { await backendApi({ method: 'get', - url: `${import.meta.env.VITE_AUTH_URL}/auth/user`, + url: '/auth/user', }) .then((data: { data: UserType }) => { if (data) { @@ -48,7 +48,7 @@ export const getUser = () => async (dispatch: AppDispatch) => { export const logoutUser = () => async (dispatch: AppDispatch) => { await backendApi({ method: 'post', - url: `${import.meta.env.VITE_AUTH_URL}/auth/logout`, + url: '/auth/logout', }) .then(() => { dispatch(actions.setUser(null)) @@ -64,7 +64,7 @@ export const signInUser = (dispatch: AppDispatch) => { return backendApi({ method: 'post', - url: `${import.meta.env.VITE_AUTH_URL}/auth/signin`, + url: '/auth/signin', data: form, }) .then(data => { @@ -88,7 +88,7 @@ export const signUpUser = (form: { login: string; password: string }) => (dispatch: AppDispatch) => { backendApi({ method: 'post', - url: `${import.meta.env.VITE_AUTH_URL}/auth/signup`, + url: '/auth/signup', data: form, }) .then((data: { data: UserType }) => { @@ -103,4 +103,4 @@ export const signUpUser = } export type ActionsType = InferAppActions -export default UserReducer +export default AuthReducer