Commit d029fe4c authored by Ermolaev Timur's avatar Ermolaev Timur

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

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