From 269f3fe70312d047484ec68626b25c6ef101a078 Mon Sep 17 00:00:00 2001 From: Mikola Date: Thu, 15 Feb 2024 14:56:58 +0300 Subject: [PATCH] choose project --- src/components/ReportForm/ReportForm.jsx | 83 +++++++++++++++--------- 1 file changed, 54 insertions(+), 29 deletions(-) diff --git a/src/components/ReportForm/ReportForm.jsx b/src/components/ReportForm/ReportForm.jsx index b8a2d31a..fb591858 100644 --- a/src/components/ReportForm/ReportForm.jsx +++ b/src/components/ReportForm/ReportForm.jsx @@ -18,10 +18,10 @@ import { ProfileBreadcrumbs } from "@components/ProfileBreadcrumbs/ProfileBreadc import { ProfileHeader } from "@components/ProfileHeader/ProfileHeader"; import arrow from "assets/icons/arrows/left-arrow.png"; +import arrowDown from "assets/icons/arrows/selectArrow.png"; import calendarIcon from "assets/icons/calendar.svg"; import ellipse from "assets/icons/ellipse.png"; import remove from "assets/icons/remove.svg"; -import arrowDown from "assets/icons/arrows/selectArrow.png"; import { getCorrectDate, @@ -41,7 +41,6 @@ const ReportForm = () => { const editReport = useSelector(getEditReport); const dispatch = useDispatch(); - useEffect(() => { initListeners(); getProjectList(); @@ -54,10 +53,10 @@ const ReportForm = () => { ? new Date(reportDate ? reportDate._d : editReport.created_at) : new Date() ); - const [projectList, setProjectList] = useState([]) - const [projectLoader, setProjectLoader] = useState(false) - const [selectedProject, setSelectedProject] = useState('Выберите проект') - const [openSelectProject, setOpenSelectProject] = useState(false) + const [projectList, setProjectList] = useState([]); + const [projectLoader, setProjectLoader] = useState(false); + const [selectedProject, setSelectedProject] = useState("Выберите проект"); + const [openSelectProject, setOpenSelectProject] = useState(false); const [datePickerOpen, setDatePickerOpen] = useState(false); const [inputs, setInputs] = useState( @@ -93,13 +92,11 @@ const ReportForm = () => { div.classList && (div.classList.contains("report-form__block-img") || div.classList.contains("react-datepicker-popper") || - div.classList.contains("report-form__project") - - ) + div.classList.contains("report-form__project")) ) ) { setDatePickerOpen(false); - setOpenSelectProject(false) + setOpenSelectProject(false); } }; @@ -110,16 +107,16 @@ const ReportForm = () => { }; const getProjectList = () => { - setProjectLoader(true) + setProjectLoader(true); apiRequest( `/project/project-list?user_id=${localStorage.getItem( "id" )}&expand=columns` ).then((el) => { - setProjectLoader(false) - setProjectList(el?.projects) + setProjectLoader(false); + setProjectList(el?.projects); }); - } + }; const handler = () => { setIsFetching(true); for (let input of inputs) { @@ -135,7 +132,7 @@ const ReportForm = () => { data: { user_id: localStorage.getItem("id"), tasks: inputs, - project_id: selectedProject.id ? selectedProject.id : '', + project_id: selectedProject.id ? selectedProject.id : "", difficulties: troublesInputValue, tomorrow: scheduledInputValue, created_at: getCreatedDate(startDate), @@ -167,7 +164,7 @@ const ReportForm = () => { data: { tasks: inputs, difficulties: troublesInputValue, - project_id: selectedProject.id ? selectedProject.id : '', + project_id: selectedProject.id ? selectedProject.id : "", tomorrow: scheduledInputValue, created_at: getCreatedDate(startDate), status: 1 @@ -244,30 +241,58 @@ const ReportForm = () => { setStartDate(date); }} /> - {projectLoader ?
: + {projectLoader ? ( +
+ +
+ ) : ( <>
Выберите проект
-
setOpenSelectProject(!openSelectProject)}> -

{selectedProject.name ? selectedProject.name : selectedProject}

- arrow +
setOpenSelectProject(!openSelectProject)} + > +

+ {selectedProject.name + ? selectedProject.name + : selectedProject} +

+ arrow
- {openSelectProject && + {openSelectProject && (
- {Boolean(projectList.length) ? projectList.map((project) => { - return { - setSelectedProject(project) - setOpenSelectProject(false) - }} key={project.id}>{project.name} - }) : Проектов нет} + {Boolean(projectList.length) ? ( + projectList.map((project) => { + return ( + { + setSelectedProject(project); + setOpenSelectProject(false); + }} + key={project.id} + > + {project.name} + + ); + }) + ) : ( + Проектов нет + )}
- } + )}
- } + )}
Какие задачи выполнены?