import { ArrowLeft, Clock, Globe, ListChecks, Mic, ShieldCheck, Video } from "lucide-react"; import { useEffect, useState } from "react"; import { Link, useNavigate, useParams } from "react-router-dom"; import { CompanyMark, JobFacts, Skills } from "../components/jobs"; import { AppShell, PublicHeader } from "../components/Shell"; import { Button, ErrorNote, Spinner, fmtDate, useCatalog } from "../components/ui"; import { api, type Application, type PublicJob, type Session } from "../lib/api"; import { useAuth } from "../lib/auth"; import { trackName, useI18n } from "../lib/i18n"; export default function Apply() { const { token } = useParams(); const { t, lang } = useI18n(); const { profile, ready } = useAuth(); const catalog = useCatalog(); const nav = useNavigate(); const [job, setJob] = useState(null); const [mine, setMine] = useState(undefined); const [error, setError] = useState(null); const [busy, setBusy] = useState(false); useEffect(() => { api.get(`/public/jobs/${token}`).then(setJob).catch((e) => setError(e.message)); }, [token]); useEffect(() => { if (!ready) return; if (profile?.role === "candidate") api.get("/applications").then((a) => setMine(a.find((x) => x.share_token === token) ?? null)).catch(() => setMine(null)); else setMine(null); }, [ready, profile, token]); const start = async () => { setBusy(true); try { const s = await api.post(`/jobs/apply/${token}`, { language: lang }); nav(s.status === "in_progress" ? `/app/interview/${s.id}` : `/app/applications`); } catch (e: any) { setError(e.message); setBusy(false); } }; const action = () => { if (!job) return null; if (profile?.role === "recruiter") return

{t("company_cant_apply")}

; if (mine?.status === "in_progress") return {t("finish_interview")}; if (mine) return

{t("apply_done")} {t("nav_applications")}

; if (!job.accepting) return

{t("apply_closed")}

; if (profile) return ; return {t("apply_signin")}; }; const content = error && !job ? {error} : !job || !ready || mine === undefined ? : (
{profile?.role === "candidate" && ( {t("nav_board")} )}

{job.title}

{job.company} · {trackName(catalog?.tracks, job.track, lang)} · {t(`lv_${job.level}` as "lv_junior")}

{t("posted", { d: fmtDate(job.created_at, lang) })}

{job.description &&

{job.description}

}

{t("apply_title", { company: job.company })}

  • {t("apply_q", { n: job.question_count })}
  • {t("apply_time", { m: Math.round(job.answer_seconds / 60) })}
  • {t("apply_how")}
  • {job.require_camera &&
  • {t("apply_camera")}
  • } {job.record_video &&
  • }
{action()}
{error &&
{error}
}
{(job.company_about || job.industry || job.company_location) && (

{t("about_company", { company: job.company })}

{[job.industry, job.company_size && `${job.company_size}`, job.company_location].filter(Boolean).join(" · ")}

{job.company_about &&

{job.company_about}

} {job.website && {job.website.replace(/^https?:\/\//, "")}}
)}
); if (profile?.role === "candidate") return {content}; return (
{content}
); }