customer/src/modules/hr/page.ts
Peppa 2669ad01ab
All checks were successful
peppa/lint lint: success за 1с
peppa/typecheck typecheck: success за 2с
peppa/test test: success за 37с
peppa/build build: success за 2с
ci / checks (pull_request) Successful in 50s
deploy / deploy (pull_request) Successful in 3s
CLT-8: HR-скрининг кандидатов со скоринговым отчётом
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-15 14:51:57 +05:00

30 lines
3.9 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { escapeHtml } from "../../html.ts";
export const PAGE_CSS = `body{font-family:system-ui,sans-serif;max-width:640px;margin:2rem auto;padding:0 1rem;color:#1b2430}
button{background:#183e78;color:#fff;border:0;border-radius:6px;padding:.6rem 1.2rem;font-size:1rem;cursor:pointer}
fieldset{margin:1rem 0;border:1px solid #ccd3de;border-radius:6px}h1{font-size:1.4rem}.err{color:#b00020}`;
/** Страница кандидата: вся логика во внешнем скрипте (CSP без inline). Токен — из пути. */
export function renderTestPage(token: string): string {
return `<!doctype html><html lang="ru"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="robots" content="noindex"><title>Тест кандидата</title><link rel="stylesheet" href="/hr/test.css"></head>
<body><h1>Тест кандидата</h1><div id="app" data-token="${escapeHtml(token)}">Загрузка…</div><script src="/hr/test.js"></script></body></html>`;
}
export const PAGE_JS = `(function(){
var app=document.getElementById("app");var token=app.dataset.token;var base="/api/hr/test/"+encodeURIComponent(token);
function el(t,x,c){var e=document.createElement(t);if(x)e.textContent=x;if(c)e.className=c;return e}
function show(){app.textContent="";for(var i=0;i<arguments.length;i++)app.appendChild(arguments[i])}
function fail(code){var m={link_expired:"Срок действия ссылки истёк.",link_used:"Тест уже пройден.",time_expired:"Время на тест вышло.",not_found:"Ссылка недействительна."};show(el("p",m[code]||"Не получилось. Попробуйте позже.","err"))}
function j(u,o){return fetch(u,o).then(function(r){return r.json().then(function(b){return{ok:r.ok,b:b}})})}
function post(u,b){return j(u,{method:"POST",headers:{"content-type":"application/json"},body:JSON.stringify(b||{})})}
function consent(info){var cb=document.createElement("input");cb.type="checkbox";var lb=el("label");lb.appendChild(cb);lb.appendChild(document.createTextNode(" Я даю согласие на обработку моих персональных данных: результаты теста будут переданы работодателю и хранятся 180 дней."));
var btn=el("button","Начать тест");btn.onclick=function(){if(!cb.checked){return}post(base+"/consent",{version:info.consentVersion}).then(function(r){if(!r.ok)return fail(r.b.error);questions()})};
show(el("p","Тест состоит из трёх частей и занимает до "+info.timeLimitMinutes+" минут. Результат — рекомендация для специалиста по подбору, а не автоматическое решение."),lb,el("p"),btn)}
function questions(){j(base+"/questions").then(function(r){if(!r.ok)return fail(r.b.error);var form=el("div");var sel={};
r.b.questions.forEach(function(q){var fs=el("fieldset");fs.appendChild(el("legend",q.text));q.options.forEach(function(o){var l=el("label");var i=document.createElement("input");i.type="radio";i.name=q.id;i.onchange=function(){sel[q.id]=o};l.appendChild(i);l.appendChild(document.createTextNode(" "+o));fs.appendChild(l);fs.appendChild(el("br"))});form.appendChild(fs)});
var msg=el("p","","err");var btn=el("button","Отправить");btn.onclick=function(){var a={};var n=0;r.b.questions.forEach(function(q){if(sel[q.id]!==undefined){a[q.id]=sel[q.id];n++}});if(n!==r.b.questions.length){msg.textContent="Ответьте на все вопросы.";return}
post(base+"/answers",{answers:a}).then(function(x){if(!x.ok)return fail(x.b.error);show(el("p","Спасибо! Ответы отправлены."))})};form.appendChild(msg);form.appendChild(btn);show(form)})}
j(base).then(function(r){if(!r.ok)return fail(r.b.error);if(r.b.status==="started")return questions();consent(r.b)}).catch(function(){fail()})
})();`;