Skip to content

Commit

Permalink
Merge pull request #20 from 001elijah/add-board-redux
Browse files Browse the repository at this point in the history
add boards slice getAll
  • Loading branch information
001elijah authored Jun 23, 2023
2 parents ff71cdf + b5c9897 commit 07984de
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/components/HeaderDashBoard/HeaderDashBoard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export const HeaderDashBoard = ({ title }) => {
</button>
{showModalWindow && (
<BackdropModal closeModal={handleModalWindowClose}>
<ModalFilter closeModal={handleModalWindowClose}
<ModalFilter
closeModal={handleModalWindowClose}
// color={setColor}
/>
</BackdropModal>
Expand Down
4 changes: 2 additions & 2 deletions src/components/ModalFilter/LabelBlock.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ InputBlock.propTypes = {
};

export const LabelBlock = ({ newField }) => {
console.log(newField)
console.log(newField);
const theme = useSelector(selectorTheme);
const [field, setField] = useState(' ');
console.log(field)
console.log(field);
const handleOnClick = e => {
setField(e.currentTarget.value);
};
Expand Down
2 changes: 1 addition & 1 deletion src/components/ModalFilter/ModalFilter.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useSelector } from 'react-redux';
import clsx from 'clsx';

export const ModalFilter = ({ closeModal, color }) => {
console.log(color)
console.log(color);
const [colorFilter, setColorFilter] = useState('');
const theme = useSelector(selectorTheme);

Expand Down
16 changes: 16 additions & 0 deletions src/redux/Boards/boardsOperations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { createAsyncThunk } from '@reduxjs/toolkit';

import { getListOfBoardsApi } from '../../services/backendAPI';

export const getListOfBoards = createAsyncThunk(
'boards/getListOfBoards',
async (_, { getState, rejectWithValue }) => {
const { token } = getState().auth;
try {
const boardsList = await getListOfBoardsApi(token);
return boardsList;
} catch (error) {
rejectWithValue(error.message);
}
},
);
1 change: 1 addition & 0 deletions src/redux/Boards/boardsSelectors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const selectBoards = state => state.boards;
14 changes: 14 additions & 0 deletions src/redux/Boards/boardsSlice.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createSlice } from '@reduxjs/toolkit';
import { getListOfBoards } from './boardsOperations';

const boardsSlice = createSlice({
name: 'boards',
initialState: [],
extraReducers: builder => {
builder.addCase(getListOfBoards.fulfilled, (state, { payload }) => {
state.boards = payload;
});
},
});

export default boardsSlice.reducer;
19 changes: 13 additions & 6 deletions src/services/backendAPI.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import axios from 'axios';

axios.defaults.baseURL = 'https://taskpro.onrender.com/user';
axios.defaults.baseURL = 'https://taskpro.onrender.com/';

const token = {
set(token) {
Expand All @@ -12,30 +12,37 @@ const token = {
};

export const registerUserApi = async userData => {
const { data } = await axios.post('/register', userData);
const { data } = await axios.post('user/register', userData);
token.set(data.token);
return { ...data.user, token: data.token };
};

export const loginUserApi = async userData => {
const { data } = await axios.post('/login', userData);
const { data } = await axios.post('user/login', userData);
token.set(data.token);
return { ...data.user, token: data.token };
};

export const currentUserApi = async userToken => {
token.set(userToken);
const { data } = await axios.get('/current');
const { data } = await axios.get('user/current');
return data;
};

export const logoutUserApi = async userToken => {
await axios.post('/logout', userToken);
await axios.post('user/logout', userToken);
token.unset();
return null;
};

export const themeChangeUserApi = async theme => {
const { data } = await axios.patch('', theme);
const { data } = await axios.patch('user/', theme);
return data;
};
//---------------------------------------------BOARDS---------------------//

export const getListOfCategoryApi = async userToken => {
token.set(userToken);
const { data } = await axios.get('/board/');
return data;
};

0 comments on commit 07984de

Please sign in to comment.