import { useState } from 'react'; import { __, _n, sprintf } from '@wordpress/i18n'; import { api, cfg } from '../api.js'; import { Button, Card, Field, Notice, Stat, toast } from '../ui.jsx'; export default function Notifications({ data }) { const [f, setF] = useState({ title: '', body: '', url: '', role: '' }); const [busy, setBusy] = useState(false); const [err, setErr] = useState(''); const [sent, setSent] = useState(null); const set = (k) => (e) => setF((x) => ({ ...x, [k]: e.target.value })); const audience = f.role ? data.roles.find((r) => r.slug === f.role)?.label : __('all members', 'dashbread'); const send = async (e) => { e.preventDefault(); setBusy(true); setErr(''); try { const r = await api.broadcast(f); setSent(r); setF({ title: '', body: '', url: '', role: '' }); toast.show(r.queued ? sprintf( /* translators: %s: number of members */ _n('Queued for %s member', 'Queued for %s members', r.sent, 'dashbread'), r.sent ) : sprintf( /* translators: %s: number of members */ _n('Sent to %s member', 'Sent to %s members', r.sent, 'dashbread'), r.sent )); } catch (ex) { setErr(ex.message); } setBusy(false); }; return (
/{data.status.route}/notifications{__('In-app only.', 'dashbread')} Dashbread Pro {/* translators: follows the product name "Dashbread Pro" */ __('also emails each notification through your SMTP or SparkPost account with a branded HTML wrapper.', 'dashbread')} {__('Learn more', 'dashbread')}
dashbread_notify()