Commit 54ec2d57 authored by Ermolaev Timur's avatar Ermolaev Timur

#135 Полностью реализовал возможность создание множество копий в недельном календаре

parent 17b16f74
...@@ -108,10 +108,11 @@ router.delete('/:dateTimeTaskId',authAuthorOrExecutorOfDateTimeTask, async(req:R ...@@ -108,10 +108,11 @@ router.delete('/:dateTimeTaskId',authAuthorOrExecutorOfDateTimeTask, async(req:R
} }
} }
if (dateTimeTasks.length ===1 ) { if (dateTimeTasks.length === 1 ) {
if ( authorStatus) { if ( authorStatus) {
Task.remove(task) task.dateTimeTasks = []
return res.send({message:"task delete succesfully"}) await task.save()
return res.send({message:"copyTask delete succesfully"})
} else{ } else{
return res.send({message:"not uathorized to delete task"}) return res.send({message:"not uathorized to delete task"})
} }
......
...@@ -49,7 +49,7 @@ const CalendarStandartCell = ({ children, xs, hours, dayNumber, createTaskInCell ...@@ -49,7 +49,7 @@ const CalendarStandartCell = ({ children, xs, hours, dayNumber, createTaskInCell
setTop(40 * Math.ceil((e.nativeEvent.offsetY - 5) / 40 - 1)) setTop(40 * Math.ceil((e.nativeEvent.offsetY - 5) / 40 - 1))
} }
} }
if (copyTask || copyMode.working) { if (copyTask || copyMode) {
createCopyTask(dayNumber, parseInt(hours.split(':')[0]), month, year) createCopyTask(dayNumber, parseInt(hours.split(':')[0]), month, year)
} else { } else {
createTaskInCellHandler(dayNumber, hours, month, year); createTaskInCellHandler(dayNumber, hours, month, year);
......
import React, { memo} from "react";
import DeleteIcons from '@mui/icons-material/Delete';
const DeleteIcon = ({onClick}) => {
const styles = { width: '20px', cursor: 'pointer', marginLeft: 'auto', marginTop: '5px', marginRight: '5px'}
return (
<DeleteIcons sx={styles} onClick={onClick}>
</DeleteIcons>)
};
export default memo(DeleteIcon);
\ No newline at end of file
...@@ -8,7 +8,7 @@ import { getTasksWithInfoForPosition, getWidthLeftZIndex } from "./Helpers"; ...@@ -8,7 +8,7 @@ import { getTasksWithInfoForPosition, getWidthLeftZIndex } from "./Helpers";
function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat, handleOpen, setCurrentTask, copyTask, setCopyTask, createCopyTask, createTaskInCellHandler, modal, dragTaskHandler, copyMode }) { function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat, handleOpen, setCurrentTask, copyTask, setCopyTask, createCopyTask, createTaskInCellHandler, modal, dragTaskHandler, copyMode, deleteTaskHandler }) {
const [columnDaySize, setColumnDaySize] = useState({ width: 0, height: 0 }) const [columnDaySize, setColumnDaySize] = useState({ width: 0, height: 0 })
...@@ -62,6 +62,8 @@ function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat ...@@ -62,6 +62,8 @@ function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat
step={step} step={step}
tasksLength={tasksLength} tasksLength={tasksLength}
hourFormat={hourFormat} hourFormat={hourFormat}
copyModeTask={copyMode.task}
deleteTaskHandler={deleteTaskHandler}
> >
</CalendarWeekTask> </CalendarWeekTask>
) )
...@@ -84,7 +86,7 @@ function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat ...@@ -84,7 +86,7 @@ function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat
month={month} month={month}
year={year} year={year}
dragTaskHandler={dragTaskHandler} dragTaskHandler={dragTaskHandler}
copyMode={copyMode} copyMode={copyMode.working}
> >
</CalendarStandartCell> </CalendarStandartCell>
) )
......
...@@ -2,9 +2,10 @@ import { Box } from "@mui/material" ...@@ -2,9 +2,10 @@ import { Box } from "@mui/material"
import { useEffect, useState, memo, useCallback, useMemo } from "react" import { useEffect, useState, memo, useCallback, useMemo } from "react"
import { getColorTaskByPriority } from "../../../../../../helpers/CalendarHelpers" import { getColorTaskByPriority } from "../../../../../../helpers/CalendarHelpers"
import CopyIcon from "../../../../UI/CopyIcon/CopyIcon"; import CopyIcon from "../../../../UI/CopyIcon/CopyIcon";
import DeleteIcon from "../../../../UI/DeleteIcon/DeleteIcon";
function CalendarWeekTask({ height, width, left, top, task, zIndex, handleOpen, setCurrentTask, modal, setCopyTask, month, dragTaskHandler, step, hourFormat, tasksLength }) { function CalendarWeekTask({ height, width, left, top, task, zIndex, handleOpen, setCurrentTask, modal, setCopyTask, month, dragTaskHandler, step, hourFormat, tasksLength, copyModeTask, deleteTaskHandler }) {
const [zIndexStyle, setZIndexStyle] = useState(10) const [zIndexStyle, setZIndexStyle] = useState(10)
const color = useMemo(() => { const color = useMemo(() => {
return getColorTaskByPriority(task.priority) return getColorTaskByPriority(task.priority)
...@@ -95,18 +96,19 @@ function CalendarWeekTask({ height, width, left, top, task, zIndex, handleOpen, ...@@ -95,18 +96,19 @@ function CalendarWeekTask({ height, width, left, top, task, zIndex, handleOpen,
setCopyTask(task) setCopyTask(task)
}, [task, setCopyTask]) }, [task, setCopyTask])
return ( const returnTask = useMemo(() => {
<Box if (copyModeTask?.id === task?.mainTaskId) {
draggable={true} return (<>
onDragStart={(e) => { dragStartHandler(e, task) }} <span style={{ textOverflow: 'ellipsis', padding: '5px 0 0 5px' }}>
onDragEnd={(e) => { dragEndHandler(e) }} {task.title}
onDrop={(e) => { dropHandler(e, task) }} </span>
onDragOver={(e) => { dragOverHandler(e) }} <DeleteIcon
onDragLeave={(e) => { dragLeaveHandler(e) }} onClick={(e) => { deleteTaskHandler(e, task.id) }}
onClick={(e) => { onClickTaskHandler(e, task) }} />
className='calendar_task_block' </>)
sx={styles}> }
{tasksLength > 2 ? <> if (tasksLength > 2) {
return (<>
<CopyIcon <CopyIcon
tasksLength={tasksLength} tasksLength={tasksLength}
onClick={(e) => { onClickCopyIconHandler(e) }} onClick={(e) => { onClickCopyIconHandler(e) }}
...@@ -114,14 +116,31 @@ function CalendarWeekTask({ height, width, left, top, task, zIndex, handleOpen, ...@@ -114,14 +116,31 @@ function CalendarWeekTask({ height, width, left, top, task, zIndex, handleOpen,
<span style={{ textOverflow: 'ellipsis', padding: '5px 0 0 5px' }}> <span style={{ textOverflow: 'ellipsis', padding: '5px 0 0 5px' }}>
{task.title} {task.title}
</span> </span>
</> </>)
: <> } else {
return (<>
<span style={{ textOverflow: 'ellipsis', padding: '5px 0 0 5px' }}> <span style={{ textOverflow: 'ellipsis', padding: '5px 0 0 5px' }}>
{task.title} {task.title}
</span> </span>
<CopyIcon <CopyIcon
onClick={(e) => { onClickCopyIconHandler(e) }} onClick={(e) => { onClickCopyIconHandler(e) }}
/> </>} />
</>)
}
}, [tasksLength, task.title, onClickCopyIconHandler, copyModeTask?.id, deleteTaskHandler, task?.id, task?.mainTaskId])
return (
<Box
draggable={true}
onDragStart={(e) => { dragStartHandler(e, task) }}
onDragEnd={(e) => { dragEndHandler(e) }}
onDrop={(e) => { dropHandler(e, task) }}
onDragOver={(e) => { dragOverHandler(e) }}
onDragLeave={(e) => { dragLeaveHandler(e) }}
onClick={(e) => { onClickTaskHandler(e, task) }}
className='calendar_task_block'
sx={styles}>
{returnTask}
</Box>); </Box>);
} }
......
...@@ -85,6 +85,7 @@ function WeekCalendarBody({ week, hoursInDay, hourFormat, setHourFormat, date, t ...@@ -85,6 +85,7 @@ function WeekCalendarBody({ week, hoursInDay, hourFormat, setHourFormat, date, t
createCopyTask={createCopyTask} createCopyTask={createCopyTask}
dragTaskHandler={dragTaskHandler} dragTaskHandler={dragTaskHandler}
copyMode={copyMode} copyMode={copyMode}
deleteTaskHandler={deleteTaskHandler}
/> />
) )
})} })}
...@@ -110,7 +111,7 @@ function WeekCalendarBody({ week, hoursInDay, hourFormat, setHourFormat, date, t ...@@ -110,7 +111,7 @@ function WeekCalendarBody({ week, hoursInDay, hourFormat, setHourFormat, date, t
project={currentTask.project} project={currentTask.project}
onChangeCurrentTaskHandler={(e) => { onChangeCurrentTaskHandler(e) }} onChangeCurrentTaskHandler={(e) => { onChangeCurrentTaskHandler(e) }}
sendNewTaskHandler={() => { sendNewTaskHandler(); handleClose() }} sendNewTaskHandler={() => { sendNewTaskHandler(); handleClose() }}
deleteTaskHandler={() => { deleteTaskHandler(currentTask.id); handleClose() }} deleteTaskHandler={(e) => { deleteTaskHandler(e, currentTask.id); handleClose() }}
/> />
</ModalTask> </ModalTask>
</> </>
......
...@@ -239,7 +239,7 @@ function WeekCalendar() { ...@@ -239,7 +239,7 @@ function WeekCalendar() {
await dispatch(addCopyCalendarTask(newTask, userId)) await dispatch(addCopyCalendarTask(newTask, userId))
setCopyTask(null) setCopyTask(null)
} }
}, [copyTask, dispatch, hoursInDay, userId]) }, [copyTask, dispatch, hoursInDay, userId, copyMode.task, copyMode.working, hourFormat])
const dragTaskHandler = useCallback(async (dayNumber, hour, month, year) => { const dragTaskHandler = useCallback(async (dayNumber, hour, month, year) => {
const hourDiff = currentTask.infoForCell.endHour - currentTask.infoForCell.startHour const hourDiff = currentTask.infoForCell.endHour - currentTask.infoForCell.startHour
...@@ -263,8 +263,10 @@ function WeekCalendar() { ...@@ -263,8 +263,10 @@ function WeekCalendar() {
setCurrentTask({}) setCurrentTask({})
}, [currentTask, dispatch, hoursInDay, userId]) }, [currentTask, dispatch, hoursInDay, userId])
const deleteTaskHandler = useCallback(async (taskId) => { const deleteTaskHandler = useCallback(async (e, taskId) => {
dispatch(deleteCalendarTask(taskId, userId)) console.log(e)
e.stopPropagation();
await dispatch(deleteCalendarTask(taskId, userId))
}, [dispatch, userId]) }, [dispatch, userId])
const handleClose = useCallback(() => { const handleClose = useCallback(() => {
...@@ -287,7 +289,7 @@ function WeekCalendar() { ...@@ -287,7 +289,7 @@ function WeekCalendar() {
const copyModeReturn = useCallback(async () => { const copyModeReturn = useCallback(async () => {
navigate('/my-tasks') navigate('/my-tasks')
}, [dispatch]) }, [navigate])
return ( return (
<> <>
......
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