33 lines
1.2 KiB
JavaScript
33 lines
1.2 KiB
JavaScript
import { h } from '/static/admin2/vendor/preact.module.js';
|
|
import { useState } from '/static/admin2/vendor/hooks.module.js';
|
|
import htm from '/static/admin2/vendor/htm.module.js';
|
|
import { api } from '/static/admin2/api.js';
|
|
const html = htm.bind(h);
|
|
|
|
export const Task = ({ item, onDone, onError }) => {
|
|
const [busy, setBusy] = useState(false);
|
|
const run = async (path, body) => {
|
|
setBusy(true);
|
|
try {
|
|
await api(path, body ? {method: 'POST', body: JSON.stringify(body)}
|
|
: {method: 'POST'});
|
|
onDone(item.key);
|
|
} catch (e) {
|
|
onError(e.message || 'Не удалось выполнить');
|
|
} finally {
|
|
setBusy(false);
|
|
}
|
|
};
|
|
return html`
|
|
<article class="task">
|
|
<div><b>${item.title}</b><p>${item.detail}</p></div>
|
|
<div class="task-actions">
|
|
<button type="button" disabled=${busy} onClick=${() => run(
|
|
'/api/admin/v2/attention/' + encodeURIComponent(item.key) + '/done')}>Готово</button>
|
|
<button type="button" disabled=${busy} onClick=${() => run(
|
|
'/api/admin/v2/attention/' + encodeURIComponent(item.key) + '/snooze',
|
|
{minutes: 60})}>1 ч</button>
|
|
</div>
|
|
</article>`;
|
|
};
|