Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 | 2x 3x 3x 3x 3x 3x 3x 1x 1x 1x 1x 3x 1x 1x 3x 1x 2x 1x 1x 1x 1x | import React, { useState } from 'react';
import { Link } from 'react-router-dom';
import { useQuery } from 'react-query';
import axios from 'axios';
import { useAuth } from '../contexts/AuthContext';
import { Search, MapPin, Clock, DollarSign, Briefcase, Plus } from 'lucide-react';
const Jobs = () => {
const { user } = useAuth();
const [filters, setFilters] = useState({
search: '',
location: '',
employmentType: '',
experienceLevel: ''
});
const {
data,
isLoading,
isError,
error,
refetch
} = useQuery(['jobs', filters], async () => {
const params = new URLSearchParams();
Object.entries(filters).forEach(([key, value]) => {
if (value) params.append(key, value);
});
const response = await axios.get(`/api/jobs?${params.toString()}`);
return response.data;
});
const handleFilterChange = (e) => {
setFilters({
...filters,
[e.target.name]: e.target.value
});
};
const handleSearch = (e) => {
e.preventDefault();
refetch();
};
const formatSalary = (min, max, currency = 'USD') => {
Iif (!min && !max) return 'Salary not specified';
Iif (!min) return `Up to ${currency} ${max?.toLocaleString()}`;
Iif (!max) return `From ${currency} ${min?.toLocaleString()}`;
return `${currency} ${min?.toLocaleString()} - ${max?.toLocaleString()}`;
};
const getStatusColor = (status) => {
switch (status) {
case 'active': return 'bg-green-100 text-green-800';
case 'paused': return 'bg-yellow-100 text-yellow-800';
case 'closed': return 'bg-red-100 text-red-800';
default: return 'bg-gray-100 text-gray-800';
}
};
if (isLoading) {
return (
<div className="flex items-center justify-center h-64">
<div
role="status"
aria-label="Loading jobs"
className="animate-spin rounded-full h-32 w-32 border-b-2 border-primary-600"
></div>
</div>
);
}
if (isError) {
return (
<div className="flex flex-col items-center justify-center h-64 text-center space-y-3">
<h2 className="text-xl font-semibold text-gray-800">Unable to load jobs</h2>
<p className="text-sm text-gray-500">{error?.message || 'Please try again later.'}</p>
<button
type="button"
onClick={() => refetch()}
className="btn btn-primary"
>
Retry
</button>
</div>
);
}
return (
<div className="space-y-6">
<div className="flex items-center justify-between">
<div>
<h1 className="text-2xl font-bold text-gray-900">Job Postings</h1>
<p className="mt-1 text-sm text-gray-500">
Find your next career opportunity
</p>
</div>
{(user?.role === 'employer' || user?.role === 'recruiter') && (
<Link
to="/jobs/create"
className="btn btn-primary"
>
<Plus className="h-4 w-4 mr-2" />
Post a Job
</Link>
)}
</div>
{/* Filters */}
<div className="bg-white shadow rounded-lg">
<div className="px-4 py-5 sm:p-6">
<form onSubmit={handleSearch} className="space-y-4">
<div className="grid grid-cols-1 gap-4 sm:grid-cols-2 lg:grid-cols-4">
<div>
<label htmlFor="search" className="block text-sm font-medium text-gray-700">
Search
</label>
<div className="mt-1 relative">
<div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
<Search className="h-5 w-5 text-gray-400" />
</div>
<input
type="text"
name="search"
id="search"
className="block w-full pl-10 pr-3 py-2 border border-gray-300 rounded-md leading-5 bg-white placeholder-gray-500 focus:outline-none focus:placeholder-gray-400 focus:ring-1 focus:ring-primary-500 focus:border-primary-500 sm:text-sm"
placeholder="Job title or keywords"
value={filters.search}
onChange={handleFilterChange}
/>
</div>
</div>
<div>
<label htmlFor="location" className="block text-sm font-medium text-gray-700">
Location
</label>
<div className="mt-1 relative">
<div className="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
<MapPin className="h-5 w-5 text-gray-400" />
</div>
<input
type="text"
name="location"
id="location"
className="block w-full pl-10 pr-3 py-2 border border-gray-300 rounded-md leading-5 bg-white placeholder-gray-500 focus:outline-none focus:placeholder-gray-400 focus:ring-1 focus:ring-primary-500 focus:border-primary-500 sm:text-sm"
placeholder="City, state, or remote"
value={filters.location}
onChange={handleFilterChange}
/>
</div>
</div>
<div>
<label htmlFor="employmentType" className="block text-sm font-medium text-gray-700">
Employment Type
</label>
<select
id="employmentType"
name="employmentType"
className="mt-1 block w-full pl-3 pr-10 py-2 text-base border border-gray-300 focus:outline-none focus:ring-primary-500 focus:border-primary-500 sm:text-sm rounded-md"
value={filters.employmentType}
onChange={handleFilterChange}
>
<option value="">All Types</option>
<option value="full-time">Full-time</option>
<option value="part-time">Part-time</option>
<option value="contract">Contract</option>
<option value="internship">Internship</option>
</select>
</div>
<div>
<label htmlFor="experienceLevel" className="block text-sm font-medium text-gray-700">
Experience Level
</label>
<select
id="experienceLevel"
name="experienceLevel"
className="mt-1 block w-full pl-3 pr-10 py-2 text-base border border-gray-300 focus:outline-none focus:ring-primary-500 focus:border-primary-500 sm:text-sm rounded-md"
value={filters.experienceLevel}
onChange={handleFilterChange}
>
<option value="">All Levels</option>
<option value="entry">Entry Level</option>
<option value="mid">Mid Level</option>
<option value="senior">Senior Level</option>
<option value="lead">Lead</option>
<option value="executive">Executive</option>
</select>
</div>
</div>
<div className="flex justify-end">
<button
type="submit"
className="btn btn-primary"
>
Search Jobs
</button>
</div>
</form>
</div>
</div>
{/* Jobs List */}
<div className="space-y-4">
{data?.jobs?.length > 0 ? (
data.jobs.map((job) => (
<div key={job.id} className="bg-white shadow rounded-lg">
<div className="px-4 py-5 sm:p-6">
<div className="flex items-start justify-between">
<div className="flex-1">
<div className="flex items-center">
<h3 className="text-lg font-medium text-gray-900">
<Link to={`/jobs/${job.id}`} className="hover:text-primary-600">
{job.title}
</Link>
</h3>
<span className={`ml-3 inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium ${getStatusColor(job.status)}`}>
{job.status}
</span>
</div>
<div className="mt-1 flex items-center text-sm text-gray-500">
<Briefcase className="h-4 w-4 mr-1" />
{job.company_name}
</div>
<div className="mt-2 flex items-center text-sm text-gray-500 space-x-4">
<div className="flex items-center">
<MapPin className="h-4 w-4 mr-1" />
{job.location}
{job.remote_allowed && <span className="ml-1">(Remote OK)</span>}
</div>
<div className="flex items-center">
<DollarSign className="h-4 w-4 mr-1" />
{formatSalary(job.salary_min, job.salary_max, job.currency)}
</div>
<div className="flex items-center">
<Clock className="h-4 w-4 mr-1" />
{new Date(job.created_at).toLocaleDateString()}
</div>
</div>
<div className="mt-3">
<p className="text-sm text-gray-600 line-clamp-2">
{job.description}
</p>
</div>
{job.skills_required && job.skills_required.length > 0 && (
<div className="mt-3">
<div className="flex flex-wrap gap-2">
{job.skills_required.slice(0, 5).map((skill, index) => (
<span
key={index}
className="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-primary-100 text-primary-800"
>
{skill}
</span>
))}
{job.skills_required.length > 5 && (
<span className="text-xs text-gray-500">
+{job.skills_required.length - 5} more
</span>
)}
</div>
</div>
)}
</div>
</div>
</div>
</div>
))
) : (
<div className="text-center py-12">
<Briefcase className="mx-auto h-12 w-12 text-gray-400" />
<h3 className="mt-2 text-sm font-medium text-gray-900">No jobs found</h3>
<p className="mt-1 text-sm text-gray-500">
Try adjusting your search criteria
</p>
</div>
)}
</div>
{/* Pagination */}
{data?.pagination && data.pagination.pages > 1 && (
<div className="bg-white px-4 py-3 flex items-center justify-between border-t border-gray-200 sm:px-6">
<div className="flex-1 flex justify-between sm:hidden">
<button className="relative inline-flex items-center px-4 py-2 border border-gray-300 text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50">
Previous
</button>
<button className="ml-3 relative inline-flex items-center px-4 py-2 border border-gray-300 text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50">
Next
</button>
</div>
<div className="hidden sm:flex-1 sm:flex sm:items-center sm:justify-between">
<div>
<p className="text-sm text-gray-700">
Showing{' '}
<span className="font-medium">
{((data.pagination.page - 1) * data.pagination.limit) + 1}
</span>{' '}
to{' '}
<span className="font-medium">
{Math.min(data.pagination.page * data.pagination.limit, data.pagination.total)}
</span>{' '}
of{' '}
<span className="font-medium">{data.pagination.total}</span>{' '}
results
</p>
</div>
</div>
</div>
)}
</div>
);
};
export default Jobs;
|