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"
|
"use client"
|
||||||
|
|
||||||
import { useCallback, useEffect, useMemo, useRef, useState } from "react"
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react"
|
||||||
|
import { useRouter } from "next/navigation"
|
||||||
import { Loader2, PlusCircle } from "lucide-react"
|
import { Loader2, PlusCircle } from "lucide-react"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
|
|
||||||
|
|
@ -36,7 +37,10 @@ type ApiCountry = {
|
||||||
iso2: string
|
iso2: string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const DESCRIPTION_MIN_LENGTH = 20
|
||||||
|
|
||||||
export default function DashboardNewJobPage() {
|
export default function DashboardNewJobPage() {
|
||||||
|
const router = useRouter()
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
const [loadingCompanies, setLoadingCompanies] = useState(true)
|
const [loadingCompanies, setLoadingCompanies] = useState(true)
|
||||||
const [companies, setCompanies] = useState<AdminCompany[]>([])
|
const [companies, setCompanies] = useState<AdminCompany[]>([])
|
||||||
|
|
@ -134,13 +138,18 @@ export default function DashboardNewJobPage() {
|
||||||
|
|
||||||
const canSubmit =
|
const canSubmit =
|
||||||
formData.title.trim().length >= 5 &&
|
formData.title.trim().length >= 5 &&
|
||||||
formData.description.trim().length >= 20 &&
|
formData.description.trim().length >= DESCRIPTION_MIN_LENGTH &&
|
||||||
formData.companyId !== ""
|
formData.companyId !== ""
|
||||||
|
|
||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
if (!canSubmit) {
|
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
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -175,30 +184,9 @@ export default function DashboardNewJobPage() {
|
||||||
|
|
||||||
await jobsApi.create(payload)
|
await jobsApi.create(payload)
|
||||||
toast.success("Vaga cadastrada com sucesso!")
|
toast.success("Vaga cadastrada com sucesso!")
|
||||||
setFormData({
|
setTimeout(() => {
|
||||||
companyId: "",
|
router.push("/dashboard/jobs")
|
||||||
title: "",
|
}, 700)
|
||||||
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 })
|
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
toast.error(error.message || "Falha ao cadastrar vaga")
|
toast.error(error.message || "Falha ao cadastrar vaga")
|
||||||
} finally {
|
} finally {
|
||||||
|
|
@ -291,6 +279,9 @@ export default function DashboardNewJobPage() {
|
||||||
value={formData.description}
|
value={formData.description}
|
||||||
onChange={(e) => set("description", e.target.value)}
|
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>
|
||||||
|
|
||||||
<div className="md:w-1/3 space-y-1.5">
|
<div className="md:w-1/3 space-y-1.5">
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue