1 | import "../shared_css/Random.css"
|
---|
2 |
|
---|
3 | import {useDispatch, useSelector} from "react-redux";
|
---|
4 | import {useEffect, useState} from "react";
|
---|
5 | import {JobAdvertisementActions} from "../../redux/actions/jobAdvertisementActions";
|
---|
6 | import {formatRelativeTime, sortElementsBy} from "../../utils/utils";
|
---|
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";
|
---|
12 | import {AUTH_TOKEN} from "../../axios/axiosInstance";
|
---|
13 | import {jwtDecode} from "jwt-decode";
|
---|
14 | import {RecruiterActions} from "../../redux/actions/recruiterActions";
|
---|
15 |
|
---|
16 | export const Dashboard = () => {
|
---|
17 |
|
---|
18 | const dispatch = useDispatch();
|
---|
19 |
|
---|
20 | const [jobAdvertisements, setJobAdvertisements] = useState([]);
|
---|
21 | let jobAdvertisementsState = useSelector(state => state.jobAd.jobAdvertisements)
|
---|
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 |
|
---|
28 | const auth = useSelector(state => state.auth);
|
---|
29 |
|
---|
30 | // const [role, setRole] = useState("");
|
---|
31 | const [selectedSortOrder, setSelectedSortOrder] = useState("date_newest");
|
---|
32 | const [selectedIndustry, setSelectedIndustry] = useState("all");
|
---|
33 | const [searchTerm, setSearchTerm] = useState("");
|
---|
34 |
|
---|
35 |
|
---|
36 | useEffect(() => {
|
---|
37 | if (!jobDispatched && jobAdvertisementsState.length == 0) {
|
---|
38 | dispatch(JobAdvertisementActions.fetchJobAdvertisements((success, response) => {
|
---|
39 | if (success && response.data.length > 0) {
|
---|
40 | setJobAdvertisements(sortElementsBy(response.data, "postedOn"))
|
---|
41 | }
|
---|
42 | setJobDispatched(true)
|
---|
43 | console.log("Fetch all job advertisements GET")
|
---|
44 | }))
|
---|
45 |
|
---|
46 | } else {
|
---|
47 | setJobAdvertisements(sortElementsBy(jobAdvertisementsState, "postedOn"))
|
---|
48 | console.log("Fetch all job advertisements STATE")
|
---|
49 |
|
---|
50 |
|
---|
51 | }
|
---|
52 | }, [jobAdvertisementsState])
|
---|
53 |
|
---|
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 |
|
---|
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 | }
|
---|
92 |
|
---|
93 | return (
|
---|
94 |
|
---|
95 | <div className="container">
|
---|
96 | <div className="filter-container">
|
---|
97 | <div className="row">
|
---|
98 | <div className="col-md-12 filter-box">
|
---|
99 | <div className="search-container">
|
---|
100 | <i className="fa-solid fa-magnifying-glass search-icon"></i>
|
---|
101 | <input
|
---|
102 | className="search-input"
|
---|
103 | type="text"
|
---|
104 | placeholder="Search job advertisement by title..."
|
---|
105 | value={searchTerm}
|
---|
106 | onChange={event => setSearchTerm(event.target.value)}
|
---|
107 | />
|
---|
108 | </div>
|
---|
109 | <div className="sort-section item">
|
---|
110 | <Select
|
---|
111 | defaultValue={{value: "all", label: "All industries"}}
|
---|
112 | value={selectedIndustry.value}
|
---|
113 | onChange={option => setSelectedIndustry(option.value)}
|
---|
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)"}}
|
---|
121 | value={selectedSortOrder.value}
|
---|
122 | onChange={option => setSelectedSortOrder(option.value)}
|
---|
123 | options={sortOptions}
|
---|
124 | className="sort-range sort"
|
---|
125 | />
|
---|
126 | </div>
|
---|
127 | <button onClick={filterJobAdvertisements} className="blue-submit-button">Find jobs</button>
|
---|
128 | </div>
|
---|
129 | </div>
|
---|
130 | </div>
|
---|
131 | <div className="row row-cols-2 row-cols-md-4 g-4">
|
---|
132 | {jobAdvertisements &&
|
---|
133 | jobAdvertisements.map((jobAd, index) => (
|
---|
134 | <div key={index} className="col">
|
---|
135 | <div className="custom-card dashboard-card">
|
---|
136 | <div className="card-head">
|
---|
137 | <span className="hourly-salary"><b>${jobAd.startingSalary}/hr</b></span>
|
---|
138 | <span
|
---|
139 | className="job-type"> {jobAd.jobType === JobType.JOB ? "Job" : "Internship"}</span>
|
---|
140 | {!jobAd.active && <span className="expired">Expired</span>}
|
---|
141 | </div>
|
---|
142 | <div className="card-body">
|
---|
143 | <img className="card-company-logo"
|
---|
144 | // loading gif
|
---|
145 | src={logos[jobAd.recruiterId]}
|
---|
146 | alt=""
|
---|
147 | width={100} height={100}
|
---|
148 | />
|
---|
149 | <h5 className="card-title">{jobAd.title}</h5>
|
---|
150 | <span>{jobAd.industry} • <span style={{
|
---|
151 | color: "black",
|
---|
152 | fontWeight: "bold"
|
---|
153 | }}>{formatRelativeTime(jobAd.postedOn)}</span></span>
|
---|
154 | <div className="card-info">
|
---|
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/>
|
---|
160 | </div>
|
---|
161 |
|
---|
162 | </div>
|
---|
163 | <div className="card-foot">
|
---|
164 | <Link to={`/job-advertisements/${jobAd.id}`} className="card-button">Read
|
---|
165 | more</Link>
|
---|
166 | </div>
|
---|
167 | </div>
|
---|
168 | </div>
|
---|
169 | ))}
|
---|
170 |
|
---|
171 | </div>
|
---|
172 | </div>
|
---|
173 | )
|
---|
174 | } |
---|