diff --git a/frontend/src/app/dashboard/jobs/new/page.tsx b/frontend/src/app/dashboard/jobs/new/page.tsx index 95291c5..fa55341 100644 --- a/frontend/src/app/dashboard/jobs/new/page.tsx +++ b/frontend/src/app/dashboard/jobs/new/page.tsx @@ -1,6 +1,7 @@ "use client" import { useCallback, useEffect, useMemo, useRef, useState } from "react" +import { useRouter } from "next/navigation" import { Loader2, PlusCircle } from "lucide-react" import { toast } from "sonner" @@ -36,7 +37,10 @@ type ApiCountry = { iso2: string } +const DESCRIPTION_MIN_LENGTH = 20 + export default function DashboardNewJobPage() { + const router = useRouter() const [loading, setLoading] = useState(false) const [loadingCompanies, setLoadingCompanies] = useState(true) const [companies, setCompanies] = useState([]) @@ -134,13 +138,18 @@ export default function DashboardNewJobPage() { const canSubmit = formData.title.trim().length >= 5 && - formData.description.trim().length >= 20 && + formData.description.trim().length >= DESCRIPTION_MIN_LENGTH && formData.companyId !== "" const handleSubmit = async (e: React.FormEvent) => { e.preventDefault() if (!canSubmit) { - toast.error("Preencha os campos obrigatórios") + const descriptionLength = formData.description.trim().length + if (descriptionLength < DESCRIPTION_MIN_LENGTH) { + toast.error(`Descricao da vaga deve ter no minimo ${DESCRIPTION_MIN_LENGTH} caracteres`) + } else { + toast.error("Preencha os campos obrigatorios") + } return } @@ -175,30 +184,9 @@ export default function DashboardNewJobPage() { await jobsApi.create(payload) toast.success("Vaga cadastrada com sucesso!") - setFormData({ - companyId: "", - title: "", - description: "", - location: "", - country: "", - employmentType: "", - workMode: "", - workingHours: "", - salaryMin: "", - salaryMax: "", - salaryType: "monthly", - currency: "BRL", - salaryNegotiable: false, - languageLevel: "", - applicationChannel: "email", - applicationEmail: "", - applicationUrl: "", - applicationPhone: "", - resumeRequirement: "optional", - visaSupport: false, - status: "draft", - }) - setLocationIds({ cityId: null, regionId: null }) + setTimeout(() => { + router.push("/dashboard/jobs") + }, 700) } catch (error: any) { toast.error(error.message || "Falha ao cadastrar vaga") } finally { @@ -291,6 +279,9 @@ export default function DashboardNewJobPage() { value={formData.description} onChange={(e) => set("description", e.target.value)} /> +

+ Minimo de {DESCRIPTION_MIN_LENGTH} caracteres ({formData.description.trim().length}/{DESCRIPTION_MIN_LENGTH}) +