Commit d33a0a95 authored by Ermolaev Timur's avatar Ermolaev Timur

#149 Полностью завершил добавление задачи и еще реализовал удаление задачи

parent 29bd3775
...@@ -3,7 +3,6 @@ import TextField from "@mui/material/TextField"; ...@@ -3,7 +3,6 @@ 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";
import { AdapterMoment } from "@mui/x-date-pickers/AdapterMoment"; import { AdapterMoment } from "@mui/x-date-pickers/AdapterMoment";
import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
import moment from "moment"; import moment from "moment";
......
import { Box, Divider, Grid, IconButton, TextField, Typography, } from "@mui/material"; import { Box, Divider, Grid, IconButton, TextField, Tooltip, Typography, } from "@mui/material";
import { styled } from '@mui/material/styles';
import { memo, useMemo } from "react"; import { memo, useMemo } from "react";
import { priorities } from "../../../../constants"; import { priorities } from "../../../../constants";
import CustomSelect from "../../../UI/СustomSelect/СustomSelect" import CustomSelect from "../../../UI/СustomSelect/СustomSelect"
import MaterialUIPickers from "./DateTimePicker/DateTimePicker"; import MaterialUIPickers from "./DateTimePicker/DateTimePicker";
import { Save } from "@mui/icons-material"; import { Save } from "@mui/icons-material";
import { isValidate } from "./helpers";
const StyledTooltip = styled(({ className, ...props }) => (
<Tooltip {...props} classes={{ popper: className }} />
))`
& .MuiTooltip-tooltip {
background: white;
}
`;
function NewTaskForm({ addFormStatus, onChangeNewTaskHandler, newTask, allUserProjectsForModalTask, onDateChange, createNewTaskHandler }) { function NewTaskForm({ addFormStatus, onChangeNewTaskHandler, newTask, allUserProjectsForModalTask, onDateChange, createNewTaskHandler }) {
const workers = useMemo(()=>{ const workers = useMemo(() => {
if (newTask?.project) { if (newTask?.project) {
return newTask?.project?.members.map((member)=>{return {value: member.user, text: member.user.displayName}}) return newTask?.project?.members.map((member) => { return { value: member.user, text: member.user.displayName } })
} else { } else {
return [{value: '', text: 'Выберите проект'}] return [{ value: '', text: 'Выберите проект' }]
} }
},[newTask?.project]) }, [newTask?.project])
return ( return (
...@@ -52,6 +64,19 @@ function NewTaskForm({ addFormStatus, onChangeNewTaskHandler, newTask, allUserPr ...@@ -52,6 +64,19 @@ function NewTaskForm({ addFormStatus, onChangeNewTaskHandler, newTask, allUserPr
/> />
</Grid> </Grid>
<Grid item xs={3.5}> <Grid item xs={3.5}>
<StyledTooltip
title={<TextField
id="task-description"
value={newTask.description}
variant="outlined"
name='description'
placeholder='Описание'
sx={{ width: '300px' }}
onChange={onChangeNewTaskHandler}
multiline
rows={5}
/>}>
<TextField <TextField
id="task-title" id="task-title"
value={newTask.title} value={newTask.title}
...@@ -60,6 +85,7 @@ function NewTaskForm({ addFormStatus, onChangeNewTaskHandler, newTask, allUserPr ...@@ -60,6 +85,7 @@ function NewTaskForm({ addFormStatus, onChangeNewTaskHandler, newTask, allUserPr
sx={{ width: '90%' }} sx={{ width: '90%' }}
onChange={onChangeNewTaskHandler} onChange={onChangeNewTaskHandler}
/> />
</StyledTooltip>
</Grid> </Grid>
<Grid item xs={2}> <Grid item xs={2}>
<CustomSelect <CustomSelect
...@@ -91,7 +117,7 @@ function NewTaskForm({ addFormStatus, onChangeNewTaskHandler, newTask, allUserPr ...@@ -91,7 +117,7 @@ function NewTaskForm({ addFormStatus, onChangeNewTaskHandler, newTask, allUserPr
/> />
</Grid> </Grid>
<Grid item xs={0.5} > <Grid item xs={0.5} >
<IconButton disabled={!newTask.title} onClick={createNewTaskHandler}> <IconButton disabled={!isValidate(newTask.title, newTask.description)} onClick={createNewTaskHandler}>
<Save /> <Save />
</IconButton> </IconButton>
</Grid> </Grid>
......
export const isValidate = (title, description) => {
if (title.length === 0) return false
if (title.length < 50 && description.length < 100) return true
return false
}
\ No newline at end of file
...@@ -3,10 +3,11 @@ import moment from "moment"; ...@@ -3,10 +3,11 @@ import moment from "moment";
import { memo } from "react"; import { memo } from "react";
import DeleteButton from "../../../UI/DeleteButton/DeleteButton"; import DeleteButton from "../../../UI/DeleteButton/DeleteButton";
import { getComparator, stableSort } from "./helpers"; import { getComparator, stableSort } from "./helpers";
import { Done, Edit } from "@mui/icons-material"; import { Edit } from "@mui/icons-material";
import { useSelector } from "react-redux";
function UsersTasksTableBody({ rows, page, rowsPerPage, order, orderBy, addFormStatus }) {
function UsersTasksTableBody({ rows, page, rowsPerPage, order, orderBy, deleteTaskHandler }) {
const user = useSelector((state) => state.users.user);
return (<> return (<>
<TableBody> <TableBody>
...@@ -22,7 +23,7 @@ function UsersTasksTableBody({ rows, page, rowsPerPage, order, orderBy, addFormS ...@@ -22,7 +23,7 @@ function UsersTasksTableBody({ rows, page, rowsPerPage, order, orderBy, addFormS
<TableCell sx={{ width: '4%' }}>{row.priority ? row.priority : null}</TableCell> <TableCell sx={{ width: '4%' }}>{row.priority ? row.priority : null}</TableCell>
<TableCell sx={{ width: '10%' }}>{moment(row.createdAt).format('DD.MM.YYYY')}</TableCell> <TableCell sx={{ width: '10%' }}>{moment(row.createdAt).format('DD.MM.YYYY')}</TableCell>
<Tooltip title={row.description}> <Tooltip title={row.description}>
<TableCell sx={{ width: '25%', overflow: 'hidden', overflow: 'hidden', textOverflow: 'ellipsis' }}> <TableCell sx={{ width: '25%', overflow: 'hidden', textOverflow: 'ellipsis' }}>
{row.title} {row.title}
</TableCell> </TableCell>
</Tooltip> </Tooltip>
...@@ -33,8 +34,14 @@ function UsersTasksTableBody({ rows, page, rowsPerPage, order, orderBy, addFormS ...@@ -33,8 +34,14 @@ function UsersTasksTableBody({ rows, page, rowsPerPage, order, orderBy, addFormS
<TableCell sx={{ width: '10%' }}>{row.dateTimeDeadLine ? moment(row.dateTimeDeadLine).utcOffset('+000').format('DD.MM.YYYY HH:MM') : null}</TableCell> <TableCell sx={{ width: '10%' }}>{row.dateTimeDeadLine ? moment(row.dateTimeDeadLine).utcOffset('+000').format('DD.MM.YYYY HH:MM') : null}</TableCell>
<TableCell sx={{ width: '7%' }}>{row.accomplish}</TableCell> <TableCell sx={{ width: '7%' }}>{row.accomplish}</TableCell>
<TableCell size='medium' sx={{ width: '5%', position: 'relative' }}> <TableCell size='medium' sx={{ width: '5%', position: 'relative' }}>
{user.id === row.author.id ?
<>
<Edit sx={{ position: 'absolute', left: -10 }} /> <Edit sx={{ position: 'absolute', left: -10 }} />
<DeleteButton /> <DeleteButton onClick={() => { deleteTaskHandler(row.id) }} />
</>
:
<Edit />
}
</TableCell> </TableCell>
</TableRow> </TableRow>
); );
......
...@@ -5,7 +5,7 @@ import UsersTasksTableBody from "./UsersTasksTableBody/UsersTasksTableBody"; ...@@ -5,7 +5,7 @@ import UsersTasksTableBody from "./UsersTasksTableBody/UsersTasksTableBody";
import UsersTasksTableHead from "./UsersTasksTableHead/UsersTasksTableHead"; import UsersTasksTableHead from "./UsersTasksTableHead/UsersTasksTableHead";
function UsersTasksTableContainer({ order, orderBy, handleRequestSort, rows, page, rowsPerPage, addFormStatus, onChangeNewTaskHandler, newTask, allUserProjectsForModalTask, onDateChange, createNewTaskHandler}) { function UsersTasksTableContainer({ order, orderBy, handleRequestSort, rows, page, rowsPerPage, addFormStatus, onChangeNewTaskHandler, newTask, allUserProjectsForModalTask, onDateChange, createNewTaskHandler, deleteTaskHandler}) {
return ( return (
<TableContainer> <TableContainer>
<NewTaskForm <NewTaskForm
...@@ -24,6 +24,7 @@ function UsersTasksTableContainer({ order, orderBy, handleRequestSort, rows, pag ...@@ -24,6 +24,7 @@ function UsersTasksTableContainer({ order, orderBy, handleRequestSort, rows, pag
order={order} order={order}
orderBy={orderBy} orderBy={orderBy}
handleRequestSort={handleRequestSort} handleRequestSort={handleRequestSort}
deleteTaskHandler={deleteTaskHandler}
/> />
<UsersTasksTableBody <UsersTasksTableBody
order={order} order={order}
...@@ -31,6 +32,7 @@ function UsersTasksTableContainer({ order, orderBy, handleRequestSort, rows, pag ...@@ -31,6 +32,7 @@ function UsersTasksTableContainer({ order, orderBy, handleRequestSort, rows, pag
rows={rows} rows={rows}
page={page} page={page}
rowsPerPage={rowsPerPage} rowsPerPage={rowsPerPage}
deleteTaskHandler={deleteTaskHandler}
/> />
</Table> </Table>
</TableContainer> </TableContainer>
......
import { AppBar, Box, Toolbar, Typography } from "@mui/material"; import { AppBar, Box, Typography } from "@mui/material";
import { memo } from "react"; import { memo } from "react";
import CreateTaskFromButton from "./CreateTaskFromButton/CreateTaskFromButton"; import CreateTaskFromButton from "./CreateTaskFromButton/CreateTaskFromButton";
......
...@@ -2,9 +2,9 @@ import Paper from '@mui/material/Paper'; ...@@ -2,9 +2,9 @@ import Paper from '@mui/material/Paper';
import UsersTasksTableToolbar from '../../components/UsersTasksCompoments/UsersTasksTableToolbar/UsersTasksTableToolbar'; import UsersTasksTableToolbar from '../../components/UsersTasksCompoments/UsersTasksTableToolbar/UsersTasksTableToolbar';
import UsersTasksTablePagination from '../../components/UsersTasksCompoments/UsersTasksTablePagination/UsersTasksTablePagination'; import UsersTasksTablePagination from '../../components/UsersTasksCompoments/UsersTasksTablePagination/UsersTasksTablePagination';
import UsersTasksTableContainer from '../../components/UsersTasksCompoments/UsersTasksTableContainer/UsersTasksTableContainer'; import UsersTasksTableContainer from '../../components/UsersTasksCompoments/UsersTasksTableContainer/UsersTasksTableContainer';
import { addTaskToUserTasksTable, fetchAllTasksByMembership } from '../../store/actions/tasksActions'; import { addTaskToUserTasksTable, deleteTaskUsers, fetchAllTasksByMembership } from '../../store/actions/tasksActions';
import { shallowEqual, useDispatch, useSelector } from 'react-redux'; import { shallowEqual, useDispatch, useSelector } from 'react-redux';
import { useEffect, useState } from 'react'; import { useCallback, useEffect, useState } from 'react';
import { fetchAllUserProjects } from '../../store/actions/projectsActions'; import { fetchAllUserProjects } from '../../store/actions/projectsActions';
import moment from 'moment'; import moment from 'moment';
...@@ -14,15 +14,15 @@ export default function EnhancedTable() { ...@@ -14,15 +14,15 @@ export default function EnhancedTable() {
const { tasks } = useSelector((state) => state.tasks); const { tasks } = useSelector((state) => state.tasks);
const { allUserProjectsForModalTask } = useSelector(state => state.projects, shallowEqual) const { allUserProjectsForModalTask } = useSelector(state => state.projects, shallowEqual)
const user = useSelector((state) => state.users.user);
const [newTask, setNewTask] = useState({ const [newTask, setNewTask] = useState({
priority: '', priority: '',
title: '', title: '',
project: null, project: '',
description: '', description: '',
executor: null, executor: '',
dateTimeDeadLine: null, dateTimeDeadLine: null,
}) })
const [order, setOrder] = useState('asc'); const [order, setOrder] = useState('asc');
const [orderBy, setOrderBy] = useState('createdAt'); const [orderBy, setOrderBy] = useState('createdAt');
const [page, setPage] = useState(0); const [page, setPage] = useState(0);
...@@ -34,7 +34,7 @@ export default function EnhancedTable() { ...@@ -34,7 +34,7 @@ export default function EnhancedTable() {
dispatch(fetchAllUserProjects()) dispatch(fetchAllUserProjects())
}, [dispatch]); }, [dispatch]);
const onChangeNewTaskHandler = (e) => { const onChangeNewTaskHandler = useCallback((e) => {
const { value, name } = e.target; const { value, name } = e.target;
setNewTask((prevState => { setNewTask((prevState => {
return { return {
...@@ -42,9 +42,9 @@ export default function EnhancedTable() { ...@@ -42,9 +42,9 @@ export default function EnhancedTable() {
[name]: value [name]: value
} }
})); }));
}; },[])
const onDateChange = (value, property) => { const onDateChange = useCallback((value, property) => {
const utcAvoidoffset = moment(value).utcOffset(0, true).format() const utcAvoidoffset = moment(value).utcOffset(0, true).format()
setNewTask((prevState => { setNewTask((prevState => {
return { return {
...@@ -52,24 +52,24 @@ export default function EnhancedTable() { ...@@ -52,24 +52,24 @@ export default function EnhancedTable() {
[property]: utcAvoidoffset [property]: utcAvoidoffset
} }
})); }));
}; },[]);
const handleRequestSort = (event, property) => { const handleRequestSort = useCallback((event, property) => {
const isAsc = orderBy === property && order === 'asc'; const isAsc = orderBy === property && order === 'asc';
setOrder(isAsc ? 'desc' : 'asc'); setOrder(isAsc ? 'desc' : 'asc');
setOrderBy(property); setOrderBy(property);
}; },[order, orderBy]);
const handleChangePage = (event, newPage) => { const handleChangePage = useCallback((event, newPage) => {
setPage(newPage); setPage(newPage);
}; },[]);
const handleChangeRowsPerPage = (event) => { const handleChangeRowsPerPage = useCallback((event) => {
setRowsPerPage(parseInt(event.target.value, 10)); setRowsPerPage(parseInt(event.target.value, 10));
setPage(0); setPage(0);
}; },[]);
const createTaskFromButtonHandler = () => { const createTaskFromButtonHandler = useCallback(() => {
if (addFormStatus) { if (addFormStatus) {
setNewTask({ setNewTask({
priority: '', priority: '',
...@@ -77,15 +77,20 @@ export default function EnhancedTable() { ...@@ -77,15 +77,20 @@ export default function EnhancedTable() {
project: '', project: '',
description: '', description: '',
executor: '', executor: '',
dateTimeDeadLine: '',
}) })
} }
setAddFormStatus((prevState) => { return !prevState }) setAddFormStatus((prevState) => { return !prevState })
} },[addFormStatus])
const createNewTaskHandler = () => { const createNewTaskHandler = useCallback(() => {
if (newTask.priority === '') { if (newTask.priority === '' || newTask.project === '' || newTask.executor) {
const task = {...newTask, priority: null} const task = {
...newTask,
priority: newTask.priority ? newTask.priority : null,
project: newTask.project ? newTask.project : null,
executor: newTask.executor ? newTask.priority : null,
}
console.log(task, 'asdasdasdasdassdasdas')
dispatch(addTaskToUserTasksTable(task)) dispatch(addTaskToUserTasksTable(task))
} else { } else {
dispatch(addTaskToUserTasksTable(newTask)) dispatch(addTaskToUserTasksTable(newTask))
...@@ -96,10 +101,14 @@ export default function EnhancedTable() { ...@@ -96,10 +101,14 @@ export default function EnhancedTable() {
project: '', project: '',
description: '', description: '',
executor: '', executor: '',
dateTimeDeadLine: '',
}) })
setAddFormStatus((prevState) => { return !prevState }) setAddFormStatus((prevState) => { return !prevState })
} },[dispatch, newTask])
const deleteTaskHandler = useCallback((id)=>{
dispatch(deleteTaskUsers(id))
}, [dispatch])
return ( return (
<Paper sx={{ width: '100%', mb: 2 }}> <Paper sx={{ width: '100%', mb: 2 }}>
...@@ -120,6 +129,7 @@ export default function EnhancedTable() { ...@@ -120,6 +129,7 @@ export default function EnhancedTable() {
allUserProjectsForModalTask={allUserProjectsForModalTask} allUserProjectsForModalTask={allUserProjectsForModalTask}
onDateChange={onDateChange} onDateChange={onDateChange}
createNewTaskHandler={createNewTaskHandler} createNewTaskHandler={createNewTaskHandler}
deleteTaskHandler={deleteTaskHandler}
/> />
<UsersTasksTablePagination <UsersTasksTablePagination
count={tasks.length} count={tasks.length}
......
...@@ -167,8 +167,7 @@ export const editCalendarTask = (task, taskId, userId) => { ...@@ -167,8 +167,7 @@ export const editCalendarTask = (task, taskId, userId) => {
return async (dispatch) => { return async (dispatch) => {
dispatch(editTaskRequest()); dispatch(editTaskRequest());
try { try {
const response = await axios.put(`/copy-tasks/change-copy/${taskId}`, task); await axios.put(`/copy-tasks/change-copy/${taskId}`, task);
console.log(response.data)
dispatch(editTaskSuccess()) dispatch(editTaskSuccess())
dispatch(fetchCalendarTasks(userId)) dispatch(fetchCalendarTasks(userId))
} catch (error) { } catch (error) {
...@@ -202,6 +201,19 @@ export const deleteTask = (taskId) => { ...@@ -202,6 +201,19 @@ export const deleteTask = (taskId) => {
} }
} }
export const deleteTaskUsers = (taskId) => {
return async (dispatch) => {
dispatch(deleteTaskRequest());
try {
await axios.delete(`/tasks/${taskId}`);
dispatch(deleteTaskSuccess())
await dispatch(fetchAllTasksByMembership())
} catch (error) {
dispatch(deleteTaskFailure(error.response.data));
}
}
}
export const deleteCalendarTask = (taskId, userId) => { export const deleteCalendarTask = (taskId, userId) => {
return async (dispatch) => { return async (dispatch) => {
dispatch(deleteTaskRequest()); dispatch(deleteTaskRequest());
......
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