Commit cf98dee7 authored by Ermolaev Timur's avatar Ermolaev Timur

Merge branch 'task-60-feature/copy_calendar_tasks' into 'development'

#60 реализовал копирование задач

See merge request !39
parents 676a167d 5023bcac
...@@ -4,7 +4,7 @@ import CalendarStandartCell from "../CalendarStandartCell.js/CalendarStandartCel ...@@ -4,7 +4,7 @@ import CalendarStandartCell from "../CalendarStandartCell.js/CalendarStandartCel
import CalendarTask from "../CalendarTask/CalendarTask"; import CalendarTask from "../CalendarTask/CalendarTask";
import EmptyBox from "./EmptyBox/EmptyBox"; import EmptyBox from "./EmptyBox/EmptyBox";
const CalendarRowDay = ({xs, hoursInDay, createTaskInCellHandler, currentTask, handleOpen, modal, setCurrentTask, year, month, tasks, day, hourFormat, setCurrentLine, currentLine, dragTaskHandler, increaseTaskHandler, reduceTaskHandler}) => { const CalendarRowDay = ({xs, hoursInDay, createTaskInCellHandler, currentTask, handleOpen, modal, setCurrentTask, year, month, tasks, day, hourFormat, setCurrentLine, currentLine, dragTaskHandler, increaseTaskHandler, reduceTaskHandler, createCopyTask, setCopyTask, copyTask}) => {
const hours = useMemo(()=>{ const hours = useMemo(()=>{
return hoursInDay.map((hour)=>parseInt(hour.split(':')[0]))}, return hoursInDay.map((hour)=>parseInt(hour.split(':')[0]))},
...@@ -137,25 +137,6 @@ const CalendarRowDay = ({xs, hoursInDay, createTaskInCellHandler, currentTask, h ...@@ -137,25 +137,6 @@ const CalendarRowDay = ({xs, hoursInDay, createTaskInCellHandler, currentTask, h
xs={10.8} xs={10.8}
align='center' align='center'
> >
{hoursInDay.map((hour, i)=>{
return (
<CalendarStandartCell
linesInDay={linesInDay}
key={i}
item xs={xs}
createTaskInCellHandler={createTaskInCellHandler}
hours={hour}
dragTaskHandler={dragTaskHandler}
dayNumber={day.dayNumber}
currentTask={currentTask}
handleOpen={handleOpen}
modal={modal}
>
</CalendarStandartCell>
)
})}
{linesInDay?.map((line, i)=>{ {linesInDay?.map((line, i)=>{
const boxes = getBoxesInLine(line) const boxes = getBoxesInLine(line)
return( return(
...@@ -164,6 +145,7 @@ const CalendarRowDay = ({xs, hoursInDay, createTaskInCellHandler, currentTask, h ...@@ -164,6 +145,7 @@ const CalendarRowDay = ({xs, hoursInDay, createTaskInCellHandler, currentTask, h
if (box.task) { if (box.task) {
return (<Grid return (<Grid
item xs={box.xs} item xs={box.xs}
key={box.task.id}
sx={{height: '35px', marginBottom: '5px'}} sx={{height: '35px', marginBottom: '5px'}}
> >
<CalendarTask <CalendarTask
...@@ -179,15 +161,19 @@ const CalendarRowDay = ({xs, hoursInDay, createTaskInCellHandler, currentTask, h ...@@ -179,15 +161,19 @@ const CalendarRowDay = ({xs, hoursInDay, createTaskInCellHandler, currentTask, h
handleOpen={handleOpen} handleOpen={handleOpen}
increaseTaskHandler={increaseTaskHandler} increaseTaskHandler={increaseTaskHandler}
reduceTaskHandler={reduceTaskHandler} reduceTaskHandler={reduceTaskHandler}
setCopyTask={setCopyTask}
/> />
</Grid>) </Grid>)
} else { } else {
return (<EmptyBox return (<EmptyBox
key={index}
modal={modal} modal={modal}
dayNumber={day.dayNumber} dayNumber={day.dayNumber}
hourNumber={box.hour} hourNumber={box.hour}
handleOpen={handleOpen} handleOpen={handleOpen}
dragTaskHandler={dragTaskHandler} dragTaskHandler={dragTaskHandler}
createCopyTask={createCopyTask}
copyTask={copyTask}
createTaskInCellHandler={createTaskInCellHandler} createTaskInCellHandler={createTaskInCellHandler}
xs={box.xs} xs={box.xs}
> >
...@@ -207,6 +193,8 @@ const CalendarRowDay = ({xs, hoursInDay, createTaskInCellHandler, currentTask, h ...@@ -207,6 +193,8 @@ const CalendarRowDay = ({xs, hoursInDay, createTaskInCellHandler, currentTask, h
hourNumber={hourNumber} hourNumber={hourNumber}
handleOpen={handleOpen} handleOpen={handleOpen}
dragTaskHandler={dragTaskHandler} dragTaskHandler={dragTaskHandler}
createCopyTask={createCopyTask}
copyTask={copyTask}
createTaskInCellHandler={createTaskInCellHandler} createTaskInCellHandler={createTaskInCellHandler}
xs={xs} xs={xs}
> >
......
...@@ -2,9 +2,7 @@ import { Grid} from "@mui/material"; ...@@ -2,9 +2,7 @@ import { Grid} from "@mui/material";
import React, { memo, useEffect, useState} from "react"; import React, { memo, useEffect, useState} from "react";
import DefaultTask from "../../DefaultTask/DefaultTask"; import DefaultTask from "../../DefaultTask/DefaultTask";
const EmptyBox = ({hourNumber, handleOpen, dayNumber, xs, dragTaskHandler, modal, createTaskInCellHandler, copyTask, createCopyTask}) => {
const EmptyBox = ({hourNumber, handleOpen, dayNumber, xs, dragTaskHandler, modal, createTaskInCellHandler}) => {
const [isThisCell, setIsThisCell] = useState(false) const [isThisCell, setIsThisCell] = useState(false)
useEffect(()=>{ useEffect(()=>{
...@@ -14,10 +12,14 @@ const EmptyBox = ({hourNumber, handleOpen, dayNumber, xs, dragTaskHandler, modal ...@@ -14,10 +12,14 @@ const EmptyBox = ({hourNumber, handleOpen, dayNumber, xs, dragTaskHandler, modal
}, [modal]) }, [modal])
const onClickHandler = (e, dayNumber, hour) => { const onClickHandler = (e, dayNumber, hour) => {
if (copyTask) {
createCopyTask(dayNumber, hour)
} else {
createTaskInCellHandler(dayNumber, hour); createTaskInCellHandler(dayNumber, hour);
setIsThisCell(true); setIsThisCell(true);
handleOpen(e) handleOpen(e)
} }
}
const dragOverHandler = (e) => { const dragOverHandler = (e) => {
e.preventDefault(); e.preventDefault();
} }
......
import { Grid} from "@mui/material"; import { Grid} from "@mui/material";
import { memo, useEffect, useState } from "react"; import { memo, useEffect, useState } from "react";
import DefaultTask from "../DefaultTask/DefaultTask";
const cellClass = {
transition: '0.3s',
position: 'relative',
height: '35px',
}
const CalendarStandartCell = ({children, xs, hours, dayNumber, createTaskInCellHandler, handleOpen, modal, divRef, dragTaskHandler, linesInDay}) => { const CalendarStandartCell = ({children, xs, hours, dayNumber, createTaskInCellHandler, handleOpen, modal, divRef, dragTaskHandler, linesInDay}) => {
const [isThisCell, setIsThisCell] = useState(false) const [isThisCell, setIsThisCell] = useState(false)
useEffect(()=>{ useEffect(()=>{
if(!modal) { if(!modal) {
setIsThisCell(false); setIsThisCell(false);
...@@ -22,20 +31,14 @@ const CalendarStandartCell = ({children, xs, hours, dayNumber, createTaskInCell ...@@ -22,20 +31,14 @@ const CalendarStandartCell = ({children, xs, hours, dayNumber, createTaskInCell
return <> return <>
<Grid <Grid
item xs={xs} item xs={xs}
sx={{position: 'relative', height: linesInDay?.length ? `${35*linesInDay}px` : '35px'}} sx={cellClass}
onClick={(e)=>{createTaskInCellHandler(dayNumber, hours); setIsThisCell(true); handleOpen(e)}} onClick={(e)=>{createTaskInCellHandler(dayNumber, hours); setIsThisCell(true); handleOpen(e)}}
onDragOver={(e)=>{dragOverHandler(e)}} onDragOver={(e)=>{dragOverHandler(e)}}
onDrop={(e)=>{dropHandler(e)}} onDrop={(e)=>{dropHandler(e)}}
> >
{children} {children}
{isThisCell ? {isThisCell ?
<Grid <DefaultTask/> : null}
sx={{ position: 'relative', height: '29px', backgroundColor: 'lightgreen', whiteSpace: 'nowrap', overflow: 'hidden', textOverflow: 'ellipsis', borderRadius: '10px', margin: '3px 10px', display: 'flex', justifyContent: 'flex-start', alignItems: 'center', paddingLeft: '5px', zIndex: '5'}}
>
<span>
Задача
</span>
</Grid> : null}
<div style={{position: 'absolute', height: children ? divRef : 0, width: '1px', backgroundColor: 'black', right: '0', top: '0', zIndex: '3'}}> <div style={{position: 'absolute', height: children ? divRef : 0, width: '1px', backgroundColor: 'black', right: '0', top: '0', zIndex: '3'}}>
</div> </div>
......
import { Grid} from "@mui/material"; import { Button, Grid} from "@mui/material";
import React, { memo, useEffect, useRef, useState} from "react"; import React, { memo, useEffect, useRef, useState} from "react";
import ArrowBackIcon from '@mui/icons-material/ArrowBack'; import ArrowBackIcon from '@mui/icons-material/ArrowBack';
import ArrowForwardIcon from '@mui/icons-material/ArrowForward'; import ArrowForwardIcon from '@mui/icons-material/ArrowForward';
...@@ -13,7 +13,7 @@ const arrowClass = { ...@@ -13,7 +13,7 @@ const arrowClass = {
} }
} }
const CalendarTask = ({setCurrentTask, handleOpen, task, line, setCurrentLine, increaseTaskHandler, reduceTaskHandler, hourFormat}) => { const CalendarTask = ({setCurrentTask, handleOpen, task, line, setCurrentLine, increaseTaskHandler, reduceTaskHandler, hourFormat, setCopyTask}) => {
const [color, setColor] = useState('') const [color, setColor] = useState('')
useEffect(() => { useEffect(() => {
...@@ -80,6 +80,9 @@ const CalendarTask = ({setCurrentTask, handleOpen, task, line, setCurrentLine, i ...@@ -80,6 +80,9 @@ const CalendarTask = ({setCurrentTask, handleOpen, task, line, setCurrentLine, i
{task.title} {task.title}
</span> </span>
<div style={{display: 'flex', alignItems: 'center'}}> <div style={{display: 'flex', alignItems: 'center'}}>
<Button sx={{color:'black', fontWeight:'600'}} onClick={(e)=>{e.stopPropagation(); setCopyTask(task)}}>
Copy
</Button>
<ArrowBackIcon sx={arrowClass} onClick={(e)=>{e.stopPropagation(); reduceTaskHandler(line, task, false)}}/> <ArrowBackIcon sx={arrowClass} onClick={(e)=>{e.stopPropagation(); reduceTaskHandler(line, task, false)}}/>
<ArrowForwardIcon sx={arrowClass} onClick={(e)=>{e.stopPropagation(); increaseTaskHandler(line, task, false)}}/> <ArrowForwardIcon sx={arrowClass} onClick={(e)=>{e.stopPropagation(); increaseTaskHandler(line, task, false)}}/>
</div> </div>
......
...@@ -8,7 +8,7 @@ import MonthCalendarModalContent from "../MonthCalendarModalContent/MonthCalenda ...@@ -8,7 +8,7 @@ import MonthCalendarModalContent from "../MonthCalendarModalContent/MonthCalenda
import CalendarRowDay from "./CalendarRowDay/CalendarRowDay"; import CalendarRowDay from "./CalendarRowDay/CalendarRowDay";
function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, currentTask, setCurrentTask, hourFormat, setHourFormat, onChangeCurrentTaskHandler, sendNewTaskHandler, deleteTaskHandler, cellSizes, hoursInDay, daysInMonth, dragTaskHandler, increaseTaskHandler, reduceTaskHandler}) { function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, currentTask, setCurrentTask, hourFormat, setHourFormat, onChangeCurrentTaskHandler, sendNewTaskHandler, deleteTaskHandler, cellSizes, hoursInDay, daysInMonth, dragTaskHandler, increaseTaskHandler, reduceTaskHandler, createCopyTask, setCopyTask, copyTask}) {
const [currentLine, setCurrentLine] = useState('') const [currentLine, setCurrentLine] = useState('')
const [modal, setModal] = useState({open:false, y: 0, x: 0,}); const [modal, setModal] = useState({open:false, y: 0, x: 0,});
...@@ -85,6 +85,9 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, current ...@@ -85,6 +85,9 @@ function MonthCalendarBody({month, year, tasks, createTaskInCellHandler, current
hourFormat={hourFormat} hourFormat={hourFormat}
increaseTaskHandler={increaseTaskHandler} increaseTaskHandler={increaseTaskHandler}
reduceTaskHandler={reduceTaskHandler} reduceTaskHandler={reduceTaskHandler}
createCopyTask={createCopyTask}
copyTask={copyTask}
setCopyTask={setCopyTask}
> >
</CalendarRowDay> </CalendarRowDay>
</CalendarRow> </CalendarRow>
......
...@@ -13,6 +13,7 @@ function MonthCalendar() { ...@@ -13,6 +13,7 @@ function MonthCalendar() {
const [worker, setWorker] = useState(''); const [worker, setWorker] = useState('');
const [calendarType, setCalendarType] = useState('Месяц'); const [calendarType, setCalendarType] = useState('Месяц');
const [currentTask, setCurrentTask] = useState({title: '', description: '', priority: ''}) const [currentTask, setCurrentTask] = useState({title: '', description: '', priority: ''})
const [copyTask, setCopyTask] = useState(null)
const [cellSizes, setCellSizes] = useState({}) const [cellSizes, setCellSizes] = useState({})
useEffect(()=>{ useEffect(()=>{
...@@ -126,11 +127,7 @@ function MonthCalendar() { ...@@ -126,11 +127,7 @@ function MonthCalendar() {
} }
const dragTaskHandler = async (dayNumber, hour) => { const dragTaskHandler = async (dayNumber, hour) => {
const timeEnd = currentTask.dateTimeDue.split('T')[1] const hourDiff = currentTask.infoForCell.endHour - currentTask.infoForCell.startHour
const timeEndHour = parseInt(timeEnd.split(':')[0])
const timeStart = currentTask.dateTimeStart.split('T')[1]
const timeStartHour = parseInt(timeStart.split(':')[0])
const hourDiff = timeEndHour - timeStartHour
const due = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, hour + hourDiff, 59)) const 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 newObj = {
...@@ -142,6 +139,7 @@ function MonthCalendar() { ...@@ -142,6 +139,7 @@ function MonthCalendar() {
await dispatch(editTask(newObj)) await dispatch(editTask(newObj))
setCurrentTask({}) setCurrentTask({})
} }
const increaseTaskHandler = async (dayNumber, task, isStartTask) => { const increaseTaskHandler = async (dayNumber, task, isStartTask) => {
const timeEnd = task.dateTimeDue.split('T')[1] const timeEnd = task.dateTimeDue.split('T')[1]
const timeEndHour = parseInt(timeEnd.split(':')[0]) const timeEndHour = parseInt(timeEnd.split(':')[0])
...@@ -228,6 +226,19 @@ function MonthCalendar() { ...@@ -228,6 +226,19 @@ function MonthCalendar() {
} }
} }
const createCopyTask = async (dayNumber, hour) => {
const hourDiff = copyTask.infoForCell.endHour - copyTask.infoForCell.startHour
const newTask = {
...copyTask,
dateTimeStart: dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, hour, 0)),
dateTimeDue: dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, dayNumber, hour + hourDiff, 59)),
}
delete newTask.infoForCell
delete newTask.id
await dispatch(addTask(newTask))
setCopyTask(null)
}
const deleteTaskHandler = async (taskId) => { const deleteTaskHandler = async (taskId) => {
dispatch(deleteTask(taskId)) dispatch(deleteTask(taskId))
} }
...@@ -262,6 +273,9 @@ function MonthCalendar() { ...@@ -262,6 +273,9 @@ function MonthCalendar() {
dragTaskHandler={dragTaskHandler} dragTaskHandler={dragTaskHandler}
increaseTaskHandler={increaseTaskHandler} increaseTaskHandler={increaseTaskHandler}
reduceTaskHandler={reduceTaskHandler} reduceTaskHandler={reduceTaskHandler}
createCopyTask={createCopyTask}
copyTask={copyTask}
setCopyTask={setCopyTask}
/> />
</> </>
......
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