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/ui/Emergency.tsx9 * Module : ui10 * 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 */4142// Permanent emergency-stop control and banner. Engaging: admin or owner, typed reason, then a confirm step. Releasing: owner only.43import { useState } from 'react';44import { post } from '../../../shared/api.ts';45import { usePrefs } from '../prefs.tsx';46import { useSession } from '../session.tsx';47import { ActionStatus, Field, Modal, useAction } from './core.tsx';4849export function EmergencyBanner() {50 const { t, dt } = usePrefs();51 const { me } = useSession();52 if (!me.emergency.emergency_stop) return null;53 return (54 <div className="estop-banner" role="alert">55 <span className="estop-mark" aria-hidden="true" />56 <p><strong>{t('estop.banner')}</strong> {t('estop.bannerReason', { reason: me.emergency.reason || '—' })} <span className="estop-since">{t('estop.bannerSince', { date: dt(me.emergency.changed_at) })}</span></p>57 </div>58 );59}6061export function EmergencyControl() {62 const { t } = usePrefs();63 const s = useSession();64 const engaged = s.me.emergency.emergency_stop;65 const [open, setOpen] = useState<'engage' | 'release' | null>(null);66 const allowed = engaged ? s.isOwner : s.isAdmin;67 return (68 <div className="estop">69 <button type="button" className={engaged ? 'estop-btn estop-btn-on' : 'estop-btn'} onClick={() => setOpen(engaged ? 'release' : 'engage')} disabled={!allowed} title={allowed ? undefined : engaged ? t('estop.ownerOnly') : t('estop.adminOnly')} aria-describedby={allowed ? undefined : 'estop-why'}>70 <span className="estop-glyph" aria-hidden="true" />{engaged ? t('estop.release') : t('estop.button')}71 </button>72 {!allowed ? <span id="estop-why" className="sr">{engaged ? t('estop.ownerOnly') : t('estop.adminOnly')}</span> : null}73 {open ? <EmergencyDialog engage={open === 'engage'} onClose={() => setOpen(null)} /> : null}74 </div>75 );76}7778function EmergencyDialog({ engage, onClose }: { engage: boolean; onClose: () => void }) {79 const { t } = usePrefs();80 const s = useSession();81 const [reason, setReason] = useState('');82 const [step, setStep] = useState<1 | 2>(1);83 const [paused, setPaused] = useState<number | null>(null);84 const a = useAction();85 const valid = reason.trim().length >= 3 && reason.length <= 500;86 const send = async () => {87 const r = await a.run(() => post<{ engaged: boolean; paused?: number }>('/v1/emergency-stop', { engage, reason: reason.trim() }), t('c.done'));88 if (r) { setPaused(typeof r.paused === 'number' ? r.paused : null); await s.reloadMe(); if (!engage || typeof r.paused !== 'number') onClose(); }89 };90 return (91 <Modal title={engage ? t('estop.engage.title') : t('estop.release.title')} onClose={onClose}>92 <p>{engage ? t('estop.engage.what') : t('estop.release.what')}</p>93 {paused !== null ? (<>94 <p role="status"><strong>{t('estop.engaged')}.</strong> {t('estop.result', { n: paused })}</p>95 <div className="row"><button type="button" className="primary" onClick={onClose}>{t('c.close')}</button></div>96 </>) : step === 1 ? (97 <form onSubmit={(e) => { e.preventDefault(); if (valid) setStep(2); }}>98 <Field label={t('estop.reason')} wide><textarea value={reason} onChange={(e) => setReason(e.target.value)} rows={3} maxLength={500} required autoFocus /></Field>99 <div className="row"><button type="submit" className="primary" disabled={!valid}>{t('estop.next')}</button><button type="button" onClick={onClose}>{t('c.cancel')}</button></div>100 </form>101 ) : (<>102 <p>{engage ? t('estop.confirmEngage') : t('estop.confirmRelease')}</p>103 <blockquote className="quote">{reason.trim()}</blockquote>104 <div className="row">105 <button type="button" className="danger" onClick={send} disabled={a.busy}>{engage ? t('estop.doEngage') : t('estop.doRelease')}</button>106 <button type="button" onClick={() => setStep(1)} disabled={a.busy}>{t('c.back')}</button>107 </div>108 <ActionStatus a={a} />109 </>)}110 </Modal>111 );112}113