№59 исправила вывод проектов в селекте при редактировании, убрала возможность…

№59 исправила вывод проектов в селекте при редактировании, убрала возможность редактировать автора задачи, поставила запрет на редактирование полей задач, где автор не пользователь. всех кроме дат,времени  и статуса
parent 99d6d937
...@@ -8,10 +8,12 @@ const CustomTableCell = ({task, ...@@ -8,10 +8,12 @@ const CustomTableCell = ({task,
onChange, onChange,
onModalOpen, onModalOpen,
placeholder, placeholder,
user
}) => { }) => {
const styles = { width: "auto", height: "10px"}; const styles = { width: "auto", height: "10px"};
if (task) {
if (task) {
return ( return (
<> <>
<TableCell <TableCell
...@@ -19,7 +21,7 @@ const CustomTableCell = ({task, ...@@ -19,7 +21,7 @@ const CustomTableCell = ({task,
align="left" align="left"
style={styles} style={styles}
> >
{task.isEditMode && onChange ? ( {task.isEditMode && onChange && name==!"author" && task.author.id==user.id ? (
<Input <Input
placeholder={placeholder} placeholder={placeholder}
value={value} value={value}
......
...@@ -3,22 +3,23 @@ import "./TaskModal.css"; ...@@ -3,22 +3,23 @@ import "./TaskModal.css";
import { Done } from "@mui/icons-material"; import { Done } from "@mui/icons-material";
import Input from "@mui/material/Input"; import Input from "@mui/material/Input";
const TaskModal = (props) => { const TaskModal = ({handleClose,open,task,onChange,user }) => {
return ( return (
<Modal <Modal
aria-labelledby="transition-modal-title" aria-labelledby="transition-modal-title"
aria-describedby="transition-modal-description" aria-describedby="transition-modal-description"
className={"modal"} className={"modal"}
closeAfterTransition closeAfterTransition
onClose={props.handleClose} onClose={handleClose}
open={props.open} open={open}
> >
{props?.task?.isEditMode ? ( {task?.isEditMode && task.author.id===user.id ? (
<div className="modalBox"> <div className="modalBox">
<Input <Input
value={props.task.title} value={task.title}
name="title" name="title"
onChange={(e) => props.onChange(e, props.task)} onChange={(e) => onChange(e, task)}
style={{ style={{
width: "auto", width: "auto",
fontSize: "12px", fontSize: "12px",
...@@ -27,18 +28,18 @@ const TaskModal = (props) => { ...@@ -27,18 +28,18 @@ const TaskModal = (props) => {
}} }}
/> />
<Input <Input
value={props.task.description} value={task.description}
name="description" name="description"
onChange={(e) => props.onChange(e, props.task)} onChange={(e) => onChange(e, task)}
style={{ width: "auto", fontSize: "12px", color: "white" }} style={{ width: "auto", fontSize: "12px", color: "white" }}
/> />
<IconButton aria-label="done" onClick={props.handleClose}> <IconButton aria-label="done" onClick={handleClose}>
<Done /> <Done />
</IconButton> </IconButton>
</div> </div>
) : ( ) : (
<div className="modalBox"> <div className="modalBox">
{props.task && props.task.title && ( {task && task.title && (
<div <div
style={{ style={{
width: "200px", width: "200px",
...@@ -47,18 +48,18 @@ const TaskModal = (props) => { ...@@ -47,18 +48,18 @@ const TaskModal = (props) => {
fontWeight: "600", fontWeight: "600",
}} }}
> >
{props.task.title} {task.title}
</div> </div>
)} )}
{props.task && props.task.description && ( {task && task.description && (
<div style={{ width: "200px", height: "200px", color: "white" }}> <div style={{ width: "200px", height: "200px", color: "white" }}>
{props.task.description} {task.description}
</div> </div>
)} )}
<IconButton <IconButton
sx={{ marginLeft: 0, color: "white" }} sx={{ marginLeft: 0, color: "white" }}
aria-label="close" aria-label="close"
onClick={props.handleClose} onClick={handleClose}
> >
X X
</IconButton> </IconButton>
......
...@@ -33,7 +33,7 @@ export default function EnhancedTable() { ...@@ -33,7 +33,7 @@ export default function EnhancedTable() {
const dispatch = useDispatch(); const dispatch = useDispatch();
const tasks = useSelector((state) => state.tasks.tasks); const tasks = useSelector((state) => state.tasks.tasks);
const user = useSelector((state) => state.users.user);
const [recievedTasks, setRecievedTasks] = useState([]); const [recievedTasks, setRecievedTasks] = useState([]);
const [addTaskForm, setAddTaskForm] = useState(false); const [addTaskForm, setAddTaskForm] = useState(false);
const [order, setOrder] = useState("asc"); const [order, setOrder] = useState("asc");
...@@ -45,9 +45,7 @@ export default function EnhancedTable() { ...@@ -45,9 +45,7 @@ export default function EnhancedTable() {
task: null, task: null,
}); });
const [projects,setProjects]=useState(['1','2']) const [projects,setProjects]=useState(['1','2'])
console.log(tasks)
useEffect(() => { useEffect(() => {
dispatch(fetchAllTasks()); dispatch(fetchAllTasks());
filterProjectsNamesFromTasks() filterProjectsNamesFromTasks()
...@@ -120,7 +118,7 @@ useEffect(() => { ...@@ -120,7 +118,7 @@ useEffect(() => {
const onProjectChange = (e, task) => { const onProjectChange = (e, task) => {
const value = e.target.value; const value = e.target.value;
const project = rawProjects.find((e) => e.id === value); const project = uniqueProjects.find((e) => e.id === value);
const { id } = task; const { id } = task;
const newTasks = recievedTasks.map((task) => { const newTasks = recievedTasks.map((task) => {
if (task.id === id) { if (task.id === id) {
...@@ -129,7 +127,7 @@ useEffect(() => { ...@@ -129,7 +127,7 @@ useEffect(() => {
updated.projectName = project.title; updated.projectName = project.title;
return updated; return updated;
} }
return task; return task;
}); });
setRecievedTasks(newTasks); setRecievedTasks(newTasks);
}; };
...@@ -195,6 +193,8 @@ useEffect(() => { ...@@ -195,6 +193,8 @@ useEffect(() => {
setFilterProjectTumbler(true) setFilterProjectTumbler(true)
} }
const rawProjects= tasks?.map(task=>task.project) const rawProjects= tasks?.map(task=>task.project)
const filterProjectsNamesFromTasks = ()=>{ const filterProjectsNamesFromTasks = ()=>{
if (tasks && tasks?.length > 0) { if (tasks && tasks?.length > 0) {
...@@ -211,6 +211,17 @@ useEffect(() => { ...@@ -211,6 +211,17 @@ useEffect(() => {
} }
} }
const uniqueProjects = rawProjects?.reduce((results, value, index) => {
const exist = results.find((v) => {
return v !== null && v.id === value?.id
});
if (!exist && value !== null) {
results.push(value);
}
return results;
}, []);
if ( if (
tasks && tasks &&
tasks?.length > 0 && tasks?.length > 0 &&
...@@ -259,7 +270,7 @@ useEffect(() => { ...@@ -259,7 +270,7 @@ useEffect(() => {
scope="row" scope="row"
padding="none" padding="none"
></TableCell> ></TableCell>
{task.isEditMode ? ( {task.isEditMode && task.author.id===user.id ? (
<TableCell> <TableCell>
<BasicSelect <BasicSelect
items={[ items={[
...@@ -271,7 +282,9 @@ useEffect(() => { ...@@ -271,7 +282,9 @@ useEffect(() => {
value={task.priority} value={task.priority}
onChange={onChange} onChange={onChange}
name="priority" name="priority"
user={user}
/> />
</TableCell> </TableCell>
) : ( ) : (
<CustomTableCell <CustomTableCell
...@@ -279,6 +292,7 @@ useEffect(() => { ...@@ -279,6 +292,7 @@ useEffect(() => {
task, task,
name: "priority", name: "priority",
value: task.priority, value: task.priority,
user:user
}} }}
/> />
)} )}
...@@ -290,7 +304,7 @@ useEffect(() => { ...@@ -290,7 +304,7 @@ useEffect(() => {
value: moment(task.createdAt) value: moment(task.createdAt)
.utc() .utc()
.format("DD-MM-YYYY hh:mm A"), .format("DD-MM-YYYY hh:mm A"),
user:user
}} }}
/> />
...@@ -301,13 +315,14 @@ useEffect(() => { ...@@ -301,13 +315,14 @@ useEffect(() => {
value: task.title, value: task.title,
onChange, onChange,
onModalOpen, onModalOpen,
user:user
}} }}
/> />
{task.isEditMode ? ( {task.isEditMode && task.author.id===user.id ? (
<TableCell> <TableCell>
<BasicSelect <BasicSelect
items={rawProjects.map((e) => ({ items={uniqueProjects.map((e) => ({
value: e?.id, value: e?.id,
title: e?.title, title: e?.title,
}))} }))}
...@@ -315,6 +330,7 @@ useEffect(() => { ...@@ -315,6 +330,7 @@ useEffect(() => {
onChange={onProjectChange} onChange={onProjectChange}
name="project" name="project"
value={task.project?.id} value={task.project?.id}
user={user}
/> />
</TableCell> </TableCell>
) : ( ) : (
...@@ -323,6 +339,7 @@ useEffect(() => { ...@@ -323,6 +339,7 @@ useEffect(() => {
task, task,
name: "projectId", name: "projectId",
value: task.project?.title, value: task.project?.title,
user:user
}} }}
/> />
)} )}
...@@ -333,6 +350,7 @@ useEffect(() => { ...@@ -333,6 +350,7 @@ useEffect(() => {
name: "author", name: "author",
value: task.author.displayName, value: task.author.displayName,
onChange: onAuthorChange, onChange: onAuthorChange,
user:user
}} }}
/> />
...@@ -341,7 +359,9 @@ useEffect(() => { ...@@ -341,7 +359,9 @@ useEffect(() => {
task={task} task={task}
name="dateTimeStart" name="dateTimeStart"
onChange={onDateChange} onChange={onDateChange}
user={user}
/> />
</TableCell> </TableCell>
<TableCell> <TableCell>
...@@ -349,6 +369,7 @@ useEffect(() => { ...@@ -349,6 +369,7 @@ useEffect(() => {
task={task} task={task}
name="dateTimeDue" name="dateTimeDue"
onChange={onDateChange} onChange={onDateChange}
user={user}
/> />
</TableCell> </TableCell>
...@@ -364,6 +385,7 @@ useEffect(() => { ...@@ -364,6 +385,7 @@ useEffect(() => {
onChange={onChange} onChange={onChange}
name="accomplish" name="accomplish"
value={task.accomplish} value={task.accomplish}
user={user}
/> />
</TableCell> </TableCell>
) : ( ) : (
...@@ -372,6 +394,7 @@ useEffect(() => { ...@@ -372,6 +394,7 @@ useEffect(() => {
task, task,
name: "accomplish", name: "accomplish",
value: task.accomplish, value: task.accomplish,
user:user
}} }}
/> />
)} )}
...@@ -430,6 +453,7 @@ useEffect(() => { ...@@ -430,6 +453,7 @@ useEffect(() => {
open={modal.open} open={modal.open}
handleClose={handleClose} handleClose={handleClose}
onChange={onChange} onChange={onChange}
user={user}
/> />
</Box> </Box>
); );
......
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