import { useEffect, useState } from 'react'; import { __, _x, sprintf } from '@wordpress/i18n'; import { api, cfg } from '../api.js'; import { Button, Card, Field, Icon, Notice, Switch, toast } from '../ui.jsx'; export default function Settings({ data, setData }) { const [s, setS] = useState(data.settings); const [busy, setBusy] = useState(false); const [err, setErr] = useState(''); const dirty = JSON.stringify(s) !== JSON.stringify(data.settings); const set = (k) => (v) => setS((x) => ({ ...x, [k]: v })); const status = data.status; useEffect(() => { const h = (e) => { if (dirty) { e.preventDefault(); e.returnValue = ''; } }; window.addEventListener('beforeunload', h); return () => window.removeEventListener('beforeunload', h); }, [dirty]); const pickLogo = () => { if (!window.wp?.media) return; const frame = window.wp.media({ title: __('Choose an app logo', 'dashbread'), button: { text: __('Use this logo', 'dashbread') }, library: { type: 'image' }, multiple: false }); frame.on('select', () => { const a = frame.state().get('selection').first().toJSON(); setS((x) => ({ ...x, logo_id: a.id, logo_url: a.sizes?.medium?.url || a.url })); }); frame.open(); }; const save = async (e) => { e.preventDefault(); setBusy(true); setErr(''); try { const res = await api.saveSettings(s); setData((d) => ({ ...d, settings: res.settings, status: res.status })); setS(res.settings); toast.show(__('Settings saved', 'dashbread')); } catch (ex) { setErr(ex.message); } setBusy(false); }; return (
{err && setErr('')}>{err}} {status.route_conflict && {/* translators: followed by the conflicting slug */ __('A page already uses the slug', 'dashbread')} {status.route}. {/* translators: followed by the link text "rename the page" */ __('The app route wins;', 'dashbread')} {__('rename the page', 'dashbread')} {/* translators: follows "rename the page" */ __('or change the route below.', 'dashbread')}}
{__('Members\' dashboard lives here.', 'dashbread')} {/* translators: followed by the default route value "app" */ _x('Default', 'followed by a default value', 'dashbread')} app. {__('Changing it re-saves permalinks.', 'dashbread')}}>
{status.home} set('route')(e.target.value)} className="sa-input sa-input-short" />
set('site_name')(e.target.value)} placeholder={window.DashbreadAdmin?.site} />
{s.logo_url ? : } {!!s.logo_id && }
set('footer_text')(e.target.value)} placeholder={sprintf( /* translators: 1: current year, 2: site name */ __('© %1$s %2$s', 'dashbread'), window.DashbreadAdmin?.year, window.DashbreadAdmin?.site )} />
set('primary')(e.target.value)} />{s.primary}
{[['console', _x('Console', 'preset name', 'dashbread'), __('Dense, dark sidebar', 'dashbread')], ['comfort', _x('Comfort', 'preset name', 'dashbread'), __('Roomy, light sidebar', 'dashbread')]].map(([v, l, d]) => ( ))}
{[['light', _x('Light', 'color mode', 'dashbread')], ['dark', _x('Dark', 'color mode', 'dashbread')], ['auto', __('Follow device', 'dashbread')]].map(([v, l]) => ( ))}

{/* translators: followed by a WordPress capability name */ __('“Members” means users without the', 'dashbread')} edit_posts {/* translators: follows a WordPress capability name */ __('capability.', 'dashbread')} {__('Staff keep wp-admin exactly as it is.', 'dashbread')}

{dirty && }
); }