"use client"; import { useState, useEffect } from "react"; import { ArrowLeft } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Textarea } from "@/components/ui/textarea"; import { Label } from "@/components/ui/label"; import { createPosition, fetchDepartments } from "@/lib/supabase/recruitment-actions"; import type { EmploymentType, PositionStatus } from "@/lib/supabase/recruitment-types"; import { EMPLOYMENT_TYPE_LABELS } from "@/lib/supabase/recruitment-types"; import PageSkeleton from "./PageSkeleton"; export default function RecruitmentNewPage({ onBack }: { onBack: () => void }) { const [title, setTitle] = useState(""); const [departmentId, setDepartmentId] = useState(""); const [employmentType, setEmploymentType] = useState("full_time"); const [description, setDescription] = useState(""); const [status, setStatus] = useState("open"); const [departments, setDepartments] = useState<{ id: string; name: string }[]>([]); const [loading, setLoading] = useState(false); const [initialLoading, setInitialLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { let cancelled = false; fetchDepartments() .then((data) => { if (!cancelled) setDepartments(data); }) .catch(() => {}) .finally(() => { if (!cancelled) setInitialLoading(false); }); return () => { cancelled = true; }; }, []); const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); if (!title.trim()) return; setLoading(true); setError(null); const result = await createPosition({ title: title.trim(), department_id: departmentId || undefined, employment_type: employmentType, description: description.trim() || undefined, status, }); setLoading(false); if (!result.success) { setError(result.error || "Failed to create position"); return; } onBack(); }; if (initialLoading) return ; return (
{/* Header */}

Add position

Create an internal requisition to track hiring

{error && (
{error}
)} {/* Form */}
{/* Title */}
setTitle(e.target.value)} placeholder="e.g. Software Engineer" required />
{/* Department */}
{/* Employment Type */}
{/* Description */}