[befb988] | 1 | import "../shared_css/Random.css"
|
---|
[19398ad] | 2 |
|
---|
| 3 | import {useDispatch, useSelector} from "react-redux";
|
---|
| 4 | import {useEffect, useState} from "react";
|
---|
| 5 | import {JobAdvertisementActions} from "../../redux/actions/jobAdvertisementActions";
|
---|
[b248810] | 6 | import {formatRelativeTime, sortElementsBy} from "../../utils/utils";
|
---|
[19398ad] | 7 | import {dataRangeOptions, industryOptions, industryOptionsFilter, sortOptions} from "../selectOptions";
|
---|
| 8 | import Select from "react-select";
|
---|
| 9 | import Roles from "../../enumerations/Roles";
|
---|
| 10 | import {Link} from "react-router-dom";
|
---|
| 11 | import JobType from "../../enumerations/JobType";
|
---|
[b248810] | 12 | import {AUTH_TOKEN} from "../../axios/axiosInstance";
|
---|
| 13 | import {jwtDecode} from "jwt-decode";
|
---|
[befb988] | 14 | import {RecruiterActions} from "../../redux/actions/recruiterActions";
|
---|
[19398ad] | 15 |
|
---|
[befb988] | 16 | export const Dashboard = () => {
|
---|
[d8b6c91] | 17 |
|
---|
[19398ad] | 18 | const dispatch = useDispatch();
|
---|
| 19 |
|
---|
| 20 | const [jobAdvertisements, setJobAdvertisements] = useState([]);
|
---|
| 21 | let jobAdvertisementsState = useSelector(state => state.jobAd.jobAdvertisements)
|
---|
[befb988] | 22 | const [jobDispatched, setJobDispatched] = useState(false);
|
---|
| 23 |
|
---|
| 24 | const [logos, setLogos] = useState({});
|
---|
| 25 | let logosState = useSelector(state => state.images.logos)
|
---|
| 26 | const [logoDispatched, setLogoDispatched] = useState(false);
|
---|
| 27 |
|
---|
[b248810] | 28 | const auth = useSelector(state => state.auth);
|
---|
[19398ad] | 29 |
|
---|
[b248810] | 30 | // const [role, setRole] = useState("");
|
---|
[28b3398] | 31 | const [selectedSortOrder, setSelectedSortOrder] = useState("date_newest");
|
---|
| 32 | const [selectedIndustry, setSelectedIndustry] = useState("all");
|
---|
[19398ad] | 33 | const [searchTerm, setSearchTerm] = useState("");
|
---|
[befb988] | 34 |
|
---|
| 35 |
|
---|
[19398ad] | 36 | useEffect(() => {
|
---|
[befb988] | 37 | if (!jobDispatched && jobAdvertisementsState.length == 0) {
|
---|
[19398ad] | 38 | dispatch(JobAdvertisementActions.fetchJobAdvertisements((success, response) => {
|
---|
| 39 | if (success && response.data.length > 0) {
|
---|
[befb988] | 40 | setJobAdvertisements(sortElementsBy(response.data, "postedOn"))
|
---|
[19398ad] | 41 | }
|
---|
[befb988] | 42 | setJobDispatched(true)
|
---|
[19398ad] | 43 | console.log("Fetch all job advertisements GET")
|
---|
| 44 | }))
|
---|
| 45 |
|
---|
| 46 | } else {
|
---|
[08f82ec] | 47 | setJobAdvertisements(sortElementsBy(jobAdvertisementsState, "postedOn"))
|
---|
[19398ad] | 48 | console.log("Fetch all job advertisements STATE")
|
---|
[befb988] | 49 |
|
---|
| 50 |
|
---|
[19398ad] | 51 | }
|
---|
[28b3398] | 52 | }, [jobAdvertisementsState])
|
---|
[19398ad] | 53 |
|
---|
[befb988] | 54 | useEffect(() => {
|
---|
| 55 |
|
---|
| 56 | if(jobDispatched && !logoDispatched) {
|
---|
| 57 | jobAdvertisements.forEach(jobAd => {
|
---|
| 58 | if(jobAd.recruiterId && !logos[jobAd.recruiterId]) {
|
---|
| 59 | fetchLogo(jobAd.recruiterId);
|
---|
| 60 | }
|
---|
| 61 | })
|
---|
| 62 | setLogoDispatched(true)
|
---|
| 63 | console.log("Fetch all logos GET")
|
---|
| 64 | } else {
|
---|
| 65 | setLogos(logosState)
|
---|
| 66 | console.log("Fetch all logos STATE")
|
---|
| 67 | }
|
---|
| 68 |
|
---|
| 69 | }, [jobDispatched, logosState])
|
---|
| 70 |
|
---|
| 71 | const fetchLogo = (recruiterId) => {
|
---|
| 72 | dispatch(RecruiterActions.downloadLogo(recruiterId, (success, response) => {
|
---|
| 73 | if(success) {
|
---|
| 74 | setLogos(prevLogos => ({...prevLogos, [recruiterId]: response}))
|
---|
| 75 | }
|
---|
| 76 | }));
|
---|
| 77 | };
|
---|
| 78 |
|
---|
[28b3398] | 79 | let filterJobAdvertisements = () => {
|
---|
| 80 | JobAdvertisementActions.filterJobAdvertisements(
|
---|
| 81 | {
|
---|
| 82 | searchTerm: searchTerm,
|
---|
| 83 | industry: selectedIndustry,
|
---|
| 84 | sortOrder: selectedSortOrder
|
---|
| 85 | }, (success, response) => {
|
---|
| 86 | if (success) {
|
---|
| 87 | setJobAdvertisements(response.data);
|
---|
| 88 | }
|
---|
| 89 | }
|
---|
| 90 | )
|
---|
| 91 | }
|
---|
[d8b6c91] | 92 |
|
---|
| 93 | return (
|
---|
[b248810] | 94 |
|
---|
[d8b6c91] | 95 | <div className="container">
|
---|
[befb988] | 96 | <div className="filter-container">
|
---|
[19398ad] | 97 | <div className="row">
|
---|
[befb988] | 98 | <div className="col-md-12 filter-box">
|
---|
[28b3398] | 99 | <div className="search-container">
|
---|
| 100 | <i className="fa-solid fa-magnifying-glass search-icon"></i>
|
---|
[19398ad] | 101 | <input
|
---|
| 102 | className="search-input"
|
---|
| 103 | type="text"
|
---|
| 104 | placeholder="Search job advertisement by title..."
|
---|
[28b3398] | 105 | value={searchTerm}
|
---|
| 106 | onChange={event => setSearchTerm(event.target.value)}
|
---|
[19398ad] | 107 | />
|
---|
| 108 | </div>
|
---|
| 109 | <div className="sort-section item">
|
---|
| 110 | <Select
|
---|
| 111 | defaultValue={{value: "all", label: "All industries"}}
|
---|
[28b3398] | 112 | value={selectedIndustry.value}
|
---|
| 113 | onChange={option => setSelectedIndustry(option.value)}
|
---|
[19398ad] | 114 | options={industryOptionsFilter}
|
---|
| 115 | className="sort-range sort"
|
---|
| 116 | />
|
---|
| 117 | </div>
|
---|
| 118 | <div className="sort-section item">
|
---|
| 119 | <Select
|
---|
| 120 | defaultValue={{value: "newest", label: "Date (Newest First)"}}
|
---|
[28b3398] | 121 | value={selectedSortOrder.value}
|
---|
| 122 | onChange={option => setSelectedSortOrder(option.value)}
|
---|
| 123 | options={sortOptions}
|
---|
[19398ad] | 124 | className="sort-range sort"
|
---|
| 125 | />
|
---|
| 126 | </div>
|
---|
[befb988] | 127 | <button onClick={filterJobAdvertisements} className="blue-submit-button">Find jobs</button>
|
---|
[d8b6c91] | 128 | </div>
|
---|
| 129 | </div>
|
---|
| 130 | </div>
|
---|
[befb988] | 131 | <div className="row row-cols-2 row-cols-md-4 g-4">
|
---|
[19398ad] | 132 | {jobAdvertisements &&
|
---|
| 133 | jobAdvertisements.map((jobAd, index) => (
|
---|
| 134 | <div key={index} className="col">
|
---|
[08f82ec] | 135 | <div className="custom-card dashboard-card">
|
---|
[19398ad] | 136 | <div className="card-head">
|
---|
| 137 | <span className="hourly-salary"><b>${jobAd.startingSalary}/hr</b></span>
|
---|
[28b3398] | 138 | <span
|
---|
| 139 | className="job-type"> {jobAd.jobType === JobType.JOB ? "Job" : "Internship"}</span>
|
---|
[19398ad] | 140 | {!jobAd.active && <span className="expired">Expired</span>}
|
---|
| 141 | </div>
|
---|
| 142 | <div className="card-body">
|
---|
[4d97b63] | 143 | <img className="card-company-logo"
|
---|
[befb988] | 144 | // loading gif
|
---|
| 145 | src={logos[jobAd.recruiterId]}
|
---|
| 146 | alt=""
|
---|
| 147 | width={100} height={100}
|
---|
| 148 | />
|
---|
[19398ad] | 149 | <h5 className="card-title">{jobAd.title}</h5>
|
---|
[28b3398] | 150 | <span>{jobAd.industry} • <span style={{
|
---|
| 151 | color: "black",
|
---|
| 152 | fontWeight: "bold"
|
---|
| 153 | }}>{formatRelativeTime(jobAd.postedOn)}</span></span>
|
---|
[19398ad] | 154 | <div className="card-info">
|
---|
[28b3398] | 155 | <span><i className="fa-solid fa-building"
|
---|
| 156 | style={{color: "#000000"}}></i> Company: <span style={{
|
---|
| 157 | color: "black",
|
---|
| 158 | fontWeight: "bold"
|
---|
| 159 | }}>{jobAd.recruiterName}</span></span> <br/>
|
---|
[19398ad] | 160 | </div>
|
---|
[d8b6c91] | 161 |
|
---|
[08f82ec] | 162 | </div>
|
---|
| 163 | <div className="card-foot">
|
---|
| 164 | <Link to={`/job-advertisements/${jobAd.id}`} className="card-button">Read
|
---|
| 165 | more</Link>
|
---|
[19398ad] | 166 | </div>
|
---|
| 167 | </div>
|
---|
| 168 | </div>
|
---|
| 169 | ))}
|
---|
| 170 |
|
---|
| 171 | </div>
|
---|
[d8b6c91] | 172 | </div>
|
---|
| 173 | )
|
---|
| 174 | } |
---|