Commit 2cfef1f4 authored by Ermolaev Timur's avatar Ermolaev Timur

Merge branch 'task-152-fix/fix_bugs_in_table_users' into 'development'

#152 Пофиксил неправильное поведение с выбором дедлайн и баг

See merge request !120
parents 046e41c0 8794a830
...@@ -16,10 +16,10 @@ ...@@ -16,10 +16,10 @@
"@testing-library/user-event": "^13.5.0", "@testing-library/user-event": "^13.5.0",
"axios": "^1.1.2", "axios": "^1.1.2",
"dayjs": "^1.11.6", "dayjs": "^1.11.6",
"react-datepicker": "^4.8.0",
"moment": "^2.29.4", "moment": "^2.29.4",
"prop-types": "^15.8.1", "prop-types": "^15.8.1",
"react": "^18.2.0", "react": "^18.2.0",
"react-datepicker": "^4.8.0",
"react-dom": "^18.2.0", "react-dom": "^18.2.0",
"react-redux": "^8.0.4", "react-redux": "^8.0.4",
"react-router-dom": "^6.4.2", "react-router-dom": "^6.4.2",
......
import React from "react"; import React, { useEffect, useState } from "react";
import TextField from "@mui/material/TextField"; import TextField from "@mui/material/TextField";
import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider"; import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider";
import { DateTimePicker } from "@mui/x-date-pickers/DateTimePicker"; import { DateTimePicker } from "@mui/x-date-pickers/DateTimePicker";
...@@ -9,10 +9,17 @@ import moment from "moment"; ...@@ -9,10 +9,17 @@ import moment from "moment";
export default function MaterialUIPickers({task, name, onChange }) { export default function MaterialUIPickers({ task, name, onChange, currentTask }) {
const [state, setState] = useState(null)
let fullYear = new Date().getFullYear() let fullYear = new Date().getFullYear()
let month = new Date().getMonth() let month = new Date().getMonth()
let day = new Date().getDate(); let day = new Date().getDate();
useEffect(() => {
if (!task.dateTimeDeadLine) setState(null)
if (currentTask) setState(moment(task.dateTimeDeadLine).utc())
}, [task.dateTimeDeadLine, currentTask])
return ( return (
<LocalizationProvider <LocalizationProvider
dateAdapter={AdapterMoment} dateAdapter={AdapterMoment}
...@@ -20,23 +27,25 @@ export default function MaterialUIPickers({task, name, onChange }) { ...@@ -20,23 +27,25 @@ export default function MaterialUIPickers({task, name, onChange }) {
adapterLocale={'ru-RU'} adapterLocale={'ru-RU'}
> >
<DateTimePicker <DateTimePicker
minTime={moment({year:fullYear,month:month,day:day ,hour:11,minute:0})}
maxTime={moment({year:fullYear,month:month,day:day ,hour:20,minute:0})}
disablePast={true} disablePast={true}
showTimeSelect={true} showTimeSelect={true}
minutesStep={60} minutesStep={60}
ampm={false} ampm={false}
ampmInClock={false} ampmInClock={false}
inputFormat="DD/MM/YY HH:mm" inputFormat="DD/MM/YY HH:mm"
renderInput={(params) =>{ return ( renderInput={(params) => {
return (
<TextField <TextField
{...params} {...params}
sx={{ width: "auto", fontWeight: "200", fontSize: 5 }} sx={{ width: "auto", fontWeight: "200", fontSize: 5 }}
name={name} name={name}
value={moment(task.dateTimeDeadLine).utc()}
/> />
)}} )
value={task.dateTimeDeadLine} }}
value={state}
onChange={(newValue) => { onChange={(newValue) => {
setState(newValue)
onChange(newValue, name); onChange(newValue, name);
}} }}
/> />
......
...@@ -100,16 +100,17 @@ function EditRow({ buttons, dateTimeTasks, onChangeCurrentTaskHandler, currentTa ...@@ -100,16 +100,17 @@ function EditRow({ buttons, dateTimeTasks, onChangeCurrentTaskHandler, currentTa
</TableCell> </TableCell>
<TableCell sx={{ width: '8%' }}>{currentTask.authorName}</TableCell> <TableCell sx={{ width: '8%' }}>{currentTask.authorName}</TableCell>
<TableCell sx={{ width: '15%' }}> <TableCell sx={{ width: '13%' }}>
{dateTimeTasks} {dateTimeTasks}
</TableCell> </TableCell>
<TableCell sx={{ width: '10%' }}> <TableCell sx={{ width: '12%' }}>
{user.id === currentTask.author.id ? {user.id === currentTask.author.id ?
<MaterialUIPickers <MaterialUIPickers
task={currentTask} task={currentTask}
name="dateTimeDeadLine" name="dateTimeDeadLine"
onChange={onDateChangeEditHandler} onChange={onDateChangeEditHandler}
currentTask={true}
/> />
: currentTask.dateTimeDeadLine ? moment(currentTask.dateTimeDeadLine).utc().format('DD.MM.YYYY HH:MM') : null} : currentTask.dateTimeDeadLine ? moment(currentTask.dateTimeDeadLine).utc().format('DD.MM.YYYY HH:MM') : null}
</TableCell> </TableCell>
......
...@@ -31,7 +31,12 @@ function UsersTasksRow({ row, deleteTaskHandler, calendarOpen, deleteCopyTaskHan ...@@ -31,7 +31,12 @@ function UsersTasksRow({ row, deleteTaskHandler, calendarOpen, deleteCopyTaskHan
if (row.dateTimeTasks.length === 1) { if (row.dateTimeTasks.length === 1) {
const date = moment(row.dateTimeTasks[0].dateTimeStart).utc().format('DD.MM') const date = moment(row.dateTimeTasks[0].dateTimeStart).utc().format('DD.MM')
const start = moment(row.dateTimeTasks[0].dateTimeStart).utc().format('HH:mm') const start = moment(row.dateTimeTasks[0].dateTimeStart).utc().format('HH:mm')
const end = moment(row.dateTimeTasks[0].dateTimeDue).utc().add(1, 'minutes').format('HH:mm') let end
if (new Date(row.dateTimeTasks[0].dateTimeDue).getMinutes() === 59 ) {
end = moment(row.dateTimeTasks[0].dateTimeDue).utc().add(1, 'minutes').format('HH:mm')
} else {
end = moment(row.dateTimeTasks[0].dateTimeDue).utc().format('HH:mm')
}
const diff = parseInt(end.split(':')[0]) - parseInt(start.split(':')[0]) const diff = parseInt(end.split(':')[0]) - parseInt(start.split(':')[0])
return <Box sx={{ width: '90%', display: 'flex' }}> return <Box sx={{ width: '90%', display: 'flex' }}>
<Tooltip title={moment(row.dateTimeTasks[0].dateTimeStart).utc().format('YYYY')}> <Tooltip title={moment(row.dateTimeTasks[0].dateTimeStart).utc().format('YYYY')}>
...@@ -123,12 +128,12 @@ function UsersTasksRow({ row, deleteTaskHandler, calendarOpen, deleteCopyTaskHan ...@@ -123,12 +128,12 @@ function UsersTasksRow({ row, deleteTaskHandler, calendarOpen, deleteCopyTaskHan
if (editMode) { if (editMode) {
return <Done sx={editClass} onClick={() => { onClickEditButtonHandler() }} /> return <Done sx={editClass} onClick={() => { onClickEditButtonHandler() }} />
} else { } else {
if (user.id === row.author.id) { if (user.id === row?.author?.id) {
return (<> return (<>
<Edit sx={{ ...editClass, position: 'absolute', left: -10 }} onClick={() => { onClickEditButtonHandler() }} /> <Edit sx={{ ...editClass, position: 'absolute', left: -10 }} onClick={() => { onClickEditButtonHandler() }} />
<DeleteButton onClick={() => { deleteTaskHandler(row.id) }} /> <DeleteButton onClick={() => { deleteTaskHandler(row.id) }} />
</>) </>)
} else if (user.id === row.executor.id) { } else if (user.id === row?.executor?.id) {
return (<Edit sx={editClass} onClick={() => { onClickEditButtonHandler() }} />) return (<Edit sx={editClass} onClick={() => { onClickEditButtonHandler() }} />)
} else { } else {
return null return null
...@@ -167,11 +172,11 @@ function UsersTasksRow({ row, deleteTaskHandler, calendarOpen, deleteCopyTaskHan ...@@ -167,11 +172,11 @@ function UsersTasksRow({ row, deleteTaskHandler, calendarOpen, deleteCopyTaskHan
<TableCell sx={{ width: '8%' }}>{row.executorName}</TableCell> <TableCell sx={{ width: '8%' }}>{row.executorName}</TableCell>
<TableCell sx={{ width: '8%' }}>{row.authorName}</TableCell> <TableCell sx={{ width: '8%' }}>{row.authorName}</TableCell>
<TableCell sx={{ width: '15%' }}> <TableCell sx={{ width: '13%' }}>
{dateTimeTasks} {dateTimeTasks}
</TableCell> </TableCell>
<TableCell sx={{ width: '10%' }}>{row.dateTimeDeadLine ? moment(row.dateTimeDeadLine).utc().format('DD.MM.YYYY HH:MM') : null}</TableCell> <TableCell sx={{ width: '12%' }}>{row.dateTimeDeadLine ? moment(row.dateTimeDeadLine).utc().format('DD.MM.YYYY HH:mm') : null}</TableCell>
<TableCell sx={{ width: '7%' }}> <TableCell sx={{ width: '7%' }}>
{row.accomplishTranslate} {row.accomplishTranslate}
</TableCell> </TableCell>
......
...@@ -150,7 +150,7 @@ export default function EnhancedTable() { ...@@ -150,7 +150,7 @@ export default function EnhancedTable() {
const calendarOpen = (task) => { const calendarOpen = (task) => {
dispatch(activateCreateCopyTasksMode(task, navigate)) dispatch(activateCreateCopyTasksMode(task, navigate))
} }
console.log(currentTask)
const editCurrentTaskHandler = useCallback(() => { const editCurrentTaskHandler = useCallback(() => {
if (currentTask.priority === '' || currentTask.project === '' || currentTask.executor === '' || !Object.keys(currentTask.executor).length) { if (currentTask.priority === '' || currentTask.project === '' || currentTask.executor === '' || !Object.keys(currentTask.executor).length) {
const task = { const task = {
......
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