#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() { ...@@ -121,6 +121,8 @@ export default function MyTasks() {
setAddFormStatus((prevState) => { return !prevState }) setAddFormStatus((prevState) => { return !prevState })
}, [addFormStatus]) }, [addFormStatus])
const createNewTaskHandler = useCallback(() => { const createNewTaskHandler = useCallback(() => {
const task = { const task = {
...newTask, ...newTask,
......
...@@ -33,4 +33,14 @@ export const FETCH_ALL_TASKS_BY_MEMBERSHIP_FAILURE = "FETCH_ALL_TASKS_BY_MEMBERS ...@@ -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 ACTIVATE_CREATE_COPY_TASKS_MODE = "ACTIVATE_CREATE_COPY_TASKS_MODE"
export const DEACTIVATE_CREATE_COPY_TASKS_MODE = "DEACTIVATE_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" export const SORT_TASKS = "SORT_TASKS"
\ No newline at end of file
...@@ -21,7 +21,9 @@ import { ...@@ -21,7 +21,9 @@ import {
FETCH_ALL_TASKS_BY_MEMBERSHIP_SUCCESS, FETCH_ALL_TASKS_BY_MEMBERSHIP_SUCCESS,
DEACTIVATE_CREATE_COPY_TASKS_MODE, DEACTIVATE_CREATE_COPY_TASKS_MODE,
ACTIVATE_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"; } from "../actionTypes/tasksTypes";
import axios from '../../axiosPlanner' import axios from '../../axiosPlanner'
...@@ -53,6 +55,25 @@ export const fetchCalendarTasks = (userId) => { ...@@ -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 = () => { export const fetchAllTasks = () => {
return async (dispatch) => { return async (dispatch) => {
......
...@@ -22,7 +22,10 @@ import { ...@@ -22,7 +22,10 @@ import {
FETCH_ALL_TASKS_BY_MEMBERSHIP_SUCCESS, FETCH_ALL_TASKS_BY_MEMBERSHIP_SUCCESS,
ACTIVATE_CREATE_COPY_TASKS_MODE, ACTIVATE_CREATE_COPY_TASKS_MODE,
DEACTIVATE_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"; } from "../actionTypes/tasksTypes";
const initialState = { const initialState = {
...@@ -168,6 +171,12 @@ const tasksReduсer = (state = initialState, action) => { ...@@ -168,6 +171,12 @@ const tasksReduсer = (state = initialState, action) => {
} }
} }
return { ...state, loading: false, sortedTasks: filteredTasks }; 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: default:
return state; 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