"use client"; import { useState } from "react"; import { useRouter } from "next/navigation"; import { toast } from "sonner"; import { Navbar } from "@/components/navbar"; import { Footer } from "@/components/footer"; 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 { Card, CardContent, CardHeader, CardTitle, CardDescription } from "@/components/ui/card"; import { Building2, Briefcase, Mail, Lock, Phone, MapPin, Eye, EyeOff, Globe } from "lucide-react"; import { LocationPicker } from "@/components/location-picker"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; // Common Country Codes const COUNTRY_CODES = [ { code: "+55", country: "Brasil (BR)" }, { code: "+1", country: "Estados Unidos (US)" }, { code: "+351", country: "Portugal (PT)" }, { code: "+44", country: "Reino Unido (UK)" }, { code: "+33", country: "França (FR)" }, { code: "+49", country: "Alemanha (DE)" }, { code: "+34", country: "Espanha (ES)" }, { code: "+39", country: "Itália (IT)" }, { code: "+81", country: "Japão (JP)" }, { code: "+86", country: "China (CN)" }, { code: "+91", country: "Índia (IN)" }, { code: "+52", country: "México (MX)" }, { code: "+54", country: "Argentina (AR)" }, { code: "+57", country: "Colômbia (CO)" }, { code: "+56", country: "Chile (CL)" }, { code: "+51", country: "Peru (PE)" }, ].sort((a, b) => a.country.localeCompare(b.country)); export default function PostJobPage() { const router = useRouter(); const [step, setStep] = useState<1 | 2 | 3>(1); const [loading, setLoading] = useState(false); // Company/User data const [company, setCompany] = useState({ name: "", email: "", password: "", confirmPassword: "", ddi: "+55", phone: "", }); const [showPassword, setShowPassword] = useState(false); const [showConfirmPassword, setShowConfirmPassword] = useState(false); // Job data const [job, setJob] = useState({ title: "", description: "", location: "", salaryMin: "", salaryMax: "", salaryFixed: "", // For fixed salary mode employmentType: "", workMode: "remote", workingHours: "", salaryNegotiable: false, // Candidate proposes salary }); // Salary mode toggle: 'fixed' | 'range' const [salaryMode, setSalaryMode] = useState<'fixed' | 'range'>('fixed'); const formatPhoneForDisplay = (value: string) => { // Simple formatting to just allow numbers and basic separators if needed // For now, just pass through but maybe restrict chars? return value.replace(/[^\d\s-]/g, ""); }; const handleSubmit = async () => { if (!company.name || !company.email || !company.password) { toast.error("Preencha os dados obrigatórios da empresa"); setStep(1); return; } if (company.password !== company.confirmPassword) { toast.error("As senhas não coincidem"); setStep(1); return; } if (company.password.length < 8) { toast.error("A senha deve ter pelo menos 8 caracteres"); setStep(1); return; } if (!job.title || !job.description) { toast.error("Preencha os dados da vaga"); setStep(2); return; } setLoading(true); try { const apiBase = process.env.NEXT_PUBLIC_API_URL || ""; // Format phone: DDI + Phone (digits only) const cleanPhone = company.phone.replace(/\D/g, ""); const finalPhone = cleanPhone ? `${company.ddi}${cleanPhone}` : ""; // 1. Register Company (creates user + company) const registerRes = await fetch(`${apiBase}/api/v1/auth/register/company`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ companyName: company.name, email: company.email, password: company.password, phone: finalPhone, }), }); if (!registerRes.ok) { const err = await registerRes.json(); throw new Error(err.message || "Erro ao registrar empresa"); } const { token } = await registerRes.json(); // 2. Create Job with token const jobRes = await fetch(`${apiBase}/api/v1/jobs`, { method: "POST", headers: { "Content-Type": "application/json", "Authorization": `Bearer ${token}`, }, body: JSON.stringify({ title: job.title, description: job.description, location: job.location, // Salary logic: if negotiable, send null values salaryMin: job.salaryNegotiable ? null : (salaryMode === 'fixed' ? (job.salaryFixed ? parseInt(job.salaryFixed) : null) : (job.salaryMin ? parseInt(job.salaryMin) : null)), salaryMax: job.salaryNegotiable ? null : (salaryMode === 'fixed' ? (job.salaryFixed ? parseInt(job.salaryFixed) : null) : (job.salaryMax ? parseInt(job.salaryMax) : null)), salaryNegotiable: job.salaryNegotiable, employmentType: job.employmentType || null, workingHours: job.workingHours || null, workMode: job.workMode, status: "pending", // Pending review }), }); if (!jobRes.ok) { const err = await jobRes.json(); throw new Error(err.message || "Erro ao criar vaga"); } // Save token for future use localStorage.setItem("token", token); localStorage.setItem("auth_token", token); toast.success("Vaga criada com sucesso! Aguardando aprovação."); router.push("/dashboard/jobs"); } catch (err: any) { toast.error(err.message || "Erro ao processar solicitação"); } finally { setLoading(false); } }; return (

Postar uma Vaga

Cadastre sua empresa e publique sua vaga em poucos minutos

{/* Progress Steps */}
{[1, 2, 3].map((s) => (
= s ? "text-primary" : "text-muted-foreground"}`} >
= s ? "bg-primary text-white" : "bg-muted"}`}> {s}
{s === 1 ? "Empresa" : s === 2 ? "Vaga" : "Confirmar"}
))}
{step === 1 && "Dados da Empresa"} {step === 2 && "Detalhes da Vaga"} {step === 3 && "Confirmar e Publicar"} {step === 1 && "Informe os dados da sua empresa para criar a conta"} {step === 2 && "Descreva a vaga que você deseja publicar"} {step === 3 && "Revise as informações antes de publicar"} {/* Step 1: Company */} {step === 1 && (
setCompany({ ...company, name: e.target.value })} placeholder="Minha Empresa Ltda" className="pl-10" />
setCompany({ ...company, email: e.target.value })} placeholder="contato@empresa.com" className="pl-10" />
{/* Password Field */}
setCompany({ ...company, password: e.target.value })} placeholder="••••••••" className="pl-10 pr-10" // Extra padding for eye icon />
{/* Confirm Password Field */}
setCompany({ ...company, confirmPassword: e.target.value })} placeholder="••••••••" className="pl-10 pr-10" />
{/* Phone Field with DDI */}
setCompany({ ...company, phone: e.target.value })} placeholder="11 99999-9999" className="pl-10" />

Selecione o código do país e digite o número com DDD.

)} {/* Step 2: Job */} {step === 2 && (
setJob({ ...job, title: e.target.value })} placeholder="Desenvolvedor Full Stack" className="pl-10" />