"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; const STATUSES = ["prospect", "reviewing", "tailoring", "ready", "applied", "interviewing", "offer", "rejected", "dead"] as const; const STATUS_CONFIG: Record = { prospect: { label: "Prospect", dot: "bg-zinc-400" }, reviewing: { label: "Reviewing", dot: "bg-amber-500" }, tailoring: { label: "Tailoring", dot: "bg-purple-500" }, ready: { label: "Ready", dot: "bg-blue-500" }, applied: { label: "Applied", dot: "bg-indigo-500" }, interviewing: { label: "Interviewing", dot: "bg-teal-500" }, offer: { label: "Offer", dot: "bg-emerald-500" }, rejected: { label: "Rejected", dot: "bg-rose-500" }, dead: { label: "Dead", dot: "bg-zinc-400" }, }; export default function JobActions({ job }: { job: { id: string; status: string } }) { const router = useRouter(); const [busy, setBusy] = useState(""); const [msg, setMsg] = useState<{ type: "success" | "error"; text: string } | null>(null); async function setStatus(status: string) { try { await fetch(`/api/jobs/${job.id}`, { method: "PATCH", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ status }), }); router.refresh(); } catch { setMsg({ type: "error", text: "Failed to update status." }); } } async function run(kind: "tailor" | "cover") { setBusy(kind); setMsg(null); try { const res = await fetch(`/api/ai/${kind}`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ jobId: job.id }), }); const data = await res.json(); if (!res.ok) throw new Error(data.error ?? "Generation failed"); setMsg({ type: "success", text: kind === "tailor" ? "Tailored resume created successfully! ✨" : "Cover letter created successfully! 📄", }); router.refresh(); } catch (e) { setMsg({ type: "error", text: String(e) }); } finally { setBusy(""); } } async function markApplied() { setBusy("applied"); setMsg(null); try { await fetch("/api/applications", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ jobId: job.id, method: "manual", submittedAt: new Date().toISOString() }), }); setMsg({ type: "success", text: "Marked as applied! Application logged. ✅" }); router.refresh(); } catch (e) { setMsg({ type: "error", text: String(e) }); } finally { setBusy(""); } } async function del() { if (!confirm("Are you sure you want to delete this job and its associated data?")) return; try { await fetch(`/api/jobs/${job.id}`, { method: "DELETE" }); router.push("/jobs"); } catch (e) { setMsg({ type: "error", text: String(e) }); } } return (
{/* Status Dropdown */}
Pipeline Stage:
{/* Action Buttons Toolbar */}
{/* AI Tailor Resume */} {/* AI Cover Letter */} {/* Apply Wizard */} Apply Wizard {/* Mark Applied */} {/* Delete Button */}
{/* Alert / Toast Message */} {msg && (
{msg.text}
)}
); }