feat(админка): удаление и восстановление из карточки
This commit is contained in:
@@ -12,7 +12,7 @@ const when = (ts) => ts ? new Date(ts * 1000).toLocaleString('ru-RU') : '—';
|
||||
const TABS = [['overview', 'Обзор'], ['dialogs', 'Диалоги'], ['ledger', 'Счёт'],
|
||||
['files', 'Файлы'], ['history', 'История']];
|
||||
|
||||
export function CustomerDrawer({ email, onClose }) {
|
||||
export function CustomerDrawer({ email, onClose, onDeleted, onChanged }) {
|
||||
const [card, setCard] = useState(null);
|
||||
const [tab, setTab] = useState('overview');
|
||||
const [rows, setRows] = useState([]);
|
||||
@@ -68,6 +68,23 @@ export function CustomerDrawer({ email, onClose }) {
|
||||
} catch (e) { setNotice(e.message || 'Не удалось отменить'); }
|
||||
finally { setBusy(false); }
|
||||
};
|
||||
const del = async () => {
|
||||
if (!confirm('Удалить учётку ' + email + '? Переписка и файлы останутся, адрес освободится.')) return;
|
||||
setBusy(true); setNotice('');
|
||||
try {
|
||||
await api('/api/admin/v2/customers/' + encodeURIComponent(email) + '/delete', {method: 'POST'});
|
||||
onDeleted && onDeleted(card ? card.profile.email : email);
|
||||
} catch (e) { setNotice(e.message || 'Не удалось удалить'); }
|
||||
finally { setBusy(false); }
|
||||
};
|
||||
const restore = async () => {
|
||||
setBusy(true); setNotice('');
|
||||
try {
|
||||
await api('/api/admin/v2/customers/' + encodeURIComponent(email) + '/restore', {method: 'POST'});
|
||||
onChanged && onChanged();
|
||||
} catch (e) { setNotice(e.message || 'Не удалось восстановить'); }
|
||||
finally { setBusy(false); }
|
||||
};
|
||||
const title = card ? card.profile.email : 'Карточка клиента';
|
||||
return html`
|
||||
<${Drawer} title=${title} onClose=${onClose}>
|
||||
@@ -92,7 +109,10 @@ export function CustomerDrawer({ email, onClose }) {
|
||||
<button type="button" disabled=${busy} onClick=${() => act('agent_access',
|
||||
{agent_access: !card.profile.agent_access}, card.profile.agent_access ? 'Доступ снят' : 'Доступ выдан')}>
|
||||
${card.profile.agent_access ? 'Снять агента' : 'Выдать агента'}</button>
|
||||
</div>` : null}
|
||||
<button type="button" disabled=${busy} onClick=${del}>Удалить</button>
|
||||
</div>` : html`<div class="actions-bar">
|
||||
<button type="button" disabled=${busy} onClick=${restore}>Восстановить</button>
|
||||
</div>`}
|
||||
${tab === 'overview' ? html`<div class="kv">
|
||||
<div><span>Статус</span><b>${card.profile.deleted_at ? 'удалён' : card.profile.blocked ? 'заблокирован' : 'активен'}</b></div>
|
||||
<div><span>Баланс</span><b>${rub(card.account && card.account.balance_rub)}</b></div>
|
||||
|
||||
Reference in New Issue
Block a user