File size: 15,252 Bytes
c7fb8cf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
/**
 * JobForm.jsx
 * The main HR input form: job details, filters, and drag-and-drop resume upload.
 */
import { useState, useRef, useCallback } from 'react';
import {
  Briefcase, FileText, Star, Clock, GraduationCap, Award,
  MapPin, Globe, Upload, X, ChevronDown, ChevronUp, Zap, Users
} from 'lucide-react';

export default function JobForm({ onSubmit, loading }) {
  // ── Job Details ─────────────────────────────────────────────────────────
  const [jobTitle, setJobTitle] = useState('');
  const [jobDescription, setJobDescription] = useState('');
  const [requiredSkills, setRequiredSkills] = useState('');
  const [experienceYears, setExperienceYears] = useState('');
  const [education, setEducation] = useState('');
  const [certifications, setCertifications] = useState('');
  const [topN, setTopN] = useState(10);

  // ── Filters ──────────────────────────────────────────────────────────────
  const [preferredLocation, setPreferredLocation] = useState('');
  const [preferredLanguages, setPreferredLanguages] = useState('');
  const [filtersOpen, setFiltersOpen] = useState(false);

  // ── Resume Upload ────────────────────────────────────────────────────────
  const [files, setFiles] = useState([]);
  const [resumeText, setResumeText] = useState('');
  const [dragging, setDragging] = useState(false);
  const fileInputRef = useRef(null);

  // ── Drag and Drop handlers ───────────────────────────────────────────────
  const handleDrop = useCallback((e) => {
    e.preventDefault();
    setDragging(false);
    const dropped = Array.from(e.dataTransfer.files).filter(f => f.type === 'application/pdf');
    setFiles(prev => {
      const names = new Set(prev.map(f => f.name));
      return [...prev, ...dropped.filter(f => !names.has(f.name))];
    });
  }, []);

  const handleDragOver = (e) => { e.preventDefault(); setDragging(true); };
  const handleDragLeave = () => setDragging(false);

  const handleFileChange = (e) => {
    const selected = Array.from(e.target.files).filter(f => f.type === 'application/pdf');
    setFiles(prev => {
      const names = new Set(prev.map(f => f.name));
      return [...prev, ...selected.filter(f => !names.has(f.name))];
    });
    e.target.value = '';
  };

  const removeFile = (name) => setFiles(prev => prev.filter(f => f.name !== name));

  // ── Form submit ──────────────────────────────────────────────────────────
  const handleSubmit = (e) => {
    e.preventDefault();
    if (!files.length && !resumeText.trim()) {
      alert('Please upload at least one resume PDF or paste resume text.');
      return;
    }

    const formData = new FormData();
    formData.append('job_title', jobTitle);
    formData.append('job_description', jobDescription);
    formData.append('required_skills', requiredSkills);
    formData.append('experience_years', experienceYears || '0');
    formData.append('education', education);
    formData.append('certifications', certifications);
    formData.append('top_n', topN);
    formData.append('preferred_location', preferredLocation);
    formData.append('preferred_languages', preferredLanguages);
    formData.append('resume_text', resumeText);

    // Append all PDF files
    if (files.length > 0) {
      files.forEach(f => formData.append('resumes', f));
    } else {
      // Append a blank file so FastAPI 'resumes' field isn't empty
      formData.append('resumes', new Blob([]), 'placeholder.pdf');
    }

    onSubmit(formData);
  };

  return (
    <form onSubmit={handleSubmit} className="space-y-6 animate-fade-in">

      {/* ── Header ── */}
      <div className="flex items-center justify-between">
        <div>
          <h2 className="text-2xl font-bold text-white">New Screening</h2>
          <p className="text-slate-400 text-sm mt-1">Configure job requirements and upload candidate resumes</p>
        </div>
        <div className="flex items-center gap-2 px-3 py-1.5 rounded-lg bg-primary-900/30 border border-primary-800/40">
          <Zap size={14} className="text-primary-400" />
          <span className="text-xs text-primary-300 font-medium">AI-Powered</span>
        </div>
      </div>

      {/* ── Job Details Card ── */}
      <div className="card p-6 space-y-5">
        <h3 className="section-header">
          <Briefcase size={18} className="text-primary-400" />
          Job Details
        </h3>

        <div className="grid grid-cols-1 md:grid-cols-2 gap-5">
          {/* Job Title */}
          <div>
            <label className="label" htmlFor="job-title">Job Title *</label>
            <input
              id="job-title"
              className="input-field"
              placeholder="e.g. Senior Software Engineer"
              value={jobTitle}
              onChange={e => setJobTitle(e.target.value)}
              required
            />
          </div>

          {/* Top N */}
          <div>
            <label className="label" htmlFor="top-n">
              <Users size={14} className="inline mr-1.5" />
              Top N Candidates
            </label>
            <input
              id="top-n"
              type="number"
              min={1}
              max={100}
              className="input-field"
              value={topN}
              onChange={e => setTopN(parseInt(e.target.value) || 10)}
            />
          </div>
        </div>

        {/* Job Description */}
        <div>
          <label className="label" htmlFor="job-description">
            <FileText size={14} className="inline mr-1.5" />
            Job Description *
          </label>
          <textarea
            id="job-description"
            className="input-field min-h-[120px] resize-y"
            placeholder="Paste the full job description here..."
            value={jobDescription}
            onChange={e => setJobDescription(e.target.value)}
            required
          />
        </div>

        {/* Required Skills */}
        <div>
          <label className="label" htmlFor="required-skills">
            <Star size={14} className="inline mr-1.5" />
            Required Skills *
            <span className="text-slate-600 font-normal ml-2">(comma separated)</span>
          </label>
          <input
            id="required-skills"
            className="input-field"
            placeholder="e.g. Python, React, SQL, Machine Learning"
            value={requiredSkills}
            onChange={e => setRequiredSkills(e.target.value)}
            required
          />
        </div>

        <div className="grid grid-cols-1 md:grid-cols-3 gap-5">
          {/* Experience */}
          <div>
            <label className="label" htmlFor="experience-years">
              <Clock size={14} className="inline mr-1.5" />
              Experience (years)
            </label>
            <input
              id="experience-years"
              type="number"
              min={0}
              className="input-field"
              placeholder="e.g. 3"
              value={experienceYears}
              onChange={e => setExperienceYears(e.target.value)}
            />
          </div>

          {/* Education */}
          <div>
            <label className="label" htmlFor="education">
              <GraduationCap size={14} className="inline mr-1.5" />
              Required Education
            </label>
            <select
              id="education"
              className="input-field"
              value={education}
              onChange={e => setEducation(e.target.value)}
            >
              <option value="">Any</option>
              <option value="certificate">Certificate / Diploma</option>
              <option value="bachelor">Bachelor's Degree</option>
              <option value="master">Master's Degree</option>
              <option value="phd">PhD / Doctorate</option>
            </select>
          </div>

          {/* Certifications */}
          <div>
            <label className="label" htmlFor="certifications">
              <Award size={14} className="inline mr-1.5" />
              Required Certifications
            </label>
            <input
              id="certifications"
              className="input-field"
              placeholder="e.g. AWS Certified, PMP"
              value={certifications}
              onChange={e => setCertifications(e.target.value)}
            />
          </div>
        </div>
      </div>

      {/* ── Optional Filters ── */}
      <div className="card overflow-hidden">
        <button
          type="button"
          onClick={() => setFiltersOpen(v => !v)}
          className="w-full flex items-center justify-between p-5 hover:bg-slate-800/50 transition-colors"
        >
          <h3 className="section-header">
            <MapPin size={18} className="text-primary-400" />
            Filters &amp; Bonus Factors
            <span className="ml-2 text-xs text-slate-500 font-normal">(5% weight)</span>
          </h3>
          {filtersOpen ? <ChevronUp size={18} className="text-slate-500" /> : <ChevronDown size={18} className="text-slate-500" />}
        </button>
        {filtersOpen && (
          <div className="px-6 pb-6 grid grid-cols-1 md:grid-cols-2 gap-5 border-t border-slate-800 pt-5 animate-fade-in">
            <div>
              <label className="label" htmlFor="preferred-location">
                <MapPin size={14} className="inline mr-1.5" />
                Preferred Location
              </label>
              <input
                id="preferred-location"
                className="input-field"
                placeholder="e.g. Karachi, Pakistan"
                value={preferredLocation}
                onChange={e => setPreferredLocation(e.target.value)}
              />
            </div>
            <div>
              <label className="label" htmlFor="preferred-languages">
                <Globe size={14} className="inline mr-1.5" />
                Preferred Languages
                <span className="text-slate-600 font-normal ml-1">(comma separated)</span>
              </label>
              <input
                id="preferred-languages"
                className="input-field"
                placeholder="e.g. English, Urdu"
                value={preferredLanguages}
                onChange={e => setPreferredLanguages(e.target.value)}
              />
            </div>
          </div>
        )}
      </div>

      {/* ── Resume Upload Card ── */}
      <div className="card p-6 space-y-5">
        <h3 className="section-header">
          <Upload size={18} className="text-primary-400" />
          Resume Upload
        </h3>

        {/* Drop Zone */}
        <div
          onDrop={handleDrop}
          onDragOver={handleDragOver}
          onDragLeave={handleDragLeave}
          onClick={() => fileInputRef.current.click()}
          className={`border-2 border-dashed rounded-xl p-10 text-center cursor-pointer transition-all duration-300 ${
            dragging
              ? 'border-primary-500 bg-primary-900/20 drop-active'
              : 'border-slate-700 hover:border-slate-600 hover:bg-slate-800/30'
          }`}
        >
          <input
            ref={fileInputRef}
            type="file"
            id="resume-upload"
            multiple
            accept=".pdf"
            className="hidden"
            onChange={handleFileChange}
          />
          <div className="flex flex-col items-center gap-3">
            <div className={`w-14 h-14 rounded-2xl flex items-center justify-center transition-colors ${
              dragging ? 'bg-primary-600/30' : 'bg-slate-800'
            }`}>
              <Upload size={26} className={dragging ? 'text-primary-400' : 'text-slate-500'} />
            </div>
            <div>
              <p className="text-slate-300 font-medium">
                {dragging ? 'Drop PDFs here!' : 'Drag & drop PDF resumes'}
              </p>
              <p className="text-slate-500 text-sm mt-1">or click to browse Β· Multiple files supported</p>
            </div>
          </div>
        </div>

        {/* File list */}
        {files.length > 0 && (
          <div className="space-y-2 animate-fade-in">
            <p className="text-slate-400 text-sm font-medium">{files.length} file(s) selected</p>
            <div className="max-h-48 overflow-y-auto space-y-1.5 pr-1">
              {files.map(f => (
                <div
                  key={f.name}
                  className="flex items-center justify-between px-4 py-2.5 bg-slate-800 rounded-lg border border-slate-700"
                >
                  <div className="flex items-center gap-2.5 min-w-0">
                    <FileText size={16} className="text-primary-400 flex-shrink-0" />
                    <span className="text-sm text-slate-300 truncate">{f.name}</span>
                    <span className="text-xs text-slate-600 flex-shrink-0">
                      {(f.size / 1024).toFixed(0)} KB
                    </span>
                  </div>
                  <button
                    type="button"
                    onClick={(e) => { e.stopPropagation(); removeFile(f.name); }}
                    className="ml-2 text-slate-600 hover:text-red-400 transition-colors flex-shrink-0"
                  >
                    <X size={16} />
                  </button>
                </div>
              ))}
            </div>
          </div>
        )}

        {/* Text paste option */}
        <div>
          <label className="label" htmlFor="resume-text">
            Or Paste Resume Text (optional)
          </label>
          <textarea
            id="resume-text"
            className="input-field min-h-[80px] resize-y"
            placeholder="Paste a plain-text resume here as an alternative or addition..."
            value={resumeText}
            onChange={e => setResumeText(e.target.value)}
          />
        </div>
      </div>

      {/* ── Submit Button ── */}
      <button
        id="run-screening-btn"
        type="submit"
        disabled={loading}
        className="btn-primary w-full flex items-center justify-center gap-2.5 py-4 text-base"
      >
        {loading ? (
          <>
            <svg className="animate-spin w-5 h-5" viewBox="0 0 24 24" fill="none">
              <circle className="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" strokeWidth="4" />
              <path className="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8v8z" />
            </svg>
            Processing Resumes...
          </>
        ) : (
          <>
            <Zap size={20} />
            Run AI Screening
          </>
        )}
      </button>
    </form>
  );
}