/* Maitha Tech — Vagas: detalhe da vaga (vaga.html?id=…). GET /opportunities/{id}; a descrição em texto é estruturada por vagasParseDescription. */ function useVagasJob(id) { const [state, setState] = React.useState({ status: id ? "loading" : "missing", job: null, error: null }); const [reloadKey, setReloadKey] = React.useState(0); React.useEffect(() => { if (!id) { setState({ status: "missing", job: null, error: null }); return; } let alive = true; setState({ status: "loading", job: null, error: null }); vagasGetOpportunity(id) .then((res) => { if (!alive) return; const job = res && res.data; if (!job || !job.name) { setState({ status: "notfound", job: null, error: null }); return; } setState({ status: "ready", job, error: null }); }) .catch((err) => { if (!alive) return; setState({ status: err && err.status === 404 ? "notfound" : "error", job: null, error: err }); }); return () => { alive = false; }; }, [id, reloadKey]); return { ...state, retry: () => setReloadKey((k) => k + 1) }; } function VagasDetailPage() { const id = vagasQueryParam("id"); const { status, job, retry } = useVagasJob(id); React.useEffect(() => { if (job && job.name) document.title = `${job.name} — Vagas | Maitha Tech`; }, [job]); const sections = React.useMemo(() => (job ? vagasParseDescription(job.description) : []), [job]); const model = React.useMemo(() => vagasFindSection(sections, "modelo de trabalho"), [sections]); const applyHref = `formulario-vaga.html?id=${encodeURIComponent(id || "")}`; const backHome = ; if (status === "missing" || status === "notfound") { return ( Vaga não encontrada} />
); } if (status === "error") { return (
); } const loading = status === "loading"; const cta = ( ); return ( : job.name}> {!loading ? ( ) : null}
{loading ? : (
{cta}
)}
); } Object.assign(window, { useVagasJob, VagasDetailPage });