#167 transfer all redux relatted operations for fetch_projects_non_watcher to the projects redux

parent 93761de7
......@@ -5,7 +5,7 @@ import MyTasksTableContainer from '../../components/MyTasksCompoments/MyTasksTab
import { activateCreateCopyTasksMode, fetchAllTasks, sortTaskByProjects, addTask, deleteTask, deleteDateTimeTask, editTask } from '../../store/actions/tasksActions';
import { shallowEqual, useDispatch, useSelector } from 'react-redux';
import { useCallback, useEffect, useState } from 'react';
import { fetchAllUserProjects, fetchProjects } from '../../store/actions/projectsActions';
import { fetchAllUserProjects, fetchProjects,fetchProjectsNonWatcherForTaskCreate } from '../../store/actions/projectsActions';
import moment from 'moment';
import { useNavigate } from 'react-router-dom';
......@@ -118,6 +118,7 @@ export default function MyTasks() {
dateTimeDeadLine: null
})
}
dispatch(fetchProjectsNonWatcherForTaskCreate(user.id))
setAddFormStatus((prevState) => { return !prevState })
}, [addFormStatus])
......
......@@ -19,4 +19,10 @@ export const DELETE_PROJECT_FAILURE = "DELETE_PROJECT_FAILURE";
export const CHANGE_MEMBER_ROLE_REQUEST = "CHANGE_MEMBER_ROLE_REQUEST";
export const CHANGE_MEMBER_ROLE_SUCCESS = "CHANGE_MEMBER_ROLE_SUCCESS";
export const CHANGE_MEMBER_ROLE_FAILURE = "CHANGE_MEMBER_ROLE_FAILURE";
\ No newline at end of file
export const CHANGE_MEMBER_ROLE_FAILURE = "CHANGE_MEMBER_ROLE_FAILURE";
export const FETCH_PROJECTS_NON_WATCHER_REQUEST = "FETCH_PROJECTS_NON_WATCHER_REQUEST";
export const FETCH_PROJECTS_NON_WATCHER_SUCCESS = "FETCH_PROJECTS_NON_WATCHER_SUCCESS";
export const FETCH_PROJECTS_NON_WATCHER_FAILURE = "FETCH_PROJECTS_NON_WATCHER_FAILURE";
......@@ -34,11 +34,6 @@ export const ACTIVATE_CREATE_COPY_TASKS_MODE = "ACTIVATE_CREATE_COPY_TASKS_MODE"
export const DEACTIVATE_CREATE_COPY_TASKS_MODE = "DEACTIVATE_CREATE_COPY_TASKS_MODE"
export const FETCH_PROJECTS_NON_WATCHER_REQUEST = "FETCH_PROJECTS_NON_WATCHER_REQUEST";
export const FETCH_PROJECTS_NON_WATCHER_SUCCESS = "FETCH_PROJECTS_NON_WATCHER_SUCCESS";
export const FETCH_PROJECTS_NON_WATCHER_FAILURE = "FETCH_PROJECTS_NON_WATCHER_FAILURE";
......
......@@ -164,3 +164,23 @@ export const changeMemberRole = (userId, data) => {
}
}
const fetchProjectsNonWatcherSuccess = (projects) => {
return { type: FETCH_PROJECTS_NON_WATCHER_SUCCESS, projects }
};
const fetchProjectsNonWatcherFailure = (error) => {
return { type: FETCH_PROJECTS_NON_WATCHER_FAILURE, error }
};
export const fetchProjectsNonWatcherForTaskCreate = (userId) => {
return async (dispatch) => {
dispatch(fetchCalendarTasksRequest());
try {
const response = await axios.get(`/projects/task_create/${userId}`);
dispatch(fetchProjectsNonWatcherSuccess(response.data.projects))
} catch (error) {
dispatch(fetchProjectsNonWatcherFailure(error.response.data));
}
}
};
\ No newline at end of file
......@@ -55,25 +55,7 @@ export const fetchCalendarTasks = (userId) => {
}
}
};
const fetchProjectsNonWatcherSuccess = (projects) => {
return { type: FETCH_PROJECTS_NON_WATCHER_SUCCESS, projects }
};
const fetchProjectsNonWatcherFailure = (error) => {
return { type: FETCH_PROJECTS_NON_WATCHER_FAILURE, error }
};
export const fetchProjectsForTaskCreate = (userId) => {
return async (dispatch) => {
dispatch(fetchCalendarTasksRequest());
try {
const response = await axios.get(`/projects/task_create/${userId}`);
dispatch(fetchProjectsNonWatcherSuccess(response.data.projects))
} catch (error) {
dispatch(fetchProjectsNonWatcherFailure(error.response.data));
}
}
};
export const fetchAllTasks = () => {
return async (dispatch) => {
......
import { CHANGE_MEMBER_ROLE_FAILURE, CHANGE_MEMBER_ROLE_REQUEST, CHANGE_MEMBER_ROLE_SUCCESS, DELETE_MEMBER_FAILURE, DELETE_MEMBER_REQUEST, DELETE_MEMBER_SUCCESS, DELETE_PROJECT_FAILURE, DELETE_PROJECT_REQUEST, DELETE_PROJECT_SUCCESS, FETCH_ALL_USER_PROJECTS_SUCCESS, FETCH_PROJECTS_ERROR, FETCH_PROJECTS_REQUEST, FETCH_PROJECTS_SUCCESS, FETCH_PROJECT_SUCCESS } from "../actionTypes/projectsActionTypes";
import { CHANGE_MEMBER_ROLE_FAILURE,
CHANGE_MEMBER_ROLE_REQUEST,
CHANGE_MEMBER_ROLE_SUCCESS,
DELETE_MEMBER_FAILURE,
DELETE_MEMBER_REQUEST,
DELETE_MEMBER_SUCCESS,
DELETE_PROJECT_FAILURE,
DELETE_PROJECT_REQUEST,
DELETE_PROJECT_SUCCESS,
FETCH_ALL_USER_PROJECTS_SUCCESS,
FETCH_PROJECTS_ERROR,
FETCH_PROJECTS_REQUEST,
FETCH_PROJECTS_SUCCESS,
FETCH_PROJECT_SUCCESS,
FETCH_PROJECTS_NON_WATCHER_REQUEST,
FETCH_PROJECTS_NON_WATCHER_SUCCESS,
FETCH_PROJECTS_NON_WATCHER_FAILURE
} from "../actionTypes/projectsActionTypes";
const initialState = {
allUserProjectsForModalTask: [],
......@@ -42,6 +59,12 @@ const projectsReducer = (state = initialState, action) => {
return { ...state, loading: true };
case CHANGE_MEMBER_ROLE_FAILURE:
return { ...state, loading: false, error: action.error };
case FETCH_PROJECTS_NON_WATCHER_REQUEST:
return { ...state, loading: true };
case FETCH_PROJECTS_NON_WATCHER_SUCCESS:
return { ...state, loading: false, allUserProjectsForModalTask: action.projects };
case FETCH_PROJECTS_NON_WATCHER_FAILURE:
return { ...state, loading: false, error: action.error };
default:
return state;
}
......
......@@ -23,9 +23,7 @@ import {
ACTIVATE_CREATE_COPY_TASKS_MODE,
DEACTIVATE_CREATE_COPY_TASKS_MODE,
SORT_TASKS,
FETCH_PROJECTS_NON_WATCHER_SUCCESS,
FETCH_PROJECTS_NON_WATCHER_REQUEST,
FETCH_PROJECTS_NON_WATCHER_FAILURE,
} from "../actionTypes/tasksTypes";
const initialState = {
......@@ -171,12 +169,7 @@ const tasksReduсer = (state = initialState, action) => {
}
}
return { ...state, loading: false, sortedTasks: filteredTasks };
case FETCH_PROJECTS_NON_WATCHER_REQUEST:
return { ...state, loading: true };
case FETCH_PROJECTS_NON_WATCHER_SUCCESS:
return { ...state, loading: false, projectsNonWatcher: action.projects };
case FETCH_PROJECTS_NON_WATCHER_FAILURE:
return { ...state, loading: false, error: action.error };
default:
return state;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment