Commit 17b16f74 authored by Ermolaev Timur's avatar Ermolaev Timur

#135 Реализовал создание копий задачи

parent ad2aeb04
...@@ -21,10 +21,10 @@ const CreateCopyTasksModeBlock = ({ copyMode, copyModeReturn, copyModeStay }) = ...@@ -21,10 +21,10 @@ const CreateCopyTasksModeBlock = ({ copyMode, copyModeReturn, copyModeStay }) =
return (<> return (<>
{copyMode ? {copyMode ?
<Box sx={style}> <Box sx={style}>
<Button onClick={copyModeStay}> <Button onClick={copyModeStay} sx={{fontWeight: 800}}>
Остаться Остаться
</Button> </Button>
<Button onClick={copyModeReturn}> <Button onClick={copyModeReturn} sx={{fontWeight: 800}}>
Вернуться Вернуться
</Button> </Button>
</Box> </Box>
......
...@@ -3,7 +3,7 @@ import { memo, useEffect, useState } from "react"; ...@@ -3,7 +3,7 @@ import { memo, useEffect, 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 }) => {
const [isThisCell, setIsThisCell] = useState(false) const [isThisCell, setIsThisCell] = useState(false)
const [top, setTop] = useState(0) const [top, setTop] = useState(0)
const cellClass = { const cellClass = {
...@@ -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) { if (copyTask || copyMode.working) {
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);
......
...@@ -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 }) {
const [columnDaySize, setColumnDaySize] = useState({ width: 0, height: 0 }) const [columnDaySize, setColumnDaySize] = useState({ width: 0, height: 0 })
...@@ -84,6 +84,7 @@ function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat ...@@ -84,6 +84,7 @@ function CalendarColumnDayWeek({ hoursInDay, tasks, month, year, day, hourFormat
month={month} month={month}
year={year} year={year}
dragTaskHandler={dragTaskHandler} dragTaskHandler={dragTaskHandler}
copyMode={copyMode}
> >
</CalendarStandartCell> </CalendarStandartCell>
) )
......
...@@ -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: copyMode ? '100px' : '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,7 @@ function WeekCalendarBody({ week, hoursInDay, hourFormat, setHourFormat, date, t ...@@ -84,6 +84,7 @@ function WeekCalendarBody({ week, hoursInDay, hourFormat, setHourFormat, date, t
setCopyTask={setCopyTask} setCopyTask={setCopyTask}
createCopyTask={createCopyTask} createCopyTask={createCopyTask}
dragTaskHandler={dragTaskHandler} dragTaskHandler={dragTaskHandler}
copyMode={copyMode}
/> />
) )
})} })}
......
...@@ -19,7 +19,7 @@ function WeekCalendar() { ...@@ -19,7 +19,7 @@ function WeekCalendar() {
const navigate = useNavigate() const navigate = useNavigate()
const { calendarTasks, copyMode } = useSelector(state => state.tasks); const { calendarTasks, copyMode } = useSelector(state => state.tasks);
const { user, currentCalendarDisplayName } = useSelector(state => state.users); const { user, currentCalendarDisplayName } = useSelector(state => state.users);
const { allUserProjects} = useSelector(state => state.projects) const { allUserProjects } = useSelector(state => state.projects)
console.log(copyMode) 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: 'Три' })
...@@ -31,13 +31,13 @@ function WeekCalendar() { ...@@ -31,13 +31,13 @@ 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 })
return () =>{ return () => {
dispatch(deactivateCreateCopyTasksMode()) dispatch(deactivateCreateCopyTasksMode())
} }
}, [dispatch, user.id]) }, [dispatch, user.id])
...@@ -205,6 +205,20 @@ function WeekCalendar() { ...@@ -205,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
...@@ -224,6 +238,7 @@ function WeekCalendar() { ...@@ -224,6 +238,7 @@ 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])
const dragTaskHandler = useCallback(async (dayNumber, hour, month, year) => { const dragTaskHandler = useCallback(async (dayNumber, hour, month, year) => {
...@@ -321,13 +336,13 @@ function WeekCalendar() { ...@@ -321,13 +336,13 @@ function WeekCalendar() {
copyTask={copyTask} copyTask={copyTask}
setCopyTask={setCopyTask} setCopyTask={setCopyTask}
dragTaskHandler={dragTaskHandler} dragTaskHandler={dragTaskHandler}
copyMode={copyMode.working} copyMode={copyMode}
/> />
<CreateCopyTasksModeBlock <CreateCopyTasksModeBlock
copyMode={copyMode.working} copyMode={copyMode.working}
copyModeStay={()=>{copyModeStay()}} copyModeStay={() => { copyModeStay() }}
copyModeReturn={()=>{copyModeReturn()}} copyModeReturn={() => { copyModeReturn() }}
/> />
</> </>
); );
......
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