"use client"; import { useState, use } from "react"; import { useRouter } from "next/navigation"; import Link from "next/link"; import { motion, AnimatePresence } from "framer-motion"; import { ChevronRight, ChevronLeft, Upload, CheckCircle2, Briefcase, FileText, User, MessageSquare, Save, ArrowLeft, } from "lucide-react"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, } from "@/components/ui/card"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { Textarea } from "@/components/ui/textarea"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue, } from "@/components/ui/select"; import { Checkbox } from "@/components/ui/checkbox"; import { Progress } from "@/components/ui/progress"; import { Separator } from "@/components/ui/separator"; import { Navbar } from "@/components/navbar"; import { Footer } from "@/components/footer"; import { useNotify } from "@/contexts/notification-context"; import { mockJobs } from "@/lib/mock-data"; import { storageApi, applicationsApi } from "@/lib/api"; // Definição Dos Passos const steps = [ { id: 1, title: "Dados Pessoais", icon: User }, { id: 2, title: "Currículo e Documentos", icon: FileText }, { id: 3, title: "Experiência", icon: Briefcase }, { id: 4, title: "Perguntas Adicionais", icon: MessageSquare }, ]; export const runtime = 'edge'; export default function JobApplicationPage({ params, }: { params: Promise<{ id: string }>; }) { const { id } = use(params); const router = useRouter(); const notify = useNotify(); const [currentStep, setCurrentStep] = useState(1); const [isSubmitting, setIsSubmitting] = useState(false); // Achar os detalhes da vaga const job = mockJobs.find((j) => j.id === id) || mockJobs[0]; // Estado do formulário const [formData, setFormData] = useState({ // Etapa 1 fullName: "", email: "", phone: "", linkedin: "", privacyAccepted: false, // Etapa 2 resume: null as File | null, coverLetter: "", portfolioUrl: "", // Etapa 3 salaryExpectation: "", hasExperience: "", // Etapa 4 whyUs: "", availability: [] as string[], }); const handleInputChange = (field: string, value: any) => { setFormData((prev) => ({ ...prev, [field]: value })); }; const validateStep = (step: number) => { switch (step) { case 1: if (!formData.fullName || !formData.email || !formData.phone) { notify.error( "Campos obrigatórios", "Por favor, preencha todos os campos obrigatórios." ); return false; } if (!formData.email.includes("@")) { notify.error( "E-mail inválido", "Por favor, insira um e-mail válido." ); return false; } if (!formData.privacyAccepted) { notify.error( "Termos de Privacidade", "Você precisa aceitar a política de privacidade para continuar." ); return false; } return true; case 2: return true; case 3: if (!formData.salaryExpectation || !formData.hasExperience) { notify.error( "Campos obrigatórios", "Por favor, responda todas as perguntas." ); return false; } return true; case 4: if (!formData.whyUs || formData.availability.length === 0) { notify.error( "Campos obrigatórios", "Por favor, preencha o motivo e selecione pelo menos uma disponibilidade." ); return false; } return true; default: return true; } }; const handleNext = () => { if (validateStep(currentStep)) { if (currentStep < steps.length) { setCurrentStep((prev) => prev + 1); window.scrollTo(0, 0); } else { handleSubmit(); } } }; const handleBack = () => { if (currentStep > 1) { setCurrentStep((prev) => prev - 1); window.scrollTo(0, 0); } }; const handleSubmit = async () => { try { setIsSubmitting(true); let resumeUrl = ""; // 1. Upload Curriculo if (formData.resume) { try { const { uploadUrl, publicUrl } = await storageApi.getUploadUrl( formData.resume.name, formData.resume.type ); await storageApi.uploadFile(uploadUrl, formData.resume); resumeUrl = publicUrl; } catch (err) { console.error("Upload error:", err); notify.error("Erro no upload", "Não foi possível enviar seu currículo. Tente novamente."); setIsSubmitting(false); return; } } // 2. Create Application await applicationsApi.create({ jobId: Number(job.id), name: formData.fullName, email: formData.email, phone: formData.phone, message: formData.coverLetter || formData.whyUs, // Using cover letter or whyUs as message resumeUrl: resumeUrl, documents: { linkedin: formData.linkedin, portfolio: formData.portfolioUrl, salaryExpectation: formData.salaryExpectation, availability: formData.availability, whyUs: formData.whyUs } }); notify.success( "Candidatura enviada com sucesso!", `Boa sorte! Sua candidatura para ${job.title} foi recebida.` ); router.push("/dashboard/candidato/candidaturas"); // Redirecionar para dashboard correto } catch (error) { console.error("Application error:", error); notify.error("Erro ao enviar", "Ocorreu um erro ao processar sua candidatura."); } finally { setIsSubmitting(false); } }; const handleSaveDraft = () => { notify.info( "Rascunho salvo", "Você pode continuar sua candidatura mais tarde." ); }; const progress = (currentStep / steps.length) * 100; if (!job) return null; return (
{/* Header */}
Voltar para detalhes da vaga

Candidatura: {job.title}

{job.company} • {job.location}

Tempo estimado: 5 min
{/* Progresso das etapas */}
Etapa {currentStep} de {steps.length}:{" "} {steps[currentStep - 1].title} {Math.round(progress)}%
{/* Indicador de etapas (DESKTOP) */}
{steps.map((step) => { const Icon = step.icon; const isActive = step.id === currentStep; const isCompleted = step.id < currentStep; return (
{isCompleted ? ( ) : ( )}
{step.title}
); })}
{/* Conteúdo do formulário */}
{steps[currentStep - 1].title} Preencha as informações abaixo para continuar. {/* Etapa 1: Dados Pessoais */} {currentStep === 1 && (
handleInputChange("fullName", e.target.value) } />
handleInputChange("email", e.target.value) } />
handleInputChange("phone", e.target.value) } />
handleInputChange("linkedin", e.target.value) } />
handleInputChange("privacyAccepted", checked) } />
)} {/* Etapa 2: Dccumentos */} {currentStep === 2 && (

Clique para fazer upload ou arraste o arquivo

PDF, DOCX ou TXT (Máx. 5MB)

handleInputChange("portfolioUrl", e.target.value) } />