brendmanager/public/index.html

93 lines
5.3 KiB
HTML
Raw Permalink 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.

<!doctype html>
<html lang="ru">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Карточка бренда</title>
<style>
:root { --bg:#fff; --fg:#1d1d1f; --muted:#6b7280; --line:#d1d5db; --err:#b42318; --ok:#067647; --accent:#2f5bea; }
@media (prefers-color-scheme: dark) { :root { --bg:#16181d; --fg:#eceef2; --muted:#9aa3b2; --line:#3a3f4b; --err:#ff8a80; --ok:#6ee7a8; --accent:#7c9cff; } }
body { background:var(--bg); color:var(--fg); font:16px/1.5 system-ui,sans-serif; margin:0; }
main { max-width:720px; margin:0 auto; padding:24px 16px 48px; }
fieldset { border:1px solid var(--line); border-radius:8px; margin:0 0 16px; padding:12px 16px 16px; }
legend { font-weight:600; padding:0 6px; }
textarea, input { width:100%; box-sizing:border-box; font:inherit; color:inherit; background:transparent; border:1px solid var(--line); border-radius:6px; padding:8px; }
textarea { min-height:90px; }
input { margin-bottom:8px; }
.row { display:grid; grid-template-columns:1fr 2fr auto; gap:8px; align-items:start; }
@media (max-width:520px) { .row { grid-template-columns:1fr; } }
button { font:inherit; padding:8px 14px; border-radius:6px; border:1px solid var(--accent); background:transparent; color:var(--accent); cursor:pointer; }
button.primary { background:var(--accent); color:var(--bg); }
.err { color:var(--err); margin:4px 0 0; min-height:1.2em; }
#status { color:var(--ok); margin-left:12px; }
.hint { color:var(--muted); font-size:14px; margin:0 0 8px; }
</style>
</head>
<body>
<main>
<h1>Карточка личного бренда</h1>
<form id="f" novalidate>
<fieldset><legend>Аудитория</legend>
<p class="hint">Кто эти люди и что им нужно.</p>
<textarea id="audience" maxlength="1000" placeholder="Например: начинающие эксперты 25–40 лет, которым нужно заявить о себе"></textarea>
<p class="err" id="e-audience"></p></fieldset>
<fieldset><legend>Позиционирование</legend>
<p class="hint">Чем вы отличаетесь от других в своей области.</p>
<textarea id="positioning" maxlength="1000" placeholder="Например: объясняю сложное простыми словами на живых примерах"></textarea>
<p class="err" id="e-positioning"></p></fieldset>
<fieldset><legend>Темы</legend>
<p class="hint">Ровно три темы, о которых вы говорите.</p>
<input class="topic" maxlength="200" placeholder="Тема 1"><input class="topic" maxlength="200" placeholder="Тема 2"><input class="topic" maxlength="200" placeholder="Тема 3">
<p class="err" id="e-topics"></p></fieldset>
<fieldset><legend>Соцсети (необязательно)</legend>
<p class="hint">Название площадки и ссылка на канал.</p>
<div id="socials"></div>
<button type="button" id="add">Добавить соцсеть</button>
<p class="err" id="e-socials"></p></fieldset>
<button class="primary" type="submit">Сохранить</button><span id="status" role="status"></span>
<p class="err" id="e-form"></p>
</form>
</main>
<script>
const $ = (s) => document.querySelector(s);
function addSocial(s = { platform: "", url: "" }) {
const row = document.createElement("div");
row.className = "row";
row.innerHTML = '<input class="platform" maxlength="50" placeholder="Площадка, например Telegram"><input class="url" placeholder="https://…"><button type="button">Удалить</button>';
row.querySelector(".platform").value = s.platform;
row.querySelector(".url").value = s.url;
row.querySelector("button").onclick = () => row.remove();
$("#socials").append(row);
}
function fill(c) {
$("#audience").value = c.audience;
$("#positioning").value = c.positioning;
document.querySelectorAll(".topic").forEach((el, i) => (el.value = c.topics[i] || ""));
$("#socials").innerHTML = "";
c.socials.forEach(addSocial);
}
function showErrors(e = {}) {
for (const k of ["audience", "positioning", "topics", "socials", "form"]) $("#e-" + k).textContent = e[k] || "";
}
$("#add").onclick = () => addSocial();
$("#f").onsubmit = async (ev) => {
ev.preventDefault();
$("#status").textContent = "";
const body = {
audience: $("#audience").value,
positioning: $("#positioning").value,
topics: [...document.querySelectorAll(".topic")].map((el) => el.value),
socials: [...document.querySelectorAll("#socials .row")].map((r) => ({ platform: r.querySelector(".platform").value, url: r.querySelector(".url").value })),
};
try {
const res = await fetch("/api/card", { method: "PUT", headers: { "content-type": "application/json" }, body: JSON.stringify(body) });
const data = await res.json();
if (!res.ok) return showErrors(data.errors);
showErrors(); fill(data); $("#status").textContent = "Сохранено";
} catch { showErrors({ form: "Не удалось сохранить, проверьте соединение" }); }
};
fetch("/api/card").then((r) => r.json()).then(fill).catch(() => showErrors({ form: "Не удалось загрузить карточку" }));
</script>
</body>
</html>