select executor on create task

This commit is contained in:
Николай Полтщук 2023-06-27 18:35:59 +03:00
parent 7c622d63a1
commit bd3e2288ed
2 changed files with 65 additions and 37 deletions

View File

@ -1,6 +1,7 @@
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { useDispatch, useSelector } from "react-redux"; import { useDispatch, useSelector } from "react-redux";
import { getProfileInfo } from "@redux/outstaffingSlice";
import { import {
addPersonToProject, addPersonToProject,
editColumnName, editColumnName,
@ -16,8 +17,6 @@ import {
setProjectBoardFetch, setProjectBoardFetch,
} from "@redux/projectsTrackerSlice"; } from "@redux/projectsTrackerSlice";
import {getProfileInfo} from "@redux/outstaffingSlice";
import { urlForLocal } from "@utils/helper"; import { urlForLocal } from "@utils/helper";
import { apiRequest } from "@api/request"; import { apiRequest } from "@api/request";
@ -37,7 +36,7 @@ export const TrackerModal = ({
titleProject, titleProject,
projectId, projectId,
priorityTask, priorityTask,
projectUsers projectUsers,
}) => { }) => {
const dispatch = useDispatch(); const dispatch = useDispatch();
const projectBoard = useSelector(getProjectBoard); const projectBoard = useSelector(getProjectBoard);
@ -58,8 +57,10 @@ export const TrackerModal = ({
const [selectColumnPriority, setSelectColumnPriority] = useState( const [selectColumnPriority, setSelectColumnPriority] = useState(
"Выберите приоритет колонки" "Выберите приоритет колонки"
); );
const [selectedExecutorTask, setSelectedExecutorTask] = useState('Выберите исполнителя задачи') const [selectedExecutorTask, setSelectedExecutorTask] = useState(
const [selectExecutorTaskOpen, setSelectExecutorTaskOpen] = useState(false) "Выберите исполнителя задачи"
);
const [selectExecutorTaskOpen, setSelectExecutorTaskOpen] = useState(false);
const [correctProjectUsers, setCorrectProjectUsers] = useState([]); const [correctProjectUsers, setCorrectProjectUsers] = useState([]);
const [selectColumnPriorityOpen, setSelectColumnPriorityOpen] = const [selectColumnPriorityOpen, setSelectColumnPriorityOpen] =
useState(false); useState(false);
@ -114,8 +115,8 @@ export const TrackerModal = ({
setActive(false); setActive(false);
setValueTiket(""); setValueTiket("");
setDescriptionTicket(""); setDescriptionTicket("");
setSelectedExecutorTask('Выберите исполнителя задачи') setSelectedExecutorTask("Выберите исполнителя задачи");
}) });
} else { } else {
setActive(false); setActive(false);
setValueTiket(""); setValueTiket("");
@ -237,9 +238,13 @@ export const TrackerModal = ({
}) })
: ""; : "";
if ( if (
localStorage.getItem("role_status") !== "18" && projectUsers && Boolean(!projectUsers.find((item) => item.user_id === profileInfo.id_user)) localStorage.getItem("role_status") !== "18" &&
projectUsers &&
Boolean(
!projectUsers.find((item) => item.user_id === profileInfo.id_user)
)
) { ) {
setCorrectProjectUsers( [ setCorrectProjectUsers([
...projectUsers, ...projectUsers,
{ {
user: { user: {
@ -250,7 +255,7 @@ export const TrackerModal = ({
}, },
]); ]);
} else { } else {
setCorrectProjectUsers(projectUsers) setCorrectProjectUsers(projectUsers);
} }
}, [active]); }, [active]);
@ -341,32 +346,52 @@ export const TrackerModal = ({
/> />
</div> </div>
<div <div
onClick={() => setSelectExecutorTaskOpen(!selectExecutorTaskOpen)} onClick={() => setSelectExecutorTaskOpen(!selectExecutorTaskOpen)}
className={selectExecutorTaskOpen ? 'select__executor select__executor--open' : 'select__executor'}> className={
<div className='selected__executor'> selectExecutorTaskOpen
{selectedExecutorTask.user_id ? ? "select__executor select__executor--open"
<> : "select__executor"
<span>{selectedExecutorTask.user.fio}</span>
<img className='avatar' src={urlForLocal(selectedExecutorTask.user.avatar)} alt='avatar' />
</>
: <span>{selectedExecutorTask}</span>
}
</div>
<img className='arrow' src={arrowDown} alt='arrow' />
{selectExecutorTaskOpen &&
<div className='select__executor__dropDown'>
{correctProjectUsers.length ?
correctProjectUsers.map((person) => {
return <div onClick={() => setSelectedExecutorTask(person)} className='executor' key={person.user_id}>
<span>{person.user.fio}</span>
<img className='avatar' src={urlForLocal(person.user.avatar)} alt='avatar'/>
</div>
})
: <span>Нет пользователей</span>
}
</div>
} }
>
<div className="selected__executor">
{selectedExecutorTask.user_id ? (
<>
<span>{selectedExecutorTask.user.fio}</span>
<img
className="avatar"
src={urlForLocal(selectedExecutorTask.user.avatar)}
alt="avatar"
/>
</>
) : (
<span>{selectedExecutorTask}</span>
)}
</div>
<img className="arrow" src={arrowDown} alt="arrow" />
{selectExecutorTaskOpen && (
<div className="select__executor__dropDown">
{correctProjectUsers.length ? (
correctProjectUsers.map((person) => {
return (
<div
onClick={() => setSelectedExecutorTask(person)}
className="executor"
key={person.user_id}
>
<span>{person.user.fio}</span>
<img
className="avatar"
src={urlForLocal(person.user.avatar)}
alt="avatar"
/>
</div>
);
})
) : (
<span>Нет пользователей</span>
)}
</div>
)}
</div> </div>
</div> </div>
<BaseButton styles={"button-add"} onClick={createTiket}> <BaseButton styles={"button-add"} onClick={createTiket}>
@ -456,7 +481,11 @@ export const TrackerModal = ({
</div> </div>
<h4>Приоритет колонки</h4> <h4>Приоритет колонки</h4>
<div <div
className={selectColumnPriorityOpen ? 'select-priority select-priority--open' : 'select-priority'} className={
selectColumnPriorityOpen
? "select-priority select-priority--open"
: "select-priority"
}
onClick={() => onClick={() =>
setSelectColumnPriorityOpen(!selectColumnPriorityOpen) setSelectColumnPriorityOpen(!selectColumnPriorityOpen)
} }

View File

@ -25,7 +25,6 @@ export const ProjectTiket = ({ project, index }) => {
initListeners(); initListeners();
}, []); }, []);
function initListeners() { function initListeners() {
document.addEventListener("click", closeByClickingOut); document.addEventListener("click", closeByClickingOut);
} }