Skip to content

Commit

Permalink
[SOK-16]
Browse files Browse the repository at this point in the history
*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
  • Loading branch information
gloginov committed Sep 27, 2024
1 parent 442c996 commit ab29ccb
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 14 deletions.
4 changes: 2 additions & 2 deletions packages/client/src/layouts/private-layout.tsx
Original file line number Diff line number Diff line change
@@ -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<RootState, UserType>(state => state.UserReducer.user)
const user = useSelector<RootState, UserType>(state => state.AuthReducer.user)
const dispatch = useAppDispatch()

useEffect(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/pages/Profile/Profile.tsx
Original file line number Diff line number Diff line change
@@ -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 = () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/pages/SignIn/SignIn.tsx
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
2 changes: 1 addition & 1 deletion packages/client/src/pages/SignUp/SignUp.tsx
Original file line number Diff line number Diff line change
@@ -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 = () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/client/src/store/index.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const initialState = {
}

const slice = createSlice({
name: 'UserReducer',
name: 'AuthReducer',
initialState,
reducers: {
setUser(state, actions) {
Expand All @@ -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) {
Expand All @@ -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))
Expand All @@ -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 => {
Expand All @@ -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 }) => {
Expand All @@ -103,4 +103,4 @@ export const signUpUser =
}

export type ActionsType = InferAppActions<typeof actions>
export default UserReducer
export default AuthReducer

0 comments on commit ab29ccb

Please sign in to comment.