edit request

This commit is contained in:
Николай Полтщук 2023-04-21 01:07:09 +03:00
parent 37d8ab385d
commit dd03bcb47c
5 changed files with 76 additions and 33 deletions

View File

@ -75,6 +75,7 @@ const App = () => {
<Route exact path='settings' element={<PartnerSettings/>}/> <Route exact path='settings' element={<PartnerSettings/>}/>
<Route exact path='requests' element={<PartnerRequests/>}/> <Route exact path='requests' element={<PartnerRequests/>}/>
<Route exact path='add-request' element={<PartnerAddRequest/>}/> <Route exact path='add-request' element={<PartnerAddRequest/>}/>
<Route exact path='edit-request' element={<PartnerAddRequest/>}/>
<Route exact path='bid' element={<PartnerBid/>}/> <Route exact path='bid' element={<PartnerBid/>}/>
<Route exact path='categories' element={<PartnerCategories/>}/> <Route exact path='categories' element={<PartnerCategories/>}/>
<Route exact path='treaties' element={<PartnerTreaties/>}/> <Route exact path='treaties' element={<PartnerTreaties/>}/>

View File

@ -4,8 +4,11 @@ import {ProfileHeader} from "../../components/ProfileHeader/ProfileHeader";
import {ProfileBreadcrumbs} from "../../components/ProfileBreadcrumbs/ProfileBreadcrumbs" import {ProfileBreadcrumbs} from "../../components/ProfileBreadcrumbs/ProfileBreadcrumbs"
import {Footer} from "../../components/Footer/Footer"; import {Footer} from "../../components/Footer/Footer";
import {Link, Navigate, useNavigate} from "react-router-dom"; import {Link, Navigate, useNavigate} from "react-router-dom";
import { Navigation } from '../../components/Navigation/Navigation';
import {apiRequest} from "../../api/request"; import {apiRequest} from "../../api/request";
import {useSelector} from "react-redux";
import { getPartnerRequestInfo } from '../../redux/outstaffingSlice'
import arrowDown from "../../images/selectArrow.png" import arrowDown from "../../images/selectArrow.png"
import processImg from "../../images/partnerAddRequestFirstImg.png" import processImg from "../../images/partnerAddRequestFirstImg.png"
@ -15,15 +18,15 @@ import deleteIcon from "../../images/close.png"
import './partnerAddRequest.scss' import './partnerAddRequest.scss'
import { Navigation } from '../../components/Navigation/Navigation';
export const PartnerAddRequest = () => { export const PartnerAddRequest = () => {
if(localStorage.getItem('role_status') !== '18') { if(localStorage.getItem('role_status') !== '18') {
return <Navigate to="/profile" replace/> return <Navigate to="/profile" replace/>
} }
const partnerRequestInfo = useSelector(getPartnerRequestInfo);
const currentUrl = useState(window.location.pathname)
const navigate= useNavigate(); const navigate= useNavigate();
const [skills, setSkills] = useState([]) const [skills, setSkills] = useState([])
const [filteredSkills, setFilteredSkills] = useState([]) const [filteredSkills, setFilteredSkills] = useState([])
const [specializationList, setSpecializationList] = useState([]) const [specializationList, setSpecializationList] = useState([])
@ -33,12 +36,17 @@ export const PartnerAddRequest = () => {
const [openSpecializationList, setOpenSpecializationListOpen] = useState(false) const [openSpecializationList, setOpenSpecializationListOpen] = useState(false)
const [openLevelList, setOpenLevelList] = useState(false) const [openLevelList, setOpenLevelList] = useState(false)
const [openCountList, setOpenCountList] = useState(false) const [openCountList, setOpenCountList] = useState(false)
const [editRequest, setEditRequest] = useState(false)
const [selectedSkills, setSelectedSkills] = useState([]) const [selectedSkills, setSelectedSkills] = useState([])
const [selectedSpecialization, setSelectedSpecialization] = useState('Выберите специализацию') const [selectedSpecialization, setSelectedSpecialization] = useState('Выберите специализацию')
const [selectedLevel, setSelectedLevel] = useState('Выберите уровень') const [selectedLevel, setSelectedLevel] = useState('Выберите уровень')
const [selectedCount, setSelectedCount] = useState('Выберите кол-во сотрудников') const [selectedCount, setSelectedCount] = useState('Выберите кол-во сотрудников')
const [inputs, setInputs] = useState({title: '', description: ''}) const [inputs, setInputs] = useState({title: '', description: ''})
if (currentUrl[0] === "/profile/edit-request" && !Object.keys(partnerRequestInfo).length) {
return <Navigate to="/profile/requests" replace/>
}
useEffect(() => { useEffect(() => {
apiRequest(`/profile/positions-list`).then((el) => setSpecializationList(el)) apiRequest(`/profile/positions-list`).then((el) => setSpecializationList(el))
apiRequest(`/profile/level-list`).then((el) => setLevelList(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 = () => { const disableBtn = () => {
if (!inputs.title || if (!inputs.title ||
typeof selectedSpecialization === "string" || typeof selectedSpecialization === "string" ||
@ -61,21 +80,40 @@ export const PartnerAddRequest = () => {
} }
const handler = () => { const handler = () => {
apiRequest('/request/create-request', { if (currentUrl[0] === "/profile/edit-request") {
method: 'POST', apiRequest('/request/update-request', {
data: { method: 'PUT',
user_id: localStorage.getItem('id'), data: {
title: inputs.title, user_id: localStorage.getItem('id'),
position_id: selectedSpecialization.id, request_id: partnerRequestInfo.id,
knowledge_level_id: selectedLevel.id, title: inputs.title,
specialist_count: selectedCount, position_id: selectedSpecialization.id,
status: 1, knowledge_level_id: selectedLevel.id,
descr: inputs.description, specialist_count: selectedCount,
skill_ids: selectedSkills.map((skill) => {return skill.id}) status: 1,
} descr: inputs.description,
}).then((res) => { skill_ids: selectedSkills.map((skill) => {return skill.id})
navigate('/profile/requests'); }
}) }).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 = () => {
<ProfileBreadcrumbs links={[ <ProfileBreadcrumbs links={[
{name: 'Главная', link: '/profile'}, {name: 'Главная', link: '/profile'},
{name: 'Запросы и открытые позиции', link: '/profile/requests'}, {name: 'Запросы и открытые позиции', link: '/profile/requests'},
{name: 'Создание новой заявки', link: '/profile/add-request'} {name: `${editRequest ? 'Редактирование заявки' : 'Создание новой заявки'}`, link: '/profile/add-request'}
]} ]}
/> />
<h2 className='partnerAddRequest__title'>Страница добавления заявки</h2> <h2 className='partnerAddRequest__title'>{editRequest ? 'Страница редактирования заявки' : 'Страница добавления заявки'}</h2>
<div className='partnerAddRequest__section'> <div className='partnerAddRequest__section'>
<div className='partnerAddRequest__form'> <div className='partnerAddRequest__form'>
<div className='partnerAddRequest__form__block form__block'> <div className='partnerAddRequest__form__block form__block'>
@ -98,7 +136,7 @@ export const PartnerAddRequest = () => {
<div className='form__block__section'> <div className='form__block__section'>
<h3>Название вакансии</h3> <h3>Название вакансии</h3>
<div className='form__block__section__input'> <div className='form__block__section__input'>
<input onChange={e => setInputs((prevValue) => ({...prevValue, title: e.target.value}) )} type='text' placeholder='Вакансия'/> <input value={inputs.title} onChange={e => setInputs((prevValue) => ({...prevValue, title: e.target.value}) )} type='text' placeholder='Вакансия'/>
</div> </div>
</div> </div>
<div className='form__block__section'> <div className='form__block__section'>
@ -196,7 +234,7 @@ export const PartnerAddRequest = () => {
</div> </div>
<div className='form__block__section'> <div className='form__block__section'>
<h3>Введите необходимое описание</h3> <h3>Введите необходимое описание</h3>
<textarea onChange={e => setInputs((prevValue) => ({...prevValue, description: e.target.value}) )}/> <textarea value={inputs.description} onChange={e => setInputs((prevValue) => ({...prevValue, description: e.target.value}) )}/>
</div> </div>
<div className='form__block__section'> <div className='form__block__section'>
<h3>Необходимое количество человек на позицию</h3> <h3>Необходимое количество человек на позицию</h3>

View File

@ -1,7 +1,7 @@
import React, {useEffect, useState} from 'react'; import React, {useEffect, useState} from 'react';
import {Link, Navigate, useNavigate} from "react-router-dom"; import {Link, Navigate, useNavigate} from "react-router-dom";
import {useSelector, useDispatch} from 'react-redux' import {useSelector, useDispatch} from 'react-redux'
import {getPartnerRequestId, getPartnerRequests, setPartnerRequestId} from '../../redux/outstaffingSlice' import {getPartnerRequestId, getPartnerRequests, setPartnerRequestId, setPartnerRequestInfo} from '../../redux/outstaffingSlice'
import {ProfileHeader} from "../../components/ProfileHeader/ProfileHeader"; import {ProfileHeader} from "../../components/ProfileHeader/ProfileHeader";
import {ProfileBreadcrumbs} from "../../components/ProfileBreadcrumbs/ProfileBreadcrumbs" import {ProfileBreadcrumbs} from "../../components/ProfileBreadcrumbs/ProfileBreadcrumbs"
@ -39,6 +39,7 @@ export const PartnerBid = () => {
setLoader(true) setLoader(true)
apiRequest(`/request/get-request?request_id=${requestId}`).then((el) => { apiRequest(`/request/get-request?request_id=${requestId}`).then((el) => {
setRequestInfo(el) setRequestInfo(el)
dispatch(setPartnerRequestInfo(el))
setLoader(false) setLoader(false)
}) })
}, [requestId]); }, [requestId]);
@ -50,12 +51,6 @@ export const PartnerBid = () => {
user_id: localStorage.getItem('id'), user_id: localStorage.getItem('id'),
request_id: requestId, request_id: requestId,
status: 0, status: 0,
// title: 'bro',
// position_id: 1,
// knowledge_level_id: 2,
// specialist_count: 2,
// descr: 'broooooo',
// skill_ids: [1, 2, 3]
} }
}).then((res) => { }).then((res) => {
navigate('/profile/requests'); navigate('/profile/requests');
@ -88,7 +83,7 @@ export const PartnerBid = () => {
<div className='partnerBid__qualification'> <div className='partnerBid__qualification'>
<h3>{requestInfo.title}</h3> <h3>{requestInfo.title}</h3>
<div className='partnerBid__qualification__buttons'> <div className='partnerBid__qualification__buttons'>
<button>Редактировать</button> <Link to='/profile/edit-request'>Редактировать</Link>
<img src={deleteBtn} alt='delete' onClick={() => deleteRequest()}/> <img src={deleteBtn} alt='delete' onClick={() => deleteRequest()}/>
</div> </div>
</div> </div>

View File

@ -41,7 +41,7 @@
display: flex; display: flex;
align-items: center; align-items: center;
button { a {
max-width: 168px; max-width: 168px;
width: 100%; width: 100%;
height: 48px; height: 48px;
@ -53,6 +53,10 @@
color: #000000; color: #000000;
padding: 8px 24px 10px 32px; padding: 8px 24px 10px 32px;
border: none; border: none;
&:hover {
color: #000000;
}
} }
img { img {

View File

@ -12,7 +12,8 @@ const initialState = {
reportsDates: '', reportsDates: '',
partnerEmployees: [], partnerEmployees: [],
partnerRequestId: null, partnerRequestId: null,
partnerRequests: [] partnerRequests: [],
partnerRequestInfo: {}
}; };
export const outstaffingSlice = createSlice({ export const outstaffingSlice = createSlice({
@ -57,11 +58,14 @@ export const outstaffingSlice = createSlice({
}, },
setPartnerRequests: (state, action) => { setPartnerRequests: (state, action) => {
state.partnerRequests = action.payload state.partnerRequests = action.payload
},
setPartnerRequestInfo: (state, action) => {
state.partnerRequestInfo = action.payload
} }
}, },
}); });
export const { tags, profiles, selectedItems, auth, currentCandidate, filteredCandidates, setPositionId, setUserInfo, setProfileInfo, setReportsDates, setPartnerEmployees, setPartnerRequestId, setPartnerRequests } = outstaffingSlice.actions; export const { tags, profiles, selectedItems, auth, currentCandidate, filteredCandidates, setPositionId, setUserInfo, setProfileInfo, setReportsDates, setPartnerEmployees, setPartnerRequestId, setPartnerRequests, setPartnerRequestInfo } = outstaffingSlice.actions;
export const selectProfiles = (state) => state.outstaffing.profiles; export const selectProfiles = (state) => state.outstaffing.profiles;
export const selectTags = (state) => state.outstaffing.tags; export const selectTags = (state) => state.outstaffing.tags;
@ -71,6 +75,7 @@ export const selectCurrentCandidate = (state) => state.outstaffing.currentCandid
export const selectAuth = (state) => state.outstaffing.auth; export const selectAuth = (state) => state.outstaffing.auth;
export const getPositionId = (state) => state.outstaffing.positionId; export const getPositionId = (state) => state.outstaffing.positionId;
export const getProfileInfo = (state) => state.outstaffing.profileInfo; export const getProfileInfo = (state) => state.outstaffing.profileInfo;
export const getPartnerRequestInfo = (state) => state.outstaffing.partnerRequestInfo;
export const selectUserInfo = (state) => state.outstaffing.userInfo; export const selectUserInfo = (state) => state.outstaffing.userInfo;
export const getReportsDates = (state) => state.outstaffing.reportsDates; export const getReportsDates = (state) => state.outstaffing.reportsDates;
export const getPartnerEmployees = (state) => state.outstaffing.partnerEmployees; export const getPartnerEmployees = (state) => state.outstaffing.partnerEmployees;