|
| 1 | +// app/(chat)/generate/page.tsx |
| 2 | +'use client'; |
| 3 | +import { useState } from 'react'; |
| 4 | + |
| 5 | +export default function GenerateJD() { |
| 6 | + const [formData, setFormData] = useState({ |
| 7 | + title: '', |
| 8 | + industry: '', |
| 9 | + experience: '', |
| 10 | + details: '' |
| 11 | + }); |
| 12 | + const [result, setResult] = useState(''); |
| 13 | + const [loading, setLoading] = useState(false); |
| 14 | + |
| 15 | + const handleSubmit = async (e: React.FormEvent) => { |
| 16 | + e.preventDefault(); |
| 17 | + setLoading(true); |
| 18 | + |
| 19 | + try { |
| 20 | + const response = await fetch('/api/chat', { |
| 21 | + method: 'POST', |
| 22 | + headers: { 'Content-Type': 'application/json' }, |
| 23 | + body: JSON.stringify({ |
| 24 | + type: 'generate_jd', |
| 25 | + content: formData |
| 26 | + }) |
| 27 | + }); |
| 28 | + |
| 29 | + const data = await response.json(); |
| 30 | + setResult(data.generatedJD); |
| 31 | + } catch (error) { |
| 32 | + console.error('Error:', error); |
| 33 | + } |
| 34 | + |
| 35 | + setLoading(false); |
| 36 | + }; |
| 37 | + |
| 38 | + return ( |
| 39 | + <div className="max-w-4xl mx-auto p-6"> |
| 40 | + <h1 className="text-2xl font-bold mb-6">Generate Job Description</h1> |
| 41 | + |
| 42 | + <form onSubmit={handleSubmit} className="space-y-6"> |
| 43 | + <div> |
| 44 | + <label className="block font-medium mb-1">Job Title</label> |
| 45 | + <input |
| 46 | + type="text" |
| 47 | + value={formData.title} |
| 48 | + onChange={(e) => setFormData(prev => ({ ...prev, title: e.target.value }))} |
| 49 | + className="w-full p-2 border rounded" |
| 50 | + placeholder="e.g., Senior Software Engineer" |
| 51 | + required |
| 52 | + /> |
| 53 | + </div> |
| 54 | + |
| 55 | + <div> |
| 56 | + <label className="block font-medium mb-1">Industry</label> |
| 57 | + <select |
| 58 | + value={formData.industry} |
| 59 | + onChange={(e) => setFormData(prev => ({ ...prev, industry: e.target.value }))} |
| 60 | + className="w-full p-2 border rounded" |
| 61 | + required |
| 62 | + > |
| 63 | + <option value="">Select Industry</option> |
| 64 | + <option value="Technology">Technology</option> |
| 65 | + <option value="Finance">Finance</option> |
| 66 | + <option value="Healthcare">Healthcare</option> |
| 67 | + <option value="Manufacturing">Manufacturing</option> |
| 68 | + <option value="Retail">Retail</option> |
| 69 | + </select> |
| 70 | + </div> |
| 71 | + |
| 72 | + <div> |
| 73 | + <label className="block font-medium mb-1">Experience Level</label> |
| 74 | + <select |
| 75 | + value={formData.experience} |
| 76 | + onChange={(e) => setFormData(prev => ({ ...prev, experience: e.target.value }))} |
| 77 | + className="w-full p-2 border rounded" |
| 78 | + required |
| 79 | + > |
| 80 | + <option value="">Select Experience Level</option> |
| 81 | + <option value="Entry Level">Entry Level (0-2 years)</option> |
| 82 | + <option value="Mid Level">Mid Level (3-5 years)</option> |
| 83 | + <option value="Senior Level">Senior Level (5+ years)</option> |
| 84 | + <option value="Lead">Lead (7+ years)</option> |
| 85 | + </select> |
| 86 | + </div> |
| 87 | + |
| 88 | + <div> |
| 89 | + <label className="block font-medium mb-1">Job Details</label> |
| 90 | + <textarea |
| 91 | + value={formData.details} |
| 92 | + onChange={(e) => setFormData(prev => ({ ...prev, details: e.target.value }))} |
| 93 | + className="w-full h-32 p-2 border rounded" |
| 94 | + placeholder="Describe the role, responsibilities, and key requirements..." |
| 95 | + required |
| 96 | + /> |
| 97 | + </div> |
| 98 | + |
| 99 | + <button |
| 100 | + type="submit" |
| 101 | + disabled={loading || !formData.title || !formData.industry || !formData.details} |
| 102 | + className="w-full py-2 bg-purple-600 text-white rounded hover:bg-purple-700 disabled:bg-purple-300" |
| 103 | + > |
| 104 | + {loading ? 'Generating...' : 'Generate JD'} |
| 105 | + </button> |
| 106 | + </form> |
| 107 | + |
| 108 | + {result && ( |
| 109 | + <div className="mt-6 p-4 bg-gray-50 rounded-lg"> |
| 110 | + <h2 className="text-lg font-medium mb-2">Generated Job Description:</h2> |
| 111 | + <div className="prose max-w-none"> |
| 112 | + <div dangerouslySetInnerHTML={{ __html: result }} /> |
| 113 | + </div> |
| 114 | + </div> |
| 115 | + )} |
| 116 | + </div> |
| 117 | + ); |
| 118 | +} |
0 commit comments