| @@ -23,6 +23,7 @@ import { format, isValid } from "date-fns"; | |||
| import { useEffect } from "react"; | |||
| import { SelectionContext } from "../../context/SelectionContext"; | |||
| import { setUpdateStatusReq } from "../../store/actions/processes/processAction"; | |||
| import { createScreeningTest } from "../../store/actions/screeningTests/screeningTestActions"; | |||
| const StatusDialog = ({ | |||
| title, | |||
| @@ -34,16 +35,18 @@ const StatusDialog = ({ | |||
| fullWidth, | |||
| responsive, | |||
| }) => { | |||
| const [selected, setSelected] = useState(""); | |||
| const [selected, setSelected] = useState(''); | |||
| const [value, setValue] = useState(null); | |||
| const [selectedScreeningTest, setSelectedScreeningTest] = useState(""); | |||
| const { activeProcess, setActiveProcess } = useContext(SelectionContext) | |||
| const { activeProcess, setActiveProcess } = useContext(SelectionContext); | |||
| const theme = useTheme(); | |||
| const fullScreen = useMediaQuery(theme.breakpoints.down("md")); | |||
| const { users } = useSelector((s) => s.users); | |||
| const { isSuccess } = useSelector((s) => s.initProcess); | |||
| const { screeningTests } = useSelector((s) => s.screeningTests); | |||
| const dispatch = useDispatch(); | |||
| @@ -52,22 +55,26 @@ const StatusDialog = ({ | |||
| }, [dispatch, isSuccess]); | |||
| const handleChange = (newValue) => { | |||
| if (isValid(newValue)) { // throws an error if invalid value is set | |||
| if (isValid(newValue)) { | |||
| // throws an error if invalid value is set | |||
| var date = format(newValue, "yyyy-MM-dd'T'HH:mm:ss.SSSxxx"); | |||
| setValue(date); | |||
| } | |||
| }; | |||
| useEffect(()=>{ | |||
| setSelected('') | |||
| setValue(null) | |||
| }, [onClose]) | |||
| useEffect(() => { | |||
| setSelected(''); | |||
| setValue(null); | |||
| setSelectedScreeningTest("") | |||
| }, [onClose]); | |||
| const handleClose = () => { | |||
| onClose(); | |||
| }; | |||
| const submitHandler = () => { | |||
| console.log(selected) | |||
| if (activeProcess.process.selectionLevelId !== 2) { | |||
| dispatch( | |||
| setUpdateStatusReq({ | |||
| data: { | |||
| @@ -76,14 +83,42 @@ const StatusDialog = ({ | |||
| newStatus: activeProcess.status, | |||
| processId: activeProcess.process.id, | |||
| }, | |||
| responseHandler: apiSuccess | |||
| responseHandler: apiSuccess, | |||
| }) | |||
| ); | |||
| } else { | |||
| dispatch( | |||
| setUpdateStatusReq({ | |||
| data: { | |||
| schedulerId: selected, | |||
| appointment: value, | |||
| newStatus: activeProcess.status, | |||
| processId: activeProcess.process.id, | |||
| }, | |||
| responseHandler: apiSuccessScreeningTests, | |||
| }) | |||
| ); | |||
| } | |||
| }; | |||
| const apiSuccessScreeningTests = () => { | |||
| const user = users.find(k => k.id === selected) | |||
| dispatch( | |||
| createScreeningTest({ | |||
| adminEmail: user.email, | |||
| email: activeProcess.process.applicant.email, | |||
| duration: 60, | |||
| testId: parseInt(selectedScreeningTest), | |||
| url: "https:dzenis-meris.com", | |||
| }) | |||
| ); | |||
| setActiveProcess(null); | |||
| }; | |||
| const apiSuccess = () =>{ | |||
| setActiveProcess(null) | |||
| } | |||
| const apiSuccess = () => { | |||
| setActiveProcess(null); | |||
| }; | |||
| return ( | |||
| <Dialog | |||
| @@ -154,7 +189,7 @@ const StatusDialog = ({ | |||
| <form className="modal-content interviewDialog"> | |||
| <FormControl fullWidth> | |||
| <InputLabel id="demo-simple-select-label"> | |||
| Ime intervjuera | |||
| Ime intervjuera | |||
| </InputLabel> | |||
| <Select | |||
| labelId="demo-simple-select-label" | |||
| @@ -166,20 +201,48 @@ const StatusDialog = ({ | |||
| }} | |||
| > | |||
| {users | |||
| ? users.map( | |||
| ({ id, firstName, lastName }, index) => ( | |||
| <MenuItem | |||
| key={index} | |||
| sx={{ textAlign: "left" }} | |||
| value={id} | |||
| > | |||
| {firstName} {lastName} | |||
| </MenuItem> | |||
| ) | |||
| ) | |||
| ? users.map(({ id, firstName, lastName }, index) => ( | |||
| <MenuItem | |||
| key={index} | |||
| sx={{ textAlign: "left" }} | |||
| value={id} | |||
| > | |||
| {firstName} {lastName} | |||
| </MenuItem> | |||
| )) | |||
| : ""} | |||
| </Select> | |||
| </FormControl> | |||
| {activeProcess !== null && | |||
| activeProcess.process.selectionLevelId === 2 && ( | |||
| <FormControl fullWidth> | |||
| <InputLabel id="demo-simple-select-label"> | |||
| Screening test | |||
| </InputLabel> | |||
| <Select | |||
| labelId="demo-simple-select-label" | |||
| id="demo-simple-select" | |||
| value={selectedScreeningTest} | |||
| label="Screening test" | |||
| onChange={(e) => { | |||
| setSelectedScreeningTest(e.target.value); | |||
| }} | |||
| > | |||
| {screeningTests | |||
| ? screeningTests.map((screeningTest, index) => ( | |||
| <MenuItem | |||
| key={index} | |||
| sx={{ textAlign: "left" }} | |||
| value={screeningTest.id} | |||
| > | |||
| {screeningTest.name} | |||
| </MenuItem> | |||
| )) | |||
| : ""} | |||
| </Select> | |||
| </FormControl> | |||
| )} | |||
| {/* {activeProcess.process && activeProcess.process.date ? <p>Proces ima zakazan termin</p> : ''} */} | |||
| <DateTimePicker | |||
| label="Termin" | |||
| @@ -19,6 +19,7 @@ import forbiden from "../../assets/images/forbiden.png"; | |||
| import { AdapterDateFns } from "@mui/x-date-pickers/AdapterDateFns"; | |||
| import { LocalizationProvider } from "@mui/x-date-pickers"; | |||
| import { fetchCandidateOptions } from "../../store/actions/candidates/candidatesActions"; | |||
| import { fetchScreeningTests } from "../../store/actions/screeningTests/screeningTestActions"; | |||
| import { SelectionContext } from "../../context/SelectionContext"; | |||
| import { setUsersReq } from "../../store/actions/users/usersActions"; | |||
| import StatusDialog from "../../components/MUI/StatusDialog"; | |||
| @@ -52,6 +53,7 @@ const SelectionProcessPage = ({ history }) => { | |||
| useEffect(() => { | |||
| dispatch(fetchCandidateOptions()); | |||
| dispatch(setProcessesReq()); | |||
| dispatch(fetchScreeningTests()); | |||
| dispatch(setUsersReq()); | |||
| const s = [ | |||
| { isChecked: false, name: "Zakazan" }, | |||
| @@ -42,7 +42,7 @@ export default { | |||
| doneProcess: base + "/selectionprocesses", | |||
| getApplicantProcesses: base + "/applicants/processes", | |||
| changeStatus: base + "/selectionprocesses/status-update", | |||
| changeInterviewer: base + "/selectionprocesses/interviewer-update" | |||
| changeInterviewer: base + "/selectionprocesses/interviewer-update", | |||
| // allProcesses: base + "/selectionprocesses", | |||
| }, | |||
| patterns: { | |||
| @@ -65,4 +65,8 @@ export default { | |||
| applyForAd: base + "/applicants/apply-for-ad", | |||
| getCV: base + "/applicants/get-CV", | |||
| }, | |||
| screeningTest: { | |||
| allTests: base + "/screeningtest", | |||
| createTest:base + '/screeningtest' | |||
| }, | |||
| }; | |||
| @@ -0,0 +1,6 @@ | |||
| import { getRequest, postRequest } from "."; | |||
| import apiEndpoints from "./apiEndpoints"; | |||
| export const getTests = () => getRequest(apiEndpoints.screeningTest.allTests); | |||
| export const createTest = (payload) => | |||
| postRequest(apiEndpoints.screeningTest.createTest,payload); | |||
| @@ -0,0 +1,37 @@ | |||
| import { | |||
| SCREENING_TESTS_FETCH, | |||
| SCREENING_TESTS_ERROR, | |||
| SCREENING_TESTS_SUCCESS, | |||
| CREATE_SCREENING_TEST, | |||
| CREATE_SCREENING_TEST_ERROR, | |||
| CREATE_SCREENING_TEST_SUCCESS, | |||
| } from "./screeningTestsActionConstants"; | |||
| export const fetchScreeningTests = () => ({ | |||
| type: SCREENING_TESTS_FETCH, | |||
| }); | |||
| export const fetchScreeningTestsError = (payload) => ({ | |||
| type: SCREENING_TESTS_ERROR, | |||
| payload, | |||
| }); | |||
| export const fetchScreeningTestsSuccess = (payload) => ({ | |||
| type: SCREENING_TESTS_SUCCESS, | |||
| payload, | |||
| }); | |||
| export const createScreeningTest = (payload) => ({ | |||
| type: CREATE_SCREENING_TEST, | |||
| payload, | |||
| }); | |||
| export const createScreeningTestError = (payload) => ({ | |||
| type: CREATE_SCREENING_TEST_ERROR, | |||
| payload, | |||
| }); | |||
| export const createScreeningTestSuccess = (payload) => ({ | |||
| type: CREATE_SCREENING_TEST_SUCCESS, | |||
| payload, | |||
| }); | |||
| @@ -0,0 +1,19 @@ | |||
| import { | |||
| createErrorType, | |||
| createFetchType, | |||
| createLoadingType, | |||
| createSuccessType, | |||
| } from "../actionHelpers"; | |||
| const SCREENING_TESTS_SCOPE = "SCREENING_TESTS"; | |||
| const CREATE_SCREENING_TEST_SCOPE = "CREATE_SCREENING_TEST"; | |||
| export const SCREENING_TESTS_FETCH = createFetchType(SCREENING_TESTS_SCOPE); | |||
| export const SCREENING_TESTS_ERROR = createErrorType(SCREENING_TESTS_SCOPE); | |||
| export const SCREENING_TESTS_SUCCESS = createSuccessType(SCREENING_TESTS_SCOPE); | |||
| export const SCREENING_TESTS_LOADING = createLoadingType(SCREENING_TESTS_SCOPE); | |||
| export const CREATE_SCREENING_TEST = createFetchType(CREATE_SCREENING_TEST_SCOPE); | |||
| export const CREATE_SCREENING_TEST_ERROR = createErrorType(CREATE_SCREENING_TEST_SCOPE); | |||
| export const CREATE_SCREENING_TEST_SUCCESS = createSuccessType(CREATE_SCREENING_TEST_SCOPE); | |||
| export const CREATE_SCREENING_TEST_LOADING = createLoadingType(CREATE_SCREENING_TEST_SCOPE); | |||
| @@ -33,6 +33,7 @@ import initProcessReducer from "./candidates/initProcessReducer"; | |||
| import applyForAdReducer from "./applicants/applyForAdReducer"; | |||
| import statusUpdateReducer from "./processes/statusUpdateReducer"; | |||
| import interviewerUpdateReducer from "./processes/interviewerUpdateReducer"; | |||
| import screeningTestsReducer from "./screeningTests/screeningTestsReducer"; | |||
| export default combineReducers({ | |||
| login: loginReducer, | |||
| @@ -68,5 +69,6 @@ export default combineReducers({ | |||
| patternApplicants: patternApplicantsReducer, | |||
| applyForAd: applyForAdReducer, | |||
| statusUpdate: statusUpdateReducer, | |||
| interviewerUpdate: interviewerUpdateReducer | |||
| interviewerUpdate: interviewerUpdateReducer, | |||
| screeningTests:screeningTestsReducer | |||
| }); | |||
| @@ -0,0 +1,32 @@ | |||
| import createReducer from "../../utils/createReducer"; | |||
| import { | |||
| SCREENING_TESTS_ERROR, | |||
| SCREENING_TESTS_SUCCESS, | |||
| } from "../../actions/screeningTests/screeningTestsActionConstants"; | |||
| const initialState = { | |||
| screeningTests: [], | |||
| errorMessage: "", | |||
| }; | |||
| export default createReducer( | |||
| { | |||
| [SCREENING_TESTS_SUCCESS]: setScreeningTests, | |||
| [SCREENING_TESTS_ERROR]: setScreeningTestsError, | |||
| }, | |||
| initialState | |||
| ); | |||
| function setScreeningTests(state, action) { | |||
| return { | |||
| ...state, | |||
| screeningTests: action.payload, | |||
| }; | |||
| } | |||
| function setScreeningTestsError(state, action) { | |||
| return { | |||
| ...state, | |||
| errorMessage: action.payload, | |||
| }; | |||
| } | |||
| @@ -10,6 +10,7 @@ import statsSaga from "./statsSaga"; | |||
| import scheduleSaga from "./scheduleSaga"; | |||
| import registerSaga from "./registerSaga"; | |||
| import applicantsSaga from "./applicantsSaga"; | |||
| import screeningTestsSaga from "./screeningTestsSaga"; | |||
| export default function* rootSaga() { | |||
| yield all([ | |||
| @@ -24,5 +25,6 @@ export default function* rootSaga() { | |||
| scheduleSaga(), | |||
| registerSaga(), | |||
| applicantsSaga(), | |||
| screeningTestsSaga() | |||
| ]); | |||
| } | |||
| @@ -0,0 +1,46 @@ | |||
| import { all, call, put, takeEvery } from "redux-saga/effects"; | |||
| import { JWT_TOKEN } from "../../constants/localStorage"; | |||
| import { addHeaderToken } from "../../request"; | |||
| import { getTests, createTest } from "../../request/screeningTestRequest"; | |||
| import { authScopeStringGetHelper } from "../../util/helpers/authScopeHelpers"; | |||
| import { rejectErrorCodeHelper } from "../../util/helpers/rejectErrorCodeHelper"; | |||
| import { SCREENING_TESTS_FETCH,CREATE_SCREENING_TEST } from "../actions/screeningTests/screeningTestsActionConstants"; | |||
| import { | |||
| fetchScreeningTestsError, | |||
| fetchScreeningTestsSuccess, | |||
| createScreeningTestSuccess, | |||
| createScreeningTestError, | |||
| } from "../actions/screeningTests/screeningTestActions"; | |||
| export function* getScreeningTests() { | |||
| try { | |||
| const JwtToken = yield call(authScopeStringGetHelper, JWT_TOKEN); | |||
| yield call(addHeaderToken, JwtToken); | |||
| const result = yield call(getTests); | |||
| yield put(fetchScreeningTestsSuccess(result.data)); | |||
| } catch (error) { | |||
| if (error.response && error.response.data) { | |||
| const errorMessage = yield call(rejectErrorCodeHelper, error); | |||
| yield put(fetchScreeningTestsError(errorMessage)); | |||
| } | |||
| } | |||
| } | |||
| export function* createScreeningTest({ payload }) { | |||
| try { | |||
| const JwtToken = yield call(authScopeStringGetHelper, JWT_TOKEN); | |||
| yield call(addHeaderToken, JwtToken); | |||
| const result = yield call(createTest, payload); | |||
| yield put(createScreeningTestSuccess(result.data)); | |||
| } catch (error) { | |||
| if (error.response && error.response.data) { | |||
| const errorMessage = yield call(rejectErrorCodeHelper, error); | |||
| yield put(createScreeningTestError(errorMessage)); | |||
| } | |||
| } | |||
| } | |||
| export default function* screeningTestsSaga() { | |||
| yield all([takeEvery(SCREENING_TESTS_FETCH, getScreeningTests)]); | |||
| yield all([takeEvery(CREATE_SCREENING_TEST, createScreeningTest)]); | |||
| } | |||
| @@ -1,8 +1,3 @@ | |||
| // export const selectAdsCandidates = createSelector( | |||
| // adsCandidatesSelector, | |||
| // (state) => state.adsCandidates, | |||
| // ); | |||
| import { createSelector } from "@reduxjs/toolkit"; | |||
| export const candidatesSelector = (state) => state.candidates; | |||
| @@ -0,0 +1,13 @@ | |||
| import { createSelector } from "@reduxjs/toolkit"; | |||
| export const screeningTestsSelector = (state) => state.screeningTests; | |||
| export const selectScreeningTests = createSelector( | |||
| screeningTestsSelector, | |||
| (state) => state.screeningTests | |||
| ); | |||
| export const selectScreeningTestsError = createSelector( | |||
| screeningTestsSelector, | |||
| (state) => state.errorMessage | |||
| ); | |||