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