Created update button for workspace settings -- these include TIMEZONE and WORKSPACE NAME
This commit is contained in:
+33
-8
@@ -1,6 +1,6 @@
|
||||
// Screens for Dashy
|
||||
|
||||
function LoginScreen({ onLogin, dbUsers = [] }) {
|
||||
function LoginScreen({ onLogin, dbUsers = [], workspace }) {
|
||||
const [pickedId, setPickedId] = React.useState('rod');
|
||||
const [password, setPassword] = React.useState('');
|
||||
const [error, setError] = React.useState('');
|
||||
@@ -28,7 +28,7 @@ function LoginScreen({ onLogin, dbUsers = [] }) {
|
||||
<span className="login__wordmark">Dashy</span>
|
||||
</div>
|
||||
<h1 className="login__title">Pick up where you left off.</h1>
|
||||
<p className="login__sub">Sign in to your team workspace · <span className="mono">murchison-auto</span></p>
|
||||
<p className="login__sub">Sign in to your team workspace · <span className="mono">{workspace ? workspace.name : 'loading…'}</span></p>
|
||||
|
||||
<div className="login__users">
|
||||
{dbUsers.map(u => (
|
||||
@@ -106,13 +106,13 @@ function BrandMark({ size = 22 }) {
|
||||
);
|
||||
}
|
||||
|
||||
function TopBar({ me, dbUsers = [], isAdmin, tab, setTab, onAdd, onLogs, onLogout, onProfile }) {
|
||||
function TopBar({ me, dbUsers = [], isAdmin, tab, setTab, onAdd, onLogs, onLogout, onProfile, workspace }) {
|
||||
return (
|
||||
<header className="topbar">
|
||||
<div className="topbar__left">
|
||||
<span className="topbar__brand"><BrandMark /><span>Dashy</span></span>
|
||||
<span className="topbar__divider" />
|
||||
<span className="topbar__workspace">murchison-auto</span>
|
||||
<span className="topbar__workspace">{workspace ? workspace.name : 'loading…'}</span>
|
||||
</div>
|
||||
|
||||
<nav className="tabs" role="tablist">
|
||||
@@ -682,7 +682,7 @@ function FilterChip({ on, onClick, children }) {
|
||||
);
|
||||
}
|
||||
|
||||
function SettingsScreen({ user, dbUsers, isAdmin, onClose, onSave, onLogout, onSwitchUser, onCreateUser, onDeleteUser, onUpdateUserRole, onChangePassword }) {
|
||||
function SettingsScreen({ user, dbUsers, isAdmin, onClose, onSave, onLogout, onSwitchUser, onCreateUser, onDeleteUser, onUpdateUserRole, onChangePassword, workspace, onUpdateWorkspace }) {
|
||||
const [name, setName] = React.useState(user.name);
|
||||
const [role, setRole] = React.useState(user.role);
|
||||
const [photo, setPhoto] = React.useState(user.photo || null);
|
||||
@@ -887,6 +887,8 @@ function SettingsScreen({ user, dbUsers, isAdmin, onClose, onSave, onLogout, onS
|
||||
onCreateUser={onCreateUser}
|
||||
onDeleteUser={onDeleteUser}
|
||||
onUpdateUserRole={onUpdateUserRole}
|
||||
workspace={workspace}
|
||||
onUpdateWorkspace={onUpdateWorkspace}
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
@@ -907,13 +909,21 @@ function ToggleRow({ label, defaultOn = false }) {
|
||||
);
|
||||
}
|
||||
|
||||
function WorkspaceTab({ user, isAdmin, dbUsers = [], onSwitchUser, onCreateUser, onDeleteUser, onUpdateUserRole }) {
|
||||
function WorkspaceTab({ user, isAdmin, dbUsers = [], onSwitchUser, onCreateUser, onDeleteUser, onUpdateUserRole, workspace, onUpdateWorkspace }) {
|
||||
const [adding, setAdding] = React.useState(false);
|
||||
const [newName, setNewName] = React.useState('');
|
||||
const [newRole, setNewRole] = React.useState('');
|
||||
const [newType, setNewType] = React.useState('standard');
|
||||
const [wsName, setWsName] = React.useState('murchison-auto');
|
||||
const [wsTz, setWsTz] = React.useState('Pacific/Auckland');
|
||||
const [wsName, setWsName] = React.useState(workspace ? workspace.name : '');
|
||||
const [wsTz, setWsTz] = React.useState(workspace ? workspace.timezone : '');
|
||||
const [wsSaved, setWsSaved] = React.useState(false);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (workspace) {
|
||||
setWsName(workspace.name);
|
||||
setWsTz(workspace.timezone);
|
||||
}
|
||||
}, [workspace]);
|
||||
|
||||
const submit = () => {
|
||||
if (!newName.trim()) return;
|
||||
@@ -921,6 +931,14 @@ function WorkspaceTab({ user, isAdmin, dbUsers = [], onSwitchUser, onCreateUser,
|
||||
setNewName(''); setNewRole(''); setNewType('standard'); setAdding(false);
|
||||
};
|
||||
|
||||
const handleUpdateWorkspace = async () => {
|
||||
await onUpdateWorkspace({ name: wsName, timezone: wsTz });
|
||||
setWsSaved(true);
|
||||
setTimeout(() => setWsSaved(false), 2000);
|
||||
};
|
||||
|
||||
const wsDirty = workspace && (wsName !== workspace.name || wsTz !== workspace.timezone);
|
||||
|
||||
return (
|
||||
<>
|
||||
<h3 className="settings__h">Switch user</h3>
|
||||
@@ -1019,6 +1037,13 @@ function WorkspaceTab({ user, isAdmin, dbUsers = [], onSwitchUser, onCreateUser,
|
||||
<input className="field__input" value={wsTz} onChange={e => setWsTz(e.target.value)} disabled={!isAdmin} />
|
||||
</label>
|
||||
</div>
|
||||
{isAdmin && (
|
||||
<div className="settings__save-row" style={{ marginTop: '1rem' }}>
|
||||
{wsSaved && <span className="settings__saved mono"><Icon.Check /> Saved</span>}
|
||||
<button className="btn btn--ghost" onClick={() => { setWsName(workspace.name); setWsTz(workspace.timezone); }} disabled={!wsDirty}>Discard</button>
|
||||
<button className="btn btn--primary" onClick={handleUpdateWorkspace} disabled={!wsDirty}>Update workspace</button>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user