Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | INFRASTRUCTURE & AUTOMATION4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : MacLustr Social Engine & Remote Navigator8 * File : apps/social-web/src/screens/settings/Users.tsx9 * Module : screens10 * Repository : https://git.spboucher.ai/maclustr-social11 * Project Website : https://social.spboucher.ai12 * Created : 2026-12-0113 * Last Modified : 2026-12-0114 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: admin@spboucher.ai23 * Technical Contact: dev@spboucher.ai24 * Security/Admin : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142import { useState } from 'react';43import type { Role } from '@mls/contracts';44import { ROLES } from '../../consts.ts';45import { get, post } from '../../../../shared/api.ts';46import { usePrefs } from '../../prefs.tsx';47import { useSession } from '../../session.tsx';48import type { UserRow } from '../../types.ts';49import { ActionStatus, Await, CopyButton, Field, Notice, Panel, TableWrap, Tag, useAction, useLoad } from '../../ui/core.tsx';5051export function Users() {52 const { t, tl, dt } = usePrefs();53 const s = useSession();54 const list = useLoad(() => get<{ users: UserRow[] }>('/v1/users'), []);55 const [f, setF] = useState({ handle: '', displayName: '', role: 'editor' as Role });56 const [link, setLink] = useState<{ who: string; url: string } | null>(null);57 const [disabling, setDisabling] = useState('');58 const a = useAction();59 const create = async () => { const r = await a.run(() => post<{ id: string; setupLink: string }>('/v1/users', { handle: f.handle, displayName: f.displayName.trim(), role: f.role })); if (r) { setLink({ who: f.handle, url: r.setupLink }); setF({ handle: '', displayName: '', role: 'editor' }); list.reload(); } };60 const relink = async (u: UserRow, target: 'social' | 'navigator') => { const r = await a.run(() => post<{ setupLink: string }>(`/v1/users/${u.id}/setup-link`, { target })); if (r) setLink({ who: u.handle, url: r.setupLink }); };61 const disable = async (u: UserRow) => { setDisabling(''); if (await a.run(() => post(`/v1/users/${u.id}/disable`), t('c.saved'))) list.reload(); };62 return (63 <>64 {link ? (65 <Notice tone="warn">66 <p><strong>{t('us.linkOnce', { who: link.who })}</strong></p>67 <p>{t('us.linkWarn')}</p>68 <p><code className="token">{link.url}</code></p>69 <p className="row"><CopyButton text={link.url} /><button type="button" className="small-btn" onClick={() => setLink(null)}>{t('wk.tokenHide')}</button></p>70 </Notice>71 ) : null}72 <Panel title={t('us.title')}>73 <Await of={list}>{(d) => (74 <TableWrap caption={t('us.title')}>75 <thead><tr><th scope="col">{t('c.name')}</th><th scope="col">{t('mb.handle')}</th><th scope="col">{t('c.role')}</th><th scope="col">{t('c.status')}</th><th scope="col" className="num">{t('us.passkeys')}</th><th scope="col">{t('c.created')}</th><th scope="col">{t('c.actions')}</th></tr></thead>76 <tbody>{d.users.map((u) => (77 <tr key={u.id}><th scope="row">{u.display_name}</th><td><code>{u.handle}</code></td><td>{tl('role', u.role)}</td><td><Tag prefix="userStatus" value={u.status} tone={u.status === 'active' ? 'ok' : 'idle'} /></td><td className="num">{u.passkeys}</td><td>{dt(u.created_at)}</td>78 <td>{u.status !== 'active' ? '—' : <span className="row">79 <button type="button" className="small-btn" disabled={a.busy} onClick={() => relink(u, 'social')}>{t('us.linkSocial')}</button>80 <button type="button" className="small-btn" disabled={a.busy} onClick={() => relink(u, 'navigator')}>{t('us.linkNavigator')}</button>81 {u.id === s.me.user.id ? null : disabling === u.id ? <><button type="button" className="small-btn danger" disabled={a.busy} onClick={() => disable(u)}>{t('c.confirm')}</button><button type="button" className="small-btn" onClick={() => setDisabling('')}>{t('c.cancel')}</button></> : <button type="button" className="small-btn" onClick={() => setDisabling(u.id)}>{t('us.disable')}</button>}82 </span>}</td></tr>83 ))}</tbody>84 </TableWrap>85 )}</Await>86 <ActionStatus a={a} />87 </Panel>88 <Panel title={t('us.new')}>89 <p className="small">{t('us.newLead')}</p>90 <form className="form inline-form" onSubmit={(e) => { e.preventDefault(); void create(); }}>91 <Field label={t('mb.handle')} hint={t('us.handleHint')}><input value={f.handle} onChange={(e) => setF({ ...f, handle: e.target.value })} pattern="[a-z0-9._-]{2,40}" className="mono" required /></Field>92 <Field label={t('us.displayName')}><input value={f.displayName} onChange={(e) => setF({ ...f, displayName: e.target.value })} maxLength={80} required /></Field>93 <Field label={t('c.role')}><select value={f.role} onChange={(e) => setF({ ...f, role: e.target.value as Role })}>{ROLES.map((r) => <option key={r} value={r}>{tl('role', r)}</option>)}</select></Field>94 <button type="submit" className="primary" disabled={a.busy || !/^[a-z0-9._-]{2,40}$/.test(f.handle) || !f.displayName.trim()}>{t('c.create')}</button>95 </form>96 </Panel>97 </>98 );99}100