#167 added types , actions , cases to reducers for the redux on fetch_projects_non_watcher

parent df273c50
......@@ -121,6 +121,8 @@ export default function MyTasks() {
setAddFormStatus((prevState) => { return !prevState })
}, [addFormStatus])
const createNewTaskHandler = useCallback(() => {
const task = {
...newTask,
......
......@@ -33,4 +33,14 @@ export const FETCH_ALL_TASKS_BY_MEMBERSHIP_FAILURE = "FETCH_ALL_TASKS_BY_MEMBERS
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";
export const SORT_TASKS = "SORT_TASKS"
\ No newline at end of file
......@@ -21,7 +21,9 @@ import {
FETCH_ALL_TASKS_BY_MEMBERSHIP_SUCCESS,
DEACTIVATE_CREATE_COPY_TASKS_MODE,
ACTIVATE_CREATE_COPY_TASKS_MODE,
SORT_TASKS
SORT_TASKS,
FETCH_PROJECTS_NON_WATCHER_SUCCESS,
FETCH_PROJECTS_NON_WATCHER_FAILURE,
} from "../actionTypes/tasksTypes";
import axios from '../../axiosPlanner'
......@@ -53,6 +55,25 @@ 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) => {
......
......@@ -22,7 +22,10 @@ import {
FETCH_ALL_TASKS_BY_MEMBERSHIP_SUCCESS,
ACTIVATE_CREATE_COPY_TASKS_MODE,
DEACTIVATE_CREATE_COPY_TASKS_MODE,
SORT_TASKS
SORT_TASKS,
FETCH_PROJECTS_NON_WATCHER_SUCCESS,
FETCH_PROJECTS_NON_WATCHER_REQUEST,
FETCH_PROJECTS_NON_WATCHER_FAILURE,
} from "../actionTypes/tasksTypes";
const initialState = {
......@@ -168,6 +171,12 @@ 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