From dd03bcb47c6a2f69f9af6e246ad4fce555059b9c Mon Sep 17 00:00:00 2001 From: M1kola Date: Fri, 21 Apr 2023 01:07:09 +0300 Subject: [PATCH] edit request --- src/App.js | 1 + .../PartnerAddRequest/PartnerAddRequest.js | 82 ++++++++++++++----- src/pages/PartnerBid/PartnerBid.js | 11 +-- src/pages/PartnerBid/partnerBid.scss | 6 +- src/redux/outstaffingSlice.js | 9 +- 5 files changed, 76 insertions(+), 33 deletions(-) diff --git a/src/App.js b/src/App.js index bb1dbb4a..8ad9b58e 100644 --- a/src/App.js +++ b/src/App.js @@ -75,6 +75,7 @@ const App = () => { }/> }/> }/> + }/> }/> }/> }/> diff --git a/src/pages/PartnerAddRequest/PartnerAddRequest.js b/src/pages/PartnerAddRequest/PartnerAddRequest.js index 65844f2e..0a4de51f 100644 --- a/src/pages/PartnerAddRequest/PartnerAddRequest.js +++ b/src/pages/PartnerAddRequest/PartnerAddRequest.js @@ -4,8 +4,11 @@ import {ProfileHeader} from "../../components/ProfileHeader/ProfileHeader"; import {ProfileBreadcrumbs} from "../../components/ProfileBreadcrumbs/ProfileBreadcrumbs" import {Footer} from "../../components/Footer/Footer"; import {Link, Navigate, useNavigate} from "react-router-dom"; - +import { Navigation } from '../../components/Navigation/Navigation'; import {apiRequest} from "../../api/request"; +import {useSelector} from "react-redux"; + +import { getPartnerRequestInfo } from '../../redux/outstaffingSlice' import arrowDown from "../../images/selectArrow.png" import processImg from "../../images/partnerAddRequestFirstImg.png" @@ -15,15 +18,15 @@ import deleteIcon from "../../images/close.png" import './partnerAddRequest.scss' -import { Navigation } from '../../components/Navigation/Navigation'; export const PartnerAddRequest = () => { if(localStorage.getItem('role_status') !== '18') { return } + const partnerRequestInfo = useSelector(getPartnerRequestInfo); + const currentUrl = useState(window.location.pathname) const navigate= useNavigate(); - const [skills, setSkills] = useState([]) const [filteredSkills, setFilteredSkills] = useState([]) const [specializationList, setSpecializationList] = useState([]) @@ -33,12 +36,17 @@ export const PartnerAddRequest = () => { const [openSpecializationList, setOpenSpecializationListOpen] = useState(false) const [openLevelList, setOpenLevelList] = useState(false) const [openCountList, setOpenCountList] = useState(false) + const [editRequest, setEditRequest] = useState(false) const [selectedSkills, setSelectedSkills] = useState([]) const [selectedSpecialization, setSelectedSpecialization] = useState('Выберите специализацию') const [selectedLevel, setSelectedLevel] = useState('Выберите уровень') const [selectedCount, setSelectedCount] = useState('Выберите кол-во сотрудников') const [inputs, setInputs] = useState({title: '', description: ''}) + if (currentUrl[0] === "/profile/edit-request" && !Object.keys(partnerRequestInfo).length) { + return + } + useEffect(() => { apiRequest(`/profile/positions-list`).then((el) => setSpecializationList(el)) apiRequest(`/profile/level-list`).then((el) => setLevelList(el)) @@ -48,6 +56,17 @@ export const PartnerAddRequest = () => { }) }, []) + useEffect(() => { + if (currentUrl[0] === "/profile/edit-request" && Object.keys(partnerRequestInfo).length) { + setInputs({title: partnerRequestInfo.title, description: partnerRequestInfo.descr}) + setSelectedSpecialization(partnerRequestInfo.position) + setSelectedLevel({name: partnerRequestInfo.level, id: partnerRequestInfo.knowledge_level_id}) + setSelectedCount(partnerRequestInfo.specialist_count) + setSelectedSkills(partnerRequestInfo.skills) + setEditRequest(true) + } + }, []) + const disableBtn = () => { if (!inputs.title || typeof selectedSpecialization === "string" || @@ -61,21 +80,40 @@ export const PartnerAddRequest = () => { } const handler = () => { - apiRequest('/request/create-request', { - method: 'POST', - data: { - user_id: localStorage.getItem('id'), - title: inputs.title, - position_id: selectedSpecialization.id, - knowledge_level_id: selectedLevel.id, - specialist_count: selectedCount, - status: 1, - descr: inputs.description, - skill_ids: selectedSkills.map((skill) => {return skill.id}) - } - }).then((res) => { - navigate('/profile/requests'); - }) + if (currentUrl[0] === "/profile/edit-request") { + apiRequest('/request/update-request', { + method: 'PUT', + data: { + user_id: localStorage.getItem('id'), + request_id: partnerRequestInfo.id, + title: inputs.title, + position_id: selectedSpecialization.id, + knowledge_level_id: selectedLevel.id, + specialist_count: selectedCount, + status: 1, + descr: inputs.description, + skill_ids: selectedSkills.map((skill) => {return skill.id}) + } + }).then((res) => { + navigate('/profile/requests'); + }) + } else { + apiRequest('/request/create-request', { + method: 'POST', + data: { + user_id: localStorage.getItem('id'), + title: inputs.title, + position_id: selectedSpecialization.id, + knowledge_level_id: selectedLevel.id, + specialist_count: selectedCount, + status: 1, + descr: inputs.description, + skill_ids: selectedSkills.map((skill) => {return skill.id}) + } + }).then((res) => { + navigate('/profile/requests'); + }) + } } @@ -87,10 +125,10 @@ export const PartnerAddRequest = () => { -

Страница добавления заявки

+

{editRequest ? 'Страница редактирования заявки' : 'Страница добавления заявки'}

@@ -98,7 +136,7 @@ export const PartnerAddRequest = () => {

Название вакансии

- setInputs((prevValue) => ({...prevValue, title: e.target.value}) )} type='text' placeholder='Вакансия'/> + setInputs((prevValue) => ({...prevValue, title: e.target.value}) )} type='text' placeholder='Вакансия'/>
@@ -196,7 +234,7 @@ export const PartnerAddRequest = () => {

Введите необходимое описание

-