Commit 346a5a8c authored by Ermolaev Timur's avatar Ermolaev Timur

#78 Небольшие фиксы\

parent 6ab13d0f
...@@ -28,25 +28,21 @@ const taskFinderById = async (taskId:string):Promise<null | Task>=>{ ...@@ -28,25 +28,21 @@ 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 = start newDateTimeTask.dateTimeStart = dateTimeStart
newDateTimeTask.dateTimeDue = due newDateTimeTask.dateTimeDue = dateTimeDue
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", async(req:Request, res: Response):Promise<Response>=>{ router.put("/change-copy", authAuthorOrExecutorOfTask, async(req:Request, res: Response):Promise<Response>=>{
console.log('change') const {dateTimeTaskId, taskId, dateTimeStart, dateTimeDue, description, title, priority} = req.body
const {dateTimeTaskId,taskId, dateTimeStart, dateTimeDue} = req.body
console.log(req.body)
const dateTimeTask = await dataSource const dateTimeTask = await dataSource
.createQueryBuilder() .createQueryBuilder()
.select('dateTimeTask') .select('dateTimeTask')
...@@ -56,11 +52,14 @@ router.put("/change-copy", async(req:Request, res: Response):Promise<Response>=> ...@@ -56,11 +52,14 @@ router.put("/change-copy", async(req:Request, res: Response):Promise<Response>=>
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=dateTimeStart
dateTimeTask.dateTimeDue=dateTimeDue dateTimeTask.dateTimeDue=dateTimeDue
console.log(dateTimeTask)
await dateTimeTask.save() await dateTimeTask.save()
const task = taskFinderById(taskId) const task = await taskFinderById(taskId)
if (!task) return res.status(404).send({Message:'task not found'})
task.title = title;
task.description = description;
task.priority = priority;
await task.save()
return res.send({task}) return res.send({task})
}) })
export default router; export default router;
...@@ -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,7 +3,7 @@ import { useDispatch, useSelector } from 'react-redux'; ...@@ -3,7 +3,7 @@ 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();
...@@ -65,7 +65,6 @@ function MonthCalendar() { ...@@ -65,7 +65,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 +134,15 @@ function MonthCalendar() { ...@@ -135,13 +134,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({})
} }
...@@ -153,18 +154,20 @@ function MonthCalendar() { ...@@ -153,18 +154,20 @@ function MonthCalendar() {
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 = { const newTask = {
...currentTask, ...currentTask,
dateTimeTaskId: currentTask.id,
dateTimeStart: start, dateTimeStart: start,
dateTimeDue: due dateTimeDue: due,
dateTimeTaskId: currentTask.id,
taskId: currentTask.mainTaskId
} }
delete newTask.id
delete newTask.infoForCell delete newTask.infoForCell
delete newTask.id
if (newTask.dateTimeTaskId) { if (newTask.dateTimeTaskId) {
await dispatch(editCalendarTask(newTask)) await dispatch(editCalendarTask(newTask))
} else { } else {
await dispatch(addCalendarTask(newTask)) await dispatch(addCalendarTask(newTask))
} }
} }
console.log(currentTask)
const createCopyTask = async (dayNumber, hour) => { const createCopyTask = async (dayNumber, hour) => {
const hourDiff = copyTask.infoForCell.endHour - copyTask.infoForCell.startHour const hourDiff = copyTask.infoForCell.endHour - copyTask.infoForCell.startHour
...@@ -180,10 +183,11 @@ function MonthCalendar() { ...@@ -180,10 +183,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,33 +71,32 @@ const addTaskFailure = (error) => { ...@@ -71,33 +71,32 @@ const addTaskFailure = (error) => {
}; };
export const addCalendarTask = (task) => { export const addCalendarTask = (task) => {
return async (dispatch, getState) => { return async (dispatch) => {
dispatch(addTaskRequest()); dispatch(addTaskRequest());
try { try {
const response = await axios.post("/tasks", task); const response = await axios.post("/tasks", task);
dispatch(addTaskSuccess()) dispatch(addTaskSuccess())
dispatch(fetchCalendarTasks()) dispatch(fetchCalendarTasks())
console.log(response.data)
} catch (error) { } catch (error) {
dispatch(addTaskFailure(error.response.data)); dispatch(addTaskFailure(error.response.data));
} }
} }
} }
export const addTask = (task) => { export const addCopyCalendarTask = (task) => {
return async (dispatch) => { return async (dispatch) => {
dispatch(addTaskRequest()); dispatch(addTaskRequest());
try { try {
await axios.post("/tasks", task); const response = await axios.post("/copy-tasks/make-copy", task);
dispatch(addTaskSuccess()) dispatch(addTaskSuccess())
dispatch(fetchAllTasks()) dispatch(fetchCalendarTasks())
} catch (error) { } catch (error) {
dispatch(addTaskFailure(error.response.data)); dispatch(addTaskFailure(error.response.data));
} }
} }
} }
export const addCopyTask = (task) => { export const addTask = (task) => {
return async (dispatch) => { return async (dispatch) => {
dispatch(addTaskRequest()); dispatch(addTaskRequest());
try { try {
...@@ -123,10 +122,10 @@ const editTaskFailure = (error) => { ...@@ -123,10 +122,10 @@ 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("/change-copy", task); await axios.put("/tasks", task);
dispatch(editTaskSuccess()) dispatch(editTaskSuccess())
dispatch(fetchAllTasks()) dispatch(fetchAllTasks())
} catch (error) { } catch (error) {
...@@ -136,7 +135,7 @@ export const editTask = (task) => { ...@@ -136,7 +135,7 @@ 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("/copy-tasks/change-copy", task); await axios.put("/copy-tasks/change-copy", task);
...@@ -161,7 +160,7 @@ const deleteTaskFailure = (error) => { ...@@ -161,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}`);
...@@ -174,10 +173,10 @@ export const deleteTask = (taskId) => { ...@@ -174,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) {
......
...@@ -35,6 +35,7 @@ const tasksReduсer = (state = initialState, action) => { ...@@ -35,6 +35,7 @@ const tasksReduсer = (state = initialState, action) => {
for (let copy of task.dateTimeTasks) { for (let copy of task.dateTimeTasks) {
newTasksWithoutInfoForCell.push({ newTasksWithoutInfoForCell.push({
...copy, ...copy,
mainTaskId: task.id,
executor: task.executor, executor: task.executor,
author: task.author, author: task.author,
priority: task.priority, priority: task.priority,
......
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