Commit ba6c7af0 authored by Ermolaev Timur's avatar Ermolaev Timur

Merge branch 'task-135-feature/create_tasks_mode_in_calendar' into 'development'

Task 135 feature/create tasks mode in calendar

See merge request !109
parents d56c1f40 261266f1
...@@ -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"})
} }
......
import { Box, Button } from "@mui/material";
import { memo } from "react";
const style = {
position: 'fixed',
left: '50%',
bottom: 10,
width: '30%',
height: '70px',
backgroundColor: 'white',
border: '2px solid black',
borderRadius: '10px',
zIndex: '100',
transform: 'translateX(-50%)',
boxShadow: '0px 5px 54px 27px rgba(34, 60, 80, 0.2)',
display: 'flex',
alignItems: 'center',
justifyContent: 'space-around'
}
const CreateCopyTasksModeBlock = ({ copyMode, copyModeReturn, copyModeStay }) => {
return (<>
{copyMode ?
<Box sx={style}>
<Button onClick={copyModeStay} sx={{fontWeight: 800}}>
Остаться
</Button>
<Button onClick={copyModeReturn} sx={{fontWeight: 800}}>
Вернуться
</Button>
</Box>
: null}
</>
);
};
export default memo(CreateCopyTasksModeBlock);
...@@ -81,6 +81,7 @@ const CalendarRowDay = ({ xs, hoursInDay, createTaskInCellHandler, currentTask, ...@@ -81,6 +81,7 @@ const CalendarRowDay = ({ xs, hoursInDay, createTaskInCellHandler, currentTask,
copyTask={copyTask} copyTask={copyTask}
createCopyTask={createCopyTask} createCopyTask={createCopyTask}
month={month} month={month}
year={year}
> >
</CalendarStandartCell> </CalendarStandartCell>
) )
......
...@@ -6,7 +6,6 @@ import CalendarStandartCell from "../../UI/CalendarStandartCell/CalendarStandart ...@@ -6,7 +6,6 @@ import CalendarStandartCell from "../../UI/CalendarStandartCell/CalendarStandart
import ModalTask from "../../UI/ModalTask/ModalTask" import ModalTask from "../../UI/ModalTask/ModalTask"
import MonthCalendarModalContent from "../../UI/CalendarModalTaskContent/CalendarModalTaskContent"; import MonthCalendarModalContent from "../../UI/CalendarModalTaskContent/CalendarModalTaskContent";
import CalendarRowDay from "./CalendarRowDay/CalendarRowDay"; import CalendarRowDay from "./CalendarRowDay/CalendarRowDay";
import { useSelector } from "react-redux";
function MonthCalendarBody({ month, year, tasks, createTaskInCellHandler, currentTask, setCurrentTask, hourFormat, setHourFormat, onChangeCurrentTaskHandler, sendNewTaskHandler, deleteTaskHandler, cellSizes, hoursInDay, daysInMonth, dragTaskHandler, createCopyTask, setCopyTask, copyTask}) { function MonthCalendarBody({ month, year, tasks, createTaskInCellHandler, currentTask, setCurrentTask, hourFormat, setHourFormat, onChangeCurrentTaskHandler, sendNewTaskHandler, deleteTaskHandler, cellSizes, hoursInDay, daysInMonth, dragTaskHandler, createCopyTask, setCopyTask, copyTask}) {
......
import { AppBar, Button, Toolbar, Typography } from '@mui/material'; import { AppBar, Toolbar, } from '@mui/material';
import { Box } from '@mui/system'; import { Box } from '@mui/system';
import ButtonSwapCalendar from '../../UI/ButtonSwapCalendar/ButtonSwapCalendar'; import ButtonSwapCalendar from '../../UI/ButtonSwapCalendar/ButtonSwapCalendar';
import CalendarUserDisplayName from '../../UI/CalendarUserDisplayName/CalendarUserDisplayName'; import CalendarUserDisplayName from '../../UI/CalendarUserDisplayName/CalendarUserDisplayName';
......
import { Grid } from "@mui/material"; import { Grid } from "@mui/material";
import { memo, useEffect, useState } from "react"; import { memo, useCallback, useEffect, useMemo, useState } from "react";
import DefaultTask from "../DefaultTask/DefaultTask"; import DefaultTask from "../DefaultTask/DefaultTask";
const heightCell = 40 const heightCell = 40
const CalendarStandartCell = ({ children, xs, hours, dayNumber, createTaskInCellHandler, handleOpen, modal, dragTaskHandler, linesInDay, week, copyTask, createCopyTask, month, year }) => { const CalendarStandartCell = ({ children, xs, hours, dayNumber, createTaskInCellHandler, handleOpen, modal, dragTaskHandler, linesInDay, week, copyTask, createCopyTask, month, year, copyMode, copyModeTask }) => {
const [isThisCell, setIsThisCell] = useState(false) const [isThisCell, setIsThisCell] = useState(false)
const [top, setTop] = useState(0) const [top, setTop] = useState(0)
const cellClass = { const isDeadLine = useMemo(()=>{
if (copyTask?.dateTimeDeadLine) {
if (new Date(copyTask?.dateTimeDeadLine).getTime() - new Date(year, month, dayNumber, parseInt(hours?.split(':')[0])).getTime() < 0 ) {
return true
}
} else {
if (copyModeTask?.dateTimeDeadLine) {
if (new Date(copyModeTask?.dateTimeDeadLine).getTime() - new Date(year, month, dayNumber, parseInt(hours?.split(':')[0])).getTime() < 0 ) {
return true
}
} else {
return false
}
}
},[copyTask, copyModeTask, year, month, dayNumber, hours])
console.log(copyTask)
const cellClass = useMemo(() => {
const backgroundColor = isDeadLine ? '#fa9b9be3' : 'null'
return ({
position: 'relative', position: 'relative',
height: linesInDay?.length ? `${heightCell * linesInDay.length + 5}px` : `${45}px`, height: linesInDay?.length ? `${heightCell * linesInDay.length + 5}px` : `${45}px`,
borderRight: '1px solid black', borderRight: '1px solid black',
borderBottom: week ? '1px solid black' : null, borderBottom: week ? '1px solid black' : null,
padding: week ? '2px' : null,
transition: week ? '0.3s' : null, transition: week ? '0.3s' : null,
backgroundColor: backgroundColor,
'&:hover': { '&:hover': {
transition: '0.3s', transition: '0.3s',
cursor: children ? null : '#d6d2d2', cursor: children ? null : '#d6d2d2',
background: children ? null : '#d6d2d2' background: children ? null : '#d6d2d2'
},
} }
})
}, [children, linesInDay?.length, week, isDeadLine])
useEffect(() => { useEffect(() => {
if (!modal) { if (!modal) {
...@@ -25,23 +48,23 @@ const CalendarStandartCell = ({ children, xs, hours, dayNumber, createTaskInCell ...@@ -25,23 +48,23 @@ const CalendarStandartCell = ({ children, xs, hours, dayNumber, createTaskInCell
} }
}, [modal]) }, [modal])
const dragOverHandler = (e) => { const dragOverHandler = useCallback((e) => {
e.preventDefault(); e.preventDefault();
e.target.style.background = children ? null : '#d6d2d2' e.target.style.background = children ? null : '#d6d2d2'
} }, [children])
const dragLeaveHandler = (e) => { const dragLeaveHandler = useCallback((e) => {
e.preventDefault(); e.preventDefault();
e.target.style.background = null e.target.style.background = null
} }, [])
const dropHandler = (e) => { const dropHandler = useCallback((e) => {
e.stopPropagation() e.stopPropagation()
e.preventDefault(); e.preventDefault();
e.target.style.background = null e.target.style.background = null
dragTaskHandler(dayNumber, parseInt(hours.split(':')[0]), month, year) dragTaskHandler(dayNumber, parseInt(hours.split(':')[0]), month, year)
} }, [dayNumber, hours, month, year, dragTaskHandler])
const onClickHandler = (e) => { const onClickHandler = useCallback((e) => {
if (!week) { if (!week) {
if (e.nativeEvent.offsetY <= 5) { if (e.nativeEvent.offsetY <= 5) {
setTop(40 * Math.ceil((e.nativeEvent.offsetY) / 40 - 1)) setTop(40 * Math.ceil((e.nativeEvent.offsetY) / 40 - 1))
...@@ -49,16 +72,39 @@ const CalendarStandartCell = ({ children, xs, hours, dayNumber, createTaskInCell ...@@ -49,16 +72,39 @@ 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) { 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);
setIsThisCell(true); setIsThisCell(true);
handleOpen(e) handleOpen(e)
} }
} }, [week, copyTask, copyMode, dayNumber, hours, month, year, createTaskInCellHandler, createCopyTask, handleOpen])
return <> const returnCells = useMemo(() => {
if (copyTask || copyMode) {
if (isDeadLine) {
return (<Grid
item xs={xs}
sx={cellClass}
>
</Grid>)
} else {
return (<Grid
item xs={xs}
sx={cellClass}
onClick={(e) => { onClickHandler(e) }}
onDragOver={(e) => { dragOverHandler(e) }}
onDragLeave={(e) => { dragLeaveHandler(e) }}
onDrop={(e) => { dropHandler(e) }}
>
{children}
{isThisCell ?
<DefaultTask week={week} top={top} /> : null}
</Grid>)
}
}
return (<>
<Grid <Grid
item xs={xs} item xs={xs}
sx={cellClass} sx={cellClass}
...@@ -72,6 +118,12 @@ const CalendarStandartCell = ({ children, xs, hours, dayNumber, createTaskInCell ...@@ -72,6 +118,12 @@ const CalendarStandartCell = ({ children, xs, hours, dayNumber, createTaskInCell
<DefaultTask week={week} top={top} /> : null} <DefaultTask week={week} top={top} /> : null}
</Grid> </Grid>
</>)
}, [cellClass, children, copyMode, copyTask, dragOverHandler, dropHandler, isThisCell, onClickHandler, top, week, xs, dragLeaveHandler, isDeadLine])
return <>
{returnCells}
</> </>
}; };
......
import React, {useState} from 'react';
import DatePicker from "react-datepicker";
const DateTimePicker =({task,name,onChange}) => {
const [startDate, setStartDate] = useState(new Date());
return (
<>
<DatePicker
selected={startDate}
onChange={(date) => setStartDate(date)}
// locale="ru"
showTimeSelect
timeFormat="p"
timeIntervals={60}
dateFormat="Pp"
/>
</>
);
};
export default DateTimePicker;
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
import Box from '@mui/material/Box'; import Box from '@mui/material/Box';
import Modal from '@mui/material/Modal'; import Modal from '@mui/material/Modal';
import { useCallback, useEffect, useMemo, useState } from 'react'; import { useCallback, useEffect, useState } from 'react';
export default function ModalTask({ modal, handleClose, children, week }) { export default function ModalTask({ modal, handleClose, children, week }) {
...@@ -38,7 +38,7 @@ export default function ModalTask({ modal, handleClose, children, week }) { ...@@ -38,7 +38,7 @@ export default function ModalTask({ modal, handleClose, children, week }) {
return modal.yClickСordinates - modal.yDiv - modal.yDivClick - ((modal.yClickСordinates + 470) - windowDimenion.winHeight) - 30 return modal.yClickСordinates - modal.yDiv - modal.yDivClick - ((modal.yClickСordinates + 470) - windowDimenion.winHeight) - 30
} }
} }
}, [windowDimenion.winHeight, modal]) }, [windowDimenion.winHeight, modal, week])
const getXCordinatesToModal = useCallback(() => { const getXCordinatesToModal = useCallback(() => {
if (windowDimenion.winWidth > modal.xClickСordinates + 270 + modal.xDiv) { if (windowDimenion.winWidth > modal.xClickСordinates + 270 + modal.xDiv) {
......
...@@ -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 }) { 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,6 +86,8 @@ function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat ...@@ -84,6 +86,8 @@ function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat
month={month} month={month}
year={year} year={year}
dragTaskHandler={dragTaskHandler} dragTaskHandler={dragTaskHandler}
copyMode={copyMode.working}
copyModeTask={copyMode.task}
> >
</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)
...@@ -94,19 +95,20 @@ function CalendarWeekTask({ height, width, left, top, task, zIndex, handleOpen, ...@@ -94,19 +95,20 @@ function CalendarWeekTask({ height, width, left, top, task, zIndex, handleOpen,
e.stopPropagation(); e.stopPropagation();
setCopyTask(task) setCopyTask(task)
}, [task, setCopyTask]) }, [task, setCopyTask])
console.log(tasksLength)
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>);
} }
......
...@@ -10,7 +10,7 @@ import HourFormatSwitch from "../../UI/HourFormatSwitch/HourFormatSwitch"; ...@@ -10,7 +10,7 @@ import HourFormatSwitch from "../../UI/HourFormatSwitch/HourFormatSwitch";
import CalendarColumnDayWeek from "./CalendarColumnDayWeek/CalendarColumnDayWeek"; import CalendarColumnDayWeek from "./CalendarColumnDayWeek/CalendarColumnDayWeek";
import { getCurrentWeekDayString, getMonthAndYearToDayColumn } from "./Helpers"; import { getCurrentWeekDayString, getMonthAndYearToDayColumn } from "./Helpers";
function WeekCalendarBody({ week, hoursInDay, hourFormat, setHourFormat, date, tasks, currentTask, setCurrentTask, onChangeCurrentTaskHandler, deleteTaskHandler, sendNewTaskHandler, createTaskInCellHandler, copyTask, setCopyTask, createCopyTask, dragTaskHandler }) { function WeekCalendarBody({ week, hoursInDay, hourFormat, setHourFormat, date, tasks, currentTask, setCurrentTask, onChangeCurrentTaskHandler, deleteTaskHandler, sendNewTaskHandler, createTaskInCellHandler, copyTask, setCopyTask, createCopyTask, dragTaskHandler, copyMode }) {
const [modal, setModal] = useState({ open: false, y: 0, x: 0, }); const [modal, setModal] = useState({ open: false, y: 0, x: 0, });
const handleOpen = useCallback((e) => { const handleOpen = useCallback((e) => {
setModal({ setModal({
...@@ -31,7 +31,7 @@ function WeekCalendarBody({ week, hoursInDay, hourFormat, setHourFormat, date, t ...@@ -31,7 +31,7 @@ function WeekCalendarBody({ week, hoursInDay, hourFormat, setHourFormat, date, t
return ( return (
<> <>
<Box style={{ marginBottom: '30px' }}> <Box style={{ marginBottom: copyMode.working ? '100px' : '30px'}}>
<Box style={{ position: 'sticky', top: '0px', zIndex: '10', backgroundColor: 'lightgrey' }}> <Box style={{ position: 'sticky', top: '0px', zIndex: '10', backgroundColor: 'lightgrey' }}>
<CalendarRow <CalendarRow
> >
...@@ -84,6 +84,8 @@ function WeekCalendarBody({ week, hoursInDay, hourFormat, setHourFormat, date, t ...@@ -84,6 +84,8 @@ function WeekCalendarBody({ week, hoursInDay, hourFormat, setHourFormat, date, t
setCopyTask={setCopyTask} setCopyTask={setCopyTask}
createCopyTask={createCopyTask} createCopyTask={createCopyTask}
dragTaskHandler={dragTaskHandler} dragTaskHandler={dragTaskHandler}
copyMode={copyMode}
deleteTaskHandler={deleteTaskHandler}
/> />
) )
})} })}
...@@ -109,7 +111,7 @@ function WeekCalendarBody({ week, hoursInDay, hourFormat, setHourFormat, date, t ...@@ -109,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>
</> </>
......
...@@ -21,7 +21,6 @@ import BasicSelect from "../UI/Select/Select"; ...@@ -21,7 +21,6 @@ import BasicSelect from "../UI/Select/Select";
import { addTask } from "../../store/actions/tasksActions"; import { addTask } from "../../store/actions/tasksActions";
import TaskModal from "./TaskModal/TaskModal"; import TaskModal from "./TaskModal/TaskModal";
import {dateToISOLikeButLocal} from '../../helpers/CalendarHelpers'; import {dateToISOLikeButLocal} from '../../helpers/CalendarHelpers';
import DateTimePicker from "../Calendars/UI/DateTimePicker/DateTimePicker";
export default function NewTaskForm({ projects, setAddTaskForm }) { export default function NewTaskForm({ projects, setAddTaskForm }) {
console.log('new task form') console.log('new task form')
......
...@@ -22,6 +22,9 @@ import BasicSelect from "../../UI/Select/Select"; ...@@ -22,6 +22,9 @@ import BasicSelect from "../../UI/Select/Select";
import CalendarMonthIcon from '@mui/icons-material/CalendarMonth'; import CalendarMonthIcon from '@mui/icons-material/CalendarMonth';
import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown'; import KeyboardArrowDownIcon from '@mui/icons-material/KeyboardArrowDown';
import KeyboardArrowUpIcon from '@mui/icons-material/KeyboardArrowUp'; import KeyboardArrowUpIcon from '@mui/icons-material/KeyboardArrowUp';
import { useNavigate } from "react-router-dom";
import { useDispatch } from "react-redux";
import { activateCreateCopyTasksMode } from "../../../store/actions/tasksActions";
const weekDays = ["Вс","Пн","Вт","Ср","Чт","Пт","Сб" ]; const weekDays = ["Вс","Пн","Вт","Ср","Чт","Пт","Сб" ];
...@@ -42,7 +45,8 @@ const TableRowTask= ({ ...@@ -42,7 +45,8 @@ const TableRowTask= ({
})=>{ })=>{
const [open, setOpen] = React.useState(false); const [open, setOpen] = React.useState(false);
const navigate = useNavigate()
const dispatch = useDispatch()
const roudHourUp =(dateIso)=>{ const roudHourUp =(dateIso)=>{
let m = moment(dateIso); let m = moment(dateIso);
let roundUp = m.minute() || m.second() || m.millisecond() ? m.add(1, 'hour').startOf('hour') : m.startOf('hour'); let roundUp = m.minute() || m.second() || m.millisecond() ? m.add(1, 'hour').startOf('hour') : m.startOf('hour');
...@@ -59,7 +63,7 @@ const TableRowTask= ({ ...@@ -59,7 +63,7 @@ const TableRowTask= ({
return weekDays[date.day()]; return weekDays[date.day()];
} }
const calendarOpen=(taskId)=>{ const calendarOpen=(taskId)=>{
console.log('task Id in Calendar Open' , taskId) dispatch(activateCreateCopyTasksMode(task, navigate))
} }
return ( return (
...@@ -159,11 +163,11 @@ const TableRowTask= ({ ...@@ -159,11 +163,11 @@ const TableRowTask= ({
user:user user:user
}} }}
/> />
{task.isEditMode && task.author.id===user.id ? ( {task.dateTimeTasks.length === 0 && task.author.id === user.id ? (
<TableCell> <TableCell>
<Tooltip title="Перейти в календарь"> <Tooltip title="Перейти в календарь">
<IconButton <IconButton
onClick={() => { calendarOpen(task.id)}} onClick={() => { calendarOpen(task)}}
> >
<CalendarMonthIcon /> <CalendarMonthIcon />
</IconButton> </IconButton>
...@@ -172,7 +176,7 @@ const TableRowTask= ({ ...@@ -172,7 +176,7 @@ const TableRowTask= ({
</TableCell> </TableCell>
) : ( ) : (
task.dateTimeTasks.length>1 ? task.dateTimeTasks.length >= 1 ?
<TableCell> <TableCell>
<IconButton <IconButton
aria-label="expand row" aria-label="expand row"
...@@ -286,7 +290,7 @@ const TableRowTask= ({ ...@@ -286,7 +290,7 @@ const TableRowTask= ({
</TableCell>):null} </TableCell>):null}
</TableRow> </TableRow>
{task.dateTimeTasks.length>1? {task.dateTimeTasks.length>=1?
<TableRow> <TableRow>
<TableCell style={{ paddingBottom: 0, paddingTop: 0 }} colSpan={11}> <TableCell style={{ paddingBottom: 0, paddingTop: 0 }} colSpan={11}>
<Collapse in={open} timeout="auto" unmountOnExit> <Collapse in={open} timeout="auto" unmountOnExit>
......
...@@ -189,7 +189,6 @@ export default function EnhancedTable() { ...@@ -189,7 +189,6 @@ export default function EnhancedTable() {
setRecievedTasks(tasksFilteredByProject) setRecievedTasks(tasksFilteredByProject)
setFilterProjectTumbler(true) setFilterProjectTumbler(true)
} }
// if ( // if (
// tasks && // tasks &&
// tasks?.length > 0 // tasks?.length > 0
......
import moment from 'moment'; import moment from 'moment';
import { useEffect, useState, useMemo, useCallback } from 'react'; import { useEffect, useState, useMemo, useCallback } from 'react';
import { useDispatch, useSelector } from 'react-redux'; import { useDispatch, useSelector } from 'react-redux';
import { useNavigate } from 'react-router-dom';
import CreateCopyTasksModeBlock from '../../components/Calendars/CreateCopyTasksModeBlock/CreateCopyTasksModeBlock';
import CalendarModalWorkerContent from '../../components/Calendars/UI/CalendarModalWorkerContent/CalendarModalWorkerContent'; import CalendarModalWorkerContent from '../../components/Calendars/UI/CalendarModalWorkerContent/CalendarModalWorkerContent';
import WeekCalendarBody from '../../components/Calendars/WeekCalendar/WeekCalendarBody/WeekCalendarBody'; import WeekCalendarBody from '../../components/Calendars/WeekCalendar/WeekCalendarBody/WeekCalendarBody';
import WeekCalendarHeader from '../../components/Calendars/WeekCalendar/WeekCalendarHeader/WeekCalendarHeader'; import WeekCalendarHeader from '../../components/Calendars/WeekCalendar/WeekCalendarHeader/WeekCalendarHeader';
...@@ -8,15 +11,16 @@ import DefaultModal from '../../components/UI/DefaultModal/DefaultModal'; ...@@ -8,15 +11,16 @@ import DefaultModal from '../../components/UI/DefaultModal/DefaultModal';
import { AllHoursOneHourFormat, AllHoursTwoHourFormat } from '../../constants'; import { AllHoursOneHourFormat, AllHoursTwoHourFormat } from '../../constants';
import { getWeekInfoString, getWeekFromCurrentDate, dateToISOLikeButLocal } from '../../helpers/CalendarHelpers'; import { getWeekInfoString, getWeekFromCurrentDate, dateToISOLikeButLocal } from '../../helpers/CalendarHelpers';
import { fetchAllUserProjects } from '../../store/actions/projectsActions'; import { fetchAllUserProjects } from '../../store/actions/projectsActions';
import { addCalendarTask, addCopyCalendarTask, deleteCalendarTask, editCalendarTask, fetchCalendarTasks } from '../../store/actions/tasksActions'; import { addCalendarTask, addCopyCalendarTask, deactivateCreateCopyTasksMode, deleteCalendarTask, editCalendarTask, fetchCalendarTasks } from '../../store/actions/tasksActions';
import { fetchCurrentCalendarDisplayName } from '../../store/actions/usersActions'; import { fetchCurrentCalendarDisplayName } from '../../store/actions/usersActions';
function WeekCalendar() { function WeekCalendar() {
const dispatch = useDispatch(); const dispatch = useDispatch();
const { calendarTasks } = useSelector(state => state.tasks); const navigate = useNavigate()
const { calendarTasks, copyMode } = useSelector(state => state.tasks);
const { user, currentCalendarDisplayName } = useSelector(state => state.users); const { user, currentCalendarDisplayName } = useSelector(state => state.users);
const { allUserProjects, project } = useSelector(state => state.projects) const { allUserProjects } = useSelector(state => state.projects)
console.log(copyMode)
const [weekGoal, setWeekGoal] = useState('Наладить режим сна') const [weekGoal, setWeekGoal] = useState('Наладить режим сна')
const [weekPriorities, setWeekPriorities] = useState({ priorityOne: 'Один', priorityTwo: 'Два', priorityThree: 'Три' }) const [weekPriorities, setWeekPriorities] = useState({ priorityOne: 'Один', priorityTwo: 'Два', priorityThree: 'Три' })
const [workerInfo, setWorkerInfo] = useState({ project: '', worker: '' }); const [workerInfo, setWorkerInfo] = useState({ project: '', worker: '' });
...@@ -27,14 +31,15 @@ function WeekCalendar() { ...@@ -27,14 +31,15 @@ function WeekCalendar() {
const [userCalendarId, setUserCalendarId] = useState(null) const [userCalendarId, setUserCalendarId] = useState(null)
const [modal, setModal] = useState(false) const [modal, setModal] = useState(false)
const [userId, setUserId] = useState('') const [userId, setUserId] = useState('')
console.log(copyTask)
useEffect(() => { useEffect(() => {
const year = new Date().getFullYear() const year = new Date().getFullYear()
const month = new Date().getMonth() const month = new Date().getMonth()
const currentDay = moment().date() const currentDay = moment().date()
setDateNow({ year: year, month: month, currentDay: currentDay }) setDateNow({ year: year, month: month, currentDay: currentDay })
dispatch(fetchCalendarTasks(user.id)) return () => {
dispatch(fetchAllUserProjects()) dispatch(deactivateCreateCopyTasksMode())
}
}, [dispatch, user.id]) }, [dispatch, user.id])
useEffect(() => { useEffect(() => {
...@@ -200,6 +205,20 @@ function WeekCalendar() { ...@@ -200,6 +205,20 @@ function WeekCalendar() {
}, [currentTask, dispatch, user.id, userId]) }, [currentTask, dispatch, user.id, userId])
const createCopyTask = useCallback(async (dayNumber, hour, month, year) => { const createCopyTask = useCallback(async (dayNumber, hour, month, year) => {
if (copyMode.working) {
const hourDiff = hourFormat ? 0 : 1
const due = dateToISOLikeButLocal(new Date(year, month, dayNumber, hour + hourDiff, 59))
const start = dateToISOLikeButLocal(new Date(year, month, dayNumber, hour, 0))
const newTask = {
...copyMode.task,
dateTimeStart: start,
dateTimeDue: due,
taskId: copyMode.task.id
}
delete newTask.infoForCell
delete newTask.id
await dispatch(addCopyCalendarTask(newTask, userId))
} else {
const hourDiff = copyTask.infoForCell.endHour - copyTask.infoForCell.startHour const hourDiff = copyTask.infoForCell.endHour - copyTask.infoForCell.startHour
const lastHour = hoursInDay[hoursInDay.length - 1].split(':')[0] const lastHour = hoursInDay[hoursInDay.length - 1].split(':')[0]
let due let due
...@@ -219,7 +238,8 @@ function WeekCalendar() { ...@@ -219,7 +238,8 @@ function WeekCalendar() {
delete newTask.id delete newTask.id
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
...@@ -243,8 +263,10 @@ function WeekCalendar() { ...@@ -243,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(() => {
...@@ -260,6 +282,15 @@ function WeekCalendar() { ...@@ -260,6 +282,15 @@ function WeekCalendar() {
setUserCalendarId(null) setUserCalendarId(null)
} }
}, [dispatch, user.id, userId]) }, [dispatch, user.id, userId])
const copyModeStay = useCallback(async () => {
dispatch(deactivateCreateCopyTasksMode())
}, [dispatch])
const copyModeReturn = useCallback(async () => {
navigate('/my-tasks')
}, [navigate])
return ( return (
<> <>
<DefaultModal <DefaultModal
...@@ -307,6 +338,13 @@ function WeekCalendar() { ...@@ -307,6 +338,13 @@ function WeekCalendar() {
copyTask={copyTask} copyTask={copyTask}
setCopyTask={setCopyTask} setCopyTask={setCopyTask}
dragTaskHandler={dragTaskHandler} dragTaskHandler={dragTaskHandler}
copyMode={copyMode}
/>
<CreateCopyTasksModeBlock
copyMode={copyMode.working}
copyModeStay={() => { copyModeStay() }}
copyModeReturn={() => { copyModeReturn() }}
/> />
</> </>
); );
......
...@@ -29,3 +29,6 @@ export const DELETE_DATETIMETASK_FAILURE = "DELETE_TASK_FAILURE"; ...@@ -29,3 +29,6 @@ export const DELETE_DATETIMETASK_FAILURE = "DELETE_TASK_FAILURE";
export const FETCH_ALL_TASKS_BY_MEMBERSHIP_REQUEST = "FETCH_ALL_TASKS_BY_MEMBERSHIP_REQUEST"; export const FETCH_ALL_TASKS_BY_MEMBERSHIP_REQUEST = "FETCH_ALL_TASKS_BY_MEMBERSHIP_REQUEST";
export const FETCH_ALL_TASKS_BY_MEMBERSHIP_SUCCESS = "FETCH_ALL_TASKS_BY_MEMBERSHIP_SUCCESS"; export const FETCH_ALL_TASKS_BY_MEMBERSHIP_SUCCESS = "FETCH_ALL_TASKS_BY_MEMBERSHIP_SUCCESS";
export const FETCH_ALL_TASKS_BY_MEMBERSHIP_FAILURE = "FETCH_ALL_TASKS_BY_MEMBERSHIP_FAILURE"; export const FETCH_ALL_TASKS_BY_MEMBERSHIP_FAILURE = "FETCH_ALL_TASKS_BY_MEMBERSHIP_FAILURE";
export const ACTIVATE_CREATE_COPY_TASKS_MODE = "ACTIVATE_CREATE_COPY_TASKS_MODE"
export const DEACTIVATE_CREATE_COPY_TASKS_MODE = "DEACTIVATE_CREATE_COPY_TASKS_MODE"
\ No newline at end of file
...@@ -18,7 +18,9 @@ import { ...@@ -18,7 +18,9 @@ import {
DELETE_DATETIMETASK_FAILURE, DELETE_DATETIMETASK_FAILURE,
DELETE_DATETIMETASK_SUCCESS, DELETE_DATETIMETASK_SUCCESS,
DELETE_DATETIMETASK_REQUEST, DELETE_DATETIMETASK_REQUEST,
FETCH_ALL_TASKS_BY_MEMBERSHIP_SUCCESS FETCH_ALL_TASKS_BY_MEMBERSHIP_SUCCESS,
DEACTIVATE_CREATE_COPY_TASKS_MODE,
ACTIVATE_CREATE_COPY_TASKS_MODE
} from "../actionTypes/tasksTypes"; } from "../actionTypes/tasksTypes";
import axios from '../../axiosPlanner' import axios from '../../axiosPlanner'
...@@ -295,3 +297,12 @@ export const addTaskToUserTasksTable = (task) => { ...@@ -295,3 +297,12 @@ export const addTaskToUserTasksTable = (task) => {
} }
/** end */ /** end */
export const activateCreateCopyTasksMode = (task, navigate) => {
navigate('/')
return {type: ACTIVATE_CREATE_COPY_TASKS_MODE, task}
}
export const deactivateCreateCopyTasksMode = () => {
return {type: DEACTIVATE_CREATE_COPY_TASKS_MODE}
}
\ No newline at end of file
...@@ -18,10 +18,17 @@ import { ...@@ -18,10 +18,17 @@ import {
DELETE_DATETIMETASK_FAILURE, DELETE_DATETIMETASK_FAILURE,
DELETE_DATETIMETASK_SUCCESS, DELETE_DATETIMETASK_SUCCESS,
DELETE_DATETIMETASK_REQUEST, DELETE_DATETIMETASK_REQUEST,
FETCH_ALL_TASKS_BY_MEMBERSHIP_SUCCESS FETCH_ALL_TASKS_BY_MEMBERSHIP_SUCCESS,
ACTIVATE_CREATE_COPY_TASKS_MODE,
DEACTIVATE_CREATE_COPY_TASKS_MODE
} from "../actionTypes/tasksTypes"; } from "../actionTypes/tasksTypes";
const initialState = { const initialState = {
copyMode: {
working: false,
task: null,
},
tasks: [],
calendarTasks: [], calendarTasks: [],
loading: false, loading: false,
error: null, error: null,
...@@ -42,6 +49,7 @@ const tasksReduсer = (state = initialState, action) => { ...@@ -42,6 +49,7 @@ const tasksReduсer = (state = initialState, action) => {
mainTaskId: task.id, mainTaskId: task.id,
executor: task.executor, executor: task.executor,
author: task.author, author: task.author,
dateTimeDeadLine: task.dateTimeDeadLine,
priority: task.priority, priority: task.priority,
title: task.title, title: task.title,
description: task.description description: task.description
...@@ -114,6 +122,10 @@ const tasksReduсer = (state = initialState, action) => { ...@@ -114,6 +122,10 @@ const tasksReduсer = (state = initialState, action) => {
return {...state, loading: true}; return {...state, loading: true};
case DELETE_DATETIMETASK_FAILURE: case DELETE_DATETIMETASK_FAILURE:
return {...state, loading: false, error: action.error}; return {...state, loading: false, error: action.error};
case ACTIVATE_CREATE_COPY_TASKS_MODE:
return {...state, copyMode: {working: true, task: action.task}}
case DEACTIVATE_CREATE_COPY_TASKS_MODE:
return {...state, copyMode: {working: false, task: null}}
default: default:
return state; return state;
} }
......
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