import {useDispatch, useSelector} from "react-redux"; import {useEffect, useState} from "react"; import {ApplicationActions} from "../../redux/actions/applicationActions"; import {ApplicationDetailsModal} from "./ApplicationDetailsModal"; import Select from "react-select"; import {RecruiterActions} from "../../redux/actions/recruiterActions"; import {sortElementsBy} from "../../utils/utils"; import {Link} from "react-router-dom"; export const ApplicationsByJobSeeker = () => { const dispatch = useDispatch(); const auth = useSelector(state => state.auth.currentUser); const [applicationsByJobSeeker, setApplicationsByJobSeeker] = useState([]); let applicationsByJobSeekerState = useSelector(state => state.appl.applicationsByJobSeeker); const [dispatched, setDispatched] = useState(false); const [logos, setLogos] = useState({}); let logosState = useSelector(state => state.images.logos) const [logoDispatched, setLogoDispatched] = useState(false); useEffect(() => { if(!dispatched && (applicationsByJobSeekerState.length === 0 || applicationsByJobSeekerState.length === 1) ) { dispatch(ApplicationActions.fetchApplicationsByJobSeeker(auth.id, (success, response) => { if(success && response.data.length > 0) { setApplicationsByJobSeeker(sortElementsBy(response.data, "submittedOn")); } setDispatched(true) console.log("Fetch applications by job seeker GET") })) } else { setApplicationsByJobSeeker(sortElementsBy(applicationsByJobSeekerState, "submittedOn")); console.log("Fetch applications by job seeker STATE") } }, [applicationsByJobSeekerState]) useEffect(() => { if(dispatched && !logoDispatched) { applicationsByJobSeeker.forEach(jobAd => { if(jobAd.recruiterId && !logos[jobAd.recruiterId]) { fetchLogo(jobAd.recruiterId); } }) setLogoDispatched(true) console.log("Fetch all logos GET") } else if (logoDispatched){ setLogos(logosState) console.log("Fetch all logos STATE") } }, [dispatched, logosState]) const fetchLogo = (recruiterId) => { dispatch(RecruiterActions.downloadLogo(recruiterId, (success, response) => { if(success) { setLogos(prevLogos => ({...prevLogos, [recruiterId]: response})) } })); }; const options = [ {value: 'PROPOSED', label: Proposed}, {value: 'UNDER_REVIEW', label: Under Review}, {value: 'ACCEPTED', label: Accepted}, {value: 'DENIED', label: Denied} ]; let handleDefaultValue = (status) => { return options.find(option => option.value === status); } return (

Application history

{applicationsByJobSeeker && applicationsByJobSeeker.map((application, index) => (
{application.jobAdTitle} {/*
*/}
{application.recruiterName}
{application.recruiterEmail}
{application.recruiterPhoneNumber}
• Submitted on {new Date(application.submittedOn).toLocaleString('default', { day: 'numeric', month: 'long', year: 'numeric' })}
<> {handleDefaultValue(application.status).label} {/*
*/} {/*