feat(админка): экран жалоб v2

This commit is contained in:
anor
2026-11-06 23:01:52 +10:00
parent 520b7c5a10
commit b847e6727f
10 changed files with 282 additions and 5 deletions
+3 -1
View File
@@ -4,6 +4,7 @@ import { SECTIONS, sectionFromPath, hrefFor } from '/static/admin2/router.js';
import { DayPage } from '/static/admin2/pages/day.js';
import { CustomersPage } from '/static/admin2/pages/customers.js';
import { MoneyPage } from '/static/admin2/pages/money.js';
import { WorkPage } from '/static/admin2/pages/work.js';
const html = htm.bind(h);
const TITLES = {
@@ -29,7 +30,8 @@ const App = () => html`
<header class="top"><div><h1>${title}</h1><p>${subtitle}</p></div></header>
${section === 'today' ? html`<${DayPage} />`
: section === 'customers' ? html`<${CustomersPage} />`
: section === 'money' ? html`<${MoneyPage} />` : html`
: section === 'money' ? html`<${MoneyPage} />`
: section === 'work' ? html`<${WorkPage} />` : html`
<section class="card" aria-labelledby="placeholder">
<h2 id="placeholder">Раздел готовится</h2>
<p>Данные и действия подключит следующий этап.</p>
+67
View File
@@ -0,0 +1,67 @@
import { h } from '/static/admin2/vendor/preact.module.js';
import { useEffect, useState } from '/static/admin2/vendor/hooks.module.js';
import htm from '/static/admin2/vendor/htm.module.js';
import { api } from '/static/admin2/api.js';
import { Table } from '/static/admin2/ui/table.js';
const html = htm.bind(h);
const CAT = {wrong_answer: 'неверный ответ', off_topic: 'не по делу', failure: 'сбой',
praise: 'похвала'};
const ST = {new: 'новое', resolved: 'разобрано', deferred: 'отложено', ignored: 'игнор'};
const when = (ts) => new Date(ts * 1000).toLocaleString('ru-RU');
export function WorkPage() {
const [status, setStatus] = useState('new');
const [category, setCategory] = useState('');
const [page, setPage] = useState(1);
const [data, setData] = useState(null);
const [error, setError] = useState('');
const [reload, setReload] = useState(0);
useEffect(() => {
let alive = true;
const p = new URLSearchParams({page: String(page), per_page: '50'});
if (status) p.set('status', status);
if (category) p.set('category', category);
api('/api/admin/v2/feedback?' + p).then((d) => {
if (alive) { setData(d); setError(''); }
}).catch((e) => { if (alive) setError(e.message || 'Жалобы не загрузились'); });
return () => { alive = false; };
}, [status, category, page, reload]);
const mark = async (id, next) => {
try {
await api('/api/admin/v2/feedback/' + id + '/status',
{method: 'POST', body: JSON.stringify({status: next})});
setReload((n) => n + 1);
} catch (e) { setError(e.message || 'Не удалось разобрать'); }
};
const columns = [
{key: 'timestamp', label: 'Когда', render: (r) => when(r.timestamp)},
{key: 'username', label: 'Клиент'},
{key: 'category', label: 'Категория', render: (r) => CAT[r.category] || 'без разбора'},
{key: 'comment', label: 'Комментарий', render: (r) => html`<div>
${r.comment || 'без текста'}${r.answer ? html`<small class="note">${String(r.answer).slice(0, 160)}</small>` : null}</div>`},
{key: 'status', label: 'Статус', render: (r) => html`<span class=${'badge s-' + r.status}>${ST[r.status] || r.status}</span>`},
{key: 'actions', label: 'Действие', render: (r) => html`<div class="task-actions">
<button type="button" onClick=${() => mark(r.id, 'resolved')}>Разобрано</button>
<button type="button" onClick=${() => mark(r.id, 'deferred')}>Отложить</button></div>`},
];
return html`
<div class="toolbar">
<select aria-label="Статус" value=${status} onChange=${(e) => { setStatus(e.currentTarget.value); setPage(1); }}>
<option value="">Все</option>${Object.entries(ST).map(([k, v]) => html`<option key=${k} value=${k}>${v}</option>`)}
</select>
<select aria-label="Категория" value=${category} onChange=${(e) => { setCategory(e.currentTarget.value); setPage(1); }}>
<option value="">Все категории</option>${Object.entries(CAT).map(([k, v]) => html`<option key=${k} value=${k}>${v}</option>`)}
</select>
<span class="note" role="status">${data ? 'Всего: ' + data.total : ''}</span>
<button type="button" disabled=${!data || page <= 1} onClick=${() => setPage(page - 1)}>←</button>
<button type="button" disabled=${!data || page * 50 >= data.total} onClick=${() => setPage(page + 1)}>→</button>
</div>
${error ? html`<div class="card error" role="alert">${error}</div>` : null}
${data ? html`<${Table} columns=${columns} rows=${data.items.map((r) => ({...r, key: r.id}))}
empty="Жалоб нет" />` : html`<div class="card">Загрузка…</div>`}`;
}
+3
View File
@@ -79,3 +79,6 @@ tr.clickable{cursor:pointer} tr.clickable:hover td{background:#f3f6ff}
.s-refunded{background:#f2f4f7;color:#667085}.s-canceled{background:#fde8e7;color:#b42318}
.s-low{background:#fff4e5;color:#b54708}.s-ok{background:#e7f6ec;color:#067647}
.s-new{background:#fff4e5;color:#b54708}.s-resolved{background:#e7f6ec;color:#067647}
.s-deferred,.s-ignored{background:#f2f4f7;color:#667085}