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>=>{
}
/** make copy of task in calendar view */
router.post("/make-copy",authAuthorOrExecutorOfTask, async(req:Request, res:Response):Promise<Response>=>{
const {executorStatus,taskId,start, due} = req.body
if (executorStatus){
router.post("/make-copy", async(req:Request, res:Response):Promise<Response>=>{
const {taskId, dateTimeDue, dateTimeStart} = req.body
const newDateTimeTask = new DateTimeTask();
newDateTimeTask.dateTimeStart = start
newDateTimeTask.dateTimeDue = due
newDateTimeTask.dateTimeStart = dateTimeStart
newDateTimeTask.dateTimeDue = dateTimeDue
newDateTimeTask.task = taskId
await newDateTimeTask.save()
const task = taskFinderById(taskId)
return res.send({task})
}
return res.send({message :"Something wrong in make-copy router"})
} )
/** change date time of copy of task in calendar view */
router.put("/change-copy", async(req:Request, res: Response):Promise<Response>=>{
console.log('change')
const {dateTimeTaskId,taskId, dateTimeStart, dateTimeDue} = req.body
console.log(req.body)
router.put("/change-copy", authAuthorOrExecutorOfTask, async(req:Request, res: Response):Promise<Response>=>{
const {dateTimeTaskId, taskId, dateTimeStart, dateTimeDue, description, title, priority} = req.body
const dateTimeTask = await dataSource
.createQueryBuilder()
.select('dateTimeTask')
......@@ -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"})
dateTimeTask.dateTimeStart=dateTimeStart
dateTimeTask.dateTimeDue=dateTimeDue
console.log(dateTimeTask)
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})
})
export default router;
......@@ -8,7 +8,7 @@ const CalendarStandartCell = ({children, xs, hours, dayNumber, createTaskInCell
const [isThisCell, setIsThisCell] = useState(false)
const cellClass = {
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',
}
useEffect(()=>{
......
......@@ -3,7 +3,7 @@ import { useDispatch, useSelector } from 'react-redux';
import MonthCalendarBody from '../../components/MonthCalendarBody/MonthCalendarBody';
import MonthCalendarHeader from '../../components/MonthCalendarHeader/MonthCalendarHeader';
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() {
const dispatch = useDispatch();
......@@ -65,7 +65,6 @@ function MonthCalendar() {
return {...prevState, month: prevState.month + 1}
})
}, [])
console.log(currentTask)
const decrementMonth = useCallback(() => {
setDateNow((prevState)=>{
if (prevState.month - 1 === -1) {
......@@ -135,13 +134,15 @@ function MonthCalendar() {
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 newObj = {
const newTask = {
...currentTask,
dateTimeTaskId: currentTask.id,
dateTimeStart: start,
dateTimeDue: due
}
delete newObj.infoForCell
await dispatch(editCalendarTask(newObj))
delete newTask.id
delete newTask.infoForCell
await dispatch(editCalendarTask(newTask))
setCurrentTask({})
}
......@@ -153,18 +154,20 @@ function MonthCalendar() {
const start = dateToISOLikeButLocal(new Date(dateNow.year, dateNow.month, day, timeStartHour, 0))
const newTask = {
...currentTask,
dateTimeTaskId: currentTask.id,
dateTimeStart: start,
dateTimeDue: due
dateTimeDue: due,
dateTimeTaskId: currentTask.id,
taskId: currentTask.mainTaskId
}
delete newTask.id
delete newTask.infoForCell
delete newTask.id
if (newTask.dateTimeTaskId) {
await dispatch(editCalendarTask(newTask))
} else {
await dispatch(addCalendarTask(newTask))
}
}
console.log(currentTask)
const createCopyTask = async (dayNumber, hour) => {
const hourDiff = copyTask.infoForCell.endHour - copyTask.infoForCell.startHour
......@@ -180,10 +183,11 @@ function MonthCalendar() {
...copyTask,
dateTimeStart: start,
dateTimeDue: due,
taskId: copyTask.mainTaskId
}
delete newTask.infoForCell
delete newTask.id
await dispatch(addCalendarTask(newTask))
await dispatch(addCopyCalendarTask(newTask))
setCopyTask(null)
}
......
......@@ -71,33 +71,32 @@ const addTaskFailure = (error) => {
};
export const addCalendarTask = (task) => {
return async (dispatch, getState) => {
return async (dispatch) => {
dispatch(addTaskRequest());
try {
const response = await axios.post("/tasks", task);
dispatch(addTaskSuccess())
dispatch(fetchCalendarTasks())
console.log(response.data)
} catch (error) {
dispatch(addTaskFailure(error.response.data));
}
}
}
export const addTask = (task) => {
export const addCopyCalendarTask = (task) => {
return async (dispatch) => {
dispatch(addTaskRequest());
try {
await axios.post("/tasks", task);
const response = await axios.post("/copy-tasks/make-copy", task);
dispatch(addTaskSuccess())
dispatch(fetchAllTasks())
dispatch(fetchCalendarTasks())
} catch (error) {
dispatch(addTaskFailure(error.response.data));
}
}
}
export const addCopyTask = (task) => {
export const addTask = (task) => {
return async (dispatch) => {
dispatch(addTaskRequest());
try {
......@@ -123,10 +122,10 @@ const editTaskFailure = (error) => {
};
export const editTask = (task) => {
return async (dispatch, getState) => {
return async (dispatch) => {
dispatch(editTaskRequest());
try {
await axios.put("/change-copy", task);
await axios.put("/tasks", task);
dispatch(editTaskSuccess())
dispatch(fetchAllTasks())
} catch (error) {
......@@ -136,7 +135,7 @@ export const editTask = (task) => {
}
export const editCalendarTask = (task) => {
return async (dispatch, getState) => {
return async (dispatch) => {
dispatch(editTaskRequest());
try {
await axios.put("/copy-tasks/change-copy", task);
......@@ -161,7 +160,7 @@ const deleteTaskFailure = (error) => {
};
export const deleteTask = (taskId) => {
return async (dispatch, getState) => {
return async (dispatch) => {
dispatch(deleteTaskRequest());
try {
await axios.delete(`/tasks/${taskId}`);
......@@ -174,10 +173,10 @@ export const deleteTask = (taskId) => {
}
export const deleteCalendarTask = (taskId) => {
return async (dispatch, getState) => {
return async (dispatch) => {
dispatch(deleteTaskRequest());
try {
await axios.delete(`/tasks/${taskId}`);
await axios.delete(`/copy-tasks/${taskId}`);
dispatch(deleteTaskSuccess())
dispatch(fetchCalendarTasks())
} catch (error) {
......
......@@ -35,6 +35,7 @@ const tasksReduсer = (state = initialState, action) => {
for (let copy of task.dateTimeTasks) {
newTasksWithoutInfoForCell.push({
...copy,
mainTaskId: task.id,
executor: task.executor,
author: task.author,
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