fix(jobs): enforce description min length and redirect after create
This commit is contained in:
parent
cf305d096e
commit
1fbbe9fe18
1 changed files with 17 additions and 26 deletions
|
|
@ -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<AdminCompany[]>([])
|
||||
|
|
@ -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)}
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground mt-1">
|
||||
Minimo de {DESCRIPTION_MIN_LENGTH} caracteres ({formData.description.trim().length}/{DESCRIPTION_MIN_LENGTH})
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="md:w-1/3 space-y-1.5">
|
||||
|
|
|
|||
Loading…
Reference in a new issue