Commit c8d15d28 authored by Ermolaev Timur's avatar Ermolaev Timur

Merge branch 'task-78-fix/fix_logic_calendar_tasks' into 'development'

Task 78 fix/fix logic calendar tasks

See merge request !55
parents b25cde8e 40be6358
......@@ -28,38 +28,38 @@ const taskFinderById = async (taskId:string):Promise<null | Task>=>{
}
/** make copy of task in calendar view */
router.post("/make-copy",authAuthorOrExecutorOfTask, async(req:Request, res:Response):Promise<Response>=>{
const {executorStatus,taskId,start, due} = req.body
if (executorStatus){
router.post("/make-copy", async(req:Request, res:Response):Promise<Response>=>{
const {taskId, dateTimeDue, dateTimeStart} = req.body
const newDateTimeTask = new DateTimeTask();
newDateTimeTask.dateTimeStart = start
newDateTimeTask.dateTimeDue = due
newDateTimeTask.dateTimeStart = dateTimeStart
newDateTimeTask.dateTimeDue = dateTimeDue
newDateTimeTask.task = taskId
await newDateTimeTask.save()
const task = taskFinderById(taskId)
return res.send({task})
}
return res.send({message :"Something wrong in make-copy router"})
} )
/** change date time of copy of task in calendar view */
router.put("change-copy", authAuthorOrExecutorOfTask, async(req:Request, res: Response):Promise<Response>=>{
const {executorStatus,dateTimeTaskId,taskId, start, due} = req.body
if (executorStatus){
router.put("/change-copy", authAuthorOrExecutorOfTask, async(req:Request, res: Response):Promise<Response>=>{
const {dateTimeTaskId, taskId, dateTimeStart, dateTimeDue, description, title, priority} = req.body
const dateTimeTask = await dataSource
.createQueryBuilder()
.select('dateTikeTask')
.select('dateTimeTask')
.from(DateTimeTask,'dateTimeTask')
.where("dateTimeTask.id = :dateTimeTaskId",{dateTimeTaskId})
.getOne()
if(!dateTimeTask) return res.send({message:"such dateTimeTask does not exists"})
dateTimeTask.dateTimeStart=start
dateTimeTask.dateTimeDue=due
dateTimeTask.dateTimeStart=dateTimeStart
dateTimeTask.dateTimeDue=dateTimeDue
await dateTimeTask.save()
const task = taskFinderById(taskId)
const task = await taskFinderById(taskId)
if (!task) return res.status(404).send({Message:'task not found'})
task.title = title;
task.description = description;
task.priority = priority;
await task.save()
return res.send({task})
}
return res.send({message :"Something wrong in make-copy router"})
})
/**delete copyTask by dateTimeTaskId */
......
......@@ -8,7 +8,7 @@ const CalendarStandartCell = ({children, xs, hours, dayNumber, createTaskInCell
const [isThisCell, setIsThisCell] = useState(false)
const cellClass = {
position: 'relative',
height: linesInDay?.length ? `${40*linesInDay.length+35}px` : `${35+35}px`,
height: linesInDay?.length ? `${40*linesInDay.length+35}px` : `${35}px`,
borderRight: '1px solid black',
}
useEffect(()=>{
......
......@@ -3,11 +3,12 @@ import { useDispatch, useSelector } from 'react-redux';
import MonthCalendarBody from '../../components/MonthCalendarBody/MonthCalendarBody';
import MonthCalendarHeader from '../../components/MonthCalendarHeader/MonthCalendarHeader';
import { dateToISOLikeButLocal, getCurrentMonthString, getDaysInMonth } from '../../helpers/CalendarHelpers';
import { addCalendarTask, deleteCalendarTask, editCalendarTask, fetchCalendarTasks} from '../../store/actions/tasksActions';
import { addCalendarTask, addCopyCalendarTask, deleteCalendarTask, editCalendarTask, fetchCalendarTasks} from '../../store/actions/tasksActions';
function MonthCalendar() {
const dispatch = useDispatch();
const { calendarTasks } = useSelector(state => state.tasks);
const user = useSelector(state => state.users?.user);
const [hourFormat, setHourFormat] = useState(false);
const [dateNow, setDateNow] = useState({month: '', year: ''})
......@@ -65,7 +66,6 @@ function MonthCalendar() {
return {...prevState, month: prevState.month + 1}
})
}, [])
console.log(currentTask)
const decrementMonth = useCallback(() => {
setDateNow((prevState)=>{
if (prevState.month - 1 === -1) {
......@@ -135,13 +135,15 @@ function MonthCalendar() {
due = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, hour + hourDiff, 59))
}
const start = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, hour, 0))
const newObj = {
const newTask = {
...currentTask,
dateTimeTaskId: currentTask.id,
dateTimeStart: start,
dateTimeDue: due
}
delete newObj.infoForCell
await dispatch(editCalendarTask(newObj))
delete newTask.id
delete newTask.infoForCell
await dispatch(editCalendarTask(newTask))
setCurrentTask({})
}
......@@ -151,15 +153,26 @@ function MonthCalendar() {
const day = currentTask.infoForCell.startDay
const due = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, day, timeEndHour - 1, 59))
const start = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, day, timeStartHour, 0))
if (currentTask.id) {
const newTask = {
...currentTask,
dateTimeStart: start,
dateTimeDue: due
dateTimeDue: due,
dateTimeTaskId: currentTask.id,
taskId: currentTask.mainTaskId
}
delete newTask.infoForCell
if (currentTask.id) {
delete newTask.id
await dispatch(editCalendarTask(newTask))
} else {
const newTask = {
...currentTask,
dateTimeStart: start,
dateTimeDue: due,
executor: user,
}
delete newTask.infoForCell
delete newTask.id
await dispatch(addCalendarTask(newTask))
}
}
......@@ -178,10 +191,11 @@ function MonthCalendar() {
...copyTask,
dateTimeStart: start,
dateTimeDue: due,
taskId: copyTask.mainTaskId
}
delete newTask.infoForCell
delete newTask.id
await dispatch(addCalendarTask(newTask))
await dispatch(addCopyCalendarTask(newTask))
setCopyTask(null)
}
......
......@@ -71,10 +71,23 @@ const addTaskFailure = (error) => {
};
export const addCalendarTask = (task) => {
return async (dispatch, getState) => {
return async (dispatch) => {
dispatch(addTaskRequest());
try {
await axios.post("/tasks", task);
const response = await axios.post("/tasks", task);
dispatch(addTaskSuccess())
dispatch(fetchCalendarTasks())
} catch (error) {
dispatch(addTaskFailure(error.response.data));
}
}
}
export const addCopyCalendarTask = (task) => {
return async (dispatch) => {
dispatch(addTaskRequest());
try {
const response = await axios.post("/copy-tasks/make-copy", task);
dispatch(addTaskSuccess())
dispatch(fetchCalendarTasks())
} catch (error) {
......@@ -84,7 +97,7 @@ export const addCalendarTask = (task) => {
}
export const addTask = (task) => {
return async (dispatch, getState) => {
return async (dispatch) => {
dispatch(addTaskRequest());
try {
await axios.post("/tasks", task);
......@@ -109,7 +122,7 @@ const editTaskFailure = (error) => {
};
export const editTask = (task) => {
return async (dispatch, getState) => {
return async (dispatch) => {
dispatch(editTaskRequest());
try {
await axios.put("/tasks", task);
......@@ -122,10 +135,10 @@ export const editTask = (task) => {
}
export const editCalendarTask = (task) => {
return async (dispatch, getState) => {
return async (dispatch) => {
dispatch(editTaskRequest());
try {
await axios.put("/tasks", task);
await axios.put("/copy-tasks/change-copy", task);
dispatch(editTaskSuccess())
dispatch(fetchCalendarTasks())
} catch (error) {
......@@ -147,7 +160,7 @@ const deleteTaskFailure = (error) => {
};
export const deleteTask = (taskId) => {
return async (dispatch, getState) => {
return async (dispatch) => {
dispatch(deleteTaskRequest());
try {
await axios.delete(`/tasks/${taskId}`);
......@@ -160,10 +173,10 @@ export const deleteTask = (taskId) => {
}
export const deleteCalendarTask = (taskId) => {
return async (dispatch, getState) => {
return async (dispatch) => {
dispatch(deleteTaskRequest());
try {
await axios.delete(`/tasks/${taskId}`);
await axios.delete(`/copy-tasks/${taskId}`);
dispatch(deleteTaskSuccess())
dispatch(fetchCalendarTasks())
} catch (error) {
......
......@@ -29,8 +29,22 @@ const tasksReduсer = (state = initialState, action) => {
case FETCH_CALENDAR_TASKS_REQUEST:
return {...state, loading: true};
case FETCH_CALENDAR_TASKS_SUCCESS:
const newArr = []
action.tasks.forEach((task)=>{
const newTasksWithoutInfoForCell = []
const newTasksWithInfoForCell = []
for (let task of action.tasks) {
for (let copy of task.dateTimeTasks) {
newTasksWithoutInfoForCell.push({
...copy,
mainTaskId: task.id,
executor: task.executor,
author: task.author,
priority: task.priority,
title: task.title,
description: task.description
})
}
}
newTasksWithoutInfoForCell.forEach((task)=>{
if (task.dateTimeStart && task.dateTimeDue) {
if (new Date(task.dateTimeDue).getTime() - new Date(task.dateTimeStart).getTime() < (24 * 3600000) &&
new Date(task.dateTimeDue).getTime() - new Date(task.dateTimeStart).getTime() > 0) {
......@@ -55,11 +69,11 @@ const tasksReduсer = (state = initialState, action) => {
endMinute: timeEndMinute,
}
}
newArr.push(newObj)
newTasksWithInfoForCell.push(newObj)
}
}
})
return {...state, loading: false, calendarTasks: newArr};
return {...state, loading: false, calendarTasks: newTasksWithInfoForCell};
case FETCH_ALL_TASKS_SUCCESS:
return {...state, loading: false, tasks: action.tasks};
case FETCH_CALENDAR_TASKS_FAILURE:
......
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