Commit d029fe4c authored by Ermolaev Timur's avatar Ermolaev Timur

#103 сделал отображение только своих задач

parent 8f1aa7fe
......@@ -17,13 +17,15 @@ function MonthCalendar() {
const [currentTask, setCurrentTask] = useState({ title: '', description: '', priority: null, infoForCell: { startHour: null, endHour: null } })
const [copyTask, setCopyTask] = useState(null)
const [cellSizes, setCellSizes] = useState({})
const [userId, setUserId] = useState('')
useEffect(() => {
setDateNow({
month: new Date().getMonth(),
year: new Date().getFullYear(),
})
dispatch(fetchCalendarTasks())
setUserId(user.id)
dispatch(fetchCalendarTasks(user.id))
}, [dispatch])
......@@ -66,6 +68,7 @@ function MonthCalendar() {
return { ...prevState, month: prevState.month + 1 }
})
}, [])
const decrementMonth = useCallback(() => {
setDateNow((prevState) => {
if (prevState.month - 1 === -1) {
......@@ -137,13 +140,12 @@ function MonthCalendar() {
const start = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, hour, 0))
const newTask = {
...currentTask,
dateTimeTaskId: currentTask.id,
dateTimeStart: start,
dateTimeDue: due
}
delete newTask.id
delete newTask.infoForCell
await dispatch(editCalendarTask(newTask))
await dispatch(editCalendarTask(newTask, currentTask.id, userId))
setCurrentTask({})
}
......@@ -161,7 +163,7 @@ function MonthCalendar() {
taskId: currentTask.mainTaskId
}
delete newTask.infoForCell
await dispatch(editCalendarTask(newTask, currentTask.id))
await dispatch(editCalendarTask(newTask, currentTask.id, userId))
} else {
const newTask = {
...currentTask,
......@@ -172,7 +174,7 @@ function MonthCalendar() {
}
delete newTask.infoForCell
delete newTask.id
await dispatch(addCalendarTask(newTask))
await dispatch(addCalendarTask(newTask, userId))
}
}
......@@ -194,12 +196,12 @@ function MonthCalendar() {
}
delete newTask.infoForCell
delete newTask.id
await dispatch(addCopyCalendarTask(newTask))
await dispatch(addCopyCalendarTask(newTask, userId))
setCopyTask(null)
}
const deleteTaskHandler = async (taskId) => {
dispatch(deleteCalendarTask(taskId))
dispatch(deleteCalendarTask(taskId, userId))
}
return (
......
......@@ -19,7 +19,7 @@ function WeekCalendar() {
const month = new Date().getMonth()
const currentDay = moment().date()
setDate({ year: year, month: month, currentDay: currentDay })
dispatch(fetchCalendarTasks())
// dispatch(fetchCalendarTasks())
}, [])
const hoursInDay = useMemo(() => {
......
......@@ -38,11 +38,11 @@ const fetchCalendarTasksFailure = (error) => {
return {type: FETCH_CALENDAR_TASKS_FAILURE, error}
};
export const fetchCalendarTasks = () => {
export const fetchCalendarTasks = (userId) => {
return async (dispatch) => {
dispatch(fetchCalendarTasksRequest());
try {
const response = await axios.get("/tasks");
const response = await axios.get(`/tasks/user/${userId}`);
dispatch(fetchCalendarTasksSuccess(response.data.tasks))
} catch (error) {
dispatch(fetchCalendarTasksFailure(error.response.data));
......@@ -73,26 +73,26 @@ const addTaskFailure = (error) => {
return {type: ADD_NEW_TASK_FAILURE, error}
};
export const addCalendarTask = (task) => {
export const addCalendarTask = (task, userId) => {
return async (dispatch) => {
dispatch(addTaskRequest());
try {
await axios.post("/tasks", task);
dispatch(addTaskSuccess())
dispatch(fetchCalendarTasks())
dispatch(fetchCalendarTasks(userId))
} catch (error) {
dispatch(addTaskFailure(error.response.data));
}
}
}
export const addCopyCalendarTask = (task) => {
export const addCopyCalendarTask = (task, userId) => {
return async (dispatch) => {
dispatch(addTaskRequest());
try {
await axios.post("/copy-tasks/make-copy", task);
dispatch(addTaskSuccess())
dispatch(fetchCalendarTasks())
dispatch(fetchCalendarTasks(userId))
} catch (error) {
dispatch(addTaskFailure(error.response.data));
}
......@@ -137,13 +137,14 @@ export const editTask = (task) => {
}
}
export const editCalendarTask = (task, taskId) => {
export const editCalendarTask = (task, taskId, userId) => {
return async (dispatch) => {
dispatch(editTaskRequest());
try {
await axios.put(`/copy-tasks/change-copy/${taskId}`, task);
const response = await axios.put(`/copy-tasks/change-copy/${taskId}`, task);
console.log(response.data)
dispatch(editTaskSuccess())
dispatch(fetchCalendarTasks())
dispatch(fetchCalendarTasks(userId))
} catch (error) {
dispatch(editTaskFailure(error.response.data));
}
......@@ -175,13 +176,13 @@ export const deleteTask = (taskId) => {
}
}
export const deleteCalendarTask = (taskId) => {
export const deleteCalendarTask = (taskId, userId) => {
return async (dispatch) => {
dispatch(deleteTaskRequest());
try {
await axios.delete(`/copy-tasks/${taskId}`);
dispatch(deleteTaskSuccess())
dispatch(fetchCalendarTasks())
dispatch(fetchCalendarTasks(userId))
} catch (error) {
dispatch(deleteTaskFailure(error.response.data));
}
......
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