feat(admin): material column + inline material manager in the Sessions view

- Sessions table gains a Material column (uploaded pill with the clean
  filename in its tooltip, dash when none)
- Expanded session row: shared MaterialPanel (open / download / delete
  with confirm) plus immediate upload/replace via MaterialUploadRow
- Schedule session modal refactored onto the same MaterialPanel; its
  upload keeps the uploads-on-Save behavior
- sessions-view e2e: new test pins the pill, panel buttons, clean
  filename, unlock hint and replace control

Co-authored-by: Stephan Charles <[email protected]>
Co-authored-by: Amelia Hernandez <[email protected]>
Co-authored-by: Markus Franz <[email protected]>
Co-authored-by: Sabrina Hota <[email protected]>
Co-authored-by: Nilüfer Doğan <[email protected]>
This commit is contained in:
committed 2026-10-21 21:30:31 +02:00
1 parent 22d2418125
commit 45ab567355
6 files changed
+210 -77

No files matched your search

+145
View File
@@ -0,0 +1,145 @@
import { useState } from 'react';
import {
downloadSessionMaterial,
openSessionMaterial,
removeSessionMaterial,
sessionMaterialName,
uploadSessionMaterial,
} from '../lib/api';
/**
* See / open / download / delete a session's material file. Admins bypass the
* attendee time-lock in storage RLS (`can_read_session_material` /
* `can_write_session_material` allow `is_admin()`), so every action works at
* any time — the `unlocksAt` hint is only about when *attendees* get access.
* Shared by the Schedule session modal and the Sessions view's expanded row.
*/
export function MaterialPanel(props: {
session: { id: string; material_path: string | null };
/** Human-readable unlock moment, e.g. "Thu, Oct 22, 16:30" — null falls back to a generic hint. */
unlocksAt?: string | null;
/** Notified after a successful delete (reload / close). */
onChanged: () => void;
}) {
const [busy, setBusy] = useState<'open' | 'download' | 'delete' | null>(null);
const [error, setError] = useState<string | null>(null);
const path = props.session.material_path;
if (!path) return <p className="muted small">No material uploaded yet.</p>;
const name = sessionMaterialName(path);
async function run(action: 'open' | 'download' | 'delete', fn: () => Promise<void>) {
setBusy(action);
setError(null);
try {
await fn();
} catch (cause) {
setError(cause instanceof Error ? cause.message : 'Material action failed');
} finally {
setBusy(null);
}
}
return (
<div className="material-panel" data-testid={`material-panel-${props.session.id}`}>
<div className="material-file" title={path}>
📎 {name}
</div>
<div className="material-actions">
<button
className="btn small"
onClick={() => void run('open', () => openSessionMaterial(path))}
disabled={busy !== null}
>
{busy === 'open' ? 'Opening…' : 'Open'}
</button>
<button
className="btn small"
onClick={() => void run('download', () => downloadSessionMaterial(path))}
disabled={busy !== null}
>
{busy === 'download' ? 'Downloading…' : '⬇ Download'}
</button>
<button
className="btn small danger"
onClick={() => {
if (!window.confirm(`Delete "${name}"? Attendees and the speaker will no longer be able to download it.`)) return;
void run('delete', async () => {
await removeSessionMaterial(props.session.id);
props.onChanged();
});
}}
disabled={busy !== null}
>
{busy === 'delete' ? 'Deleting…' : 'Delete'}
</button>
</div>
<p className="muted small">
{props.unlocksAt
? `Attendees can download it once the session ends (${props.unlocksAt}).`
: 'Attendees can download it once the session ends.'}
</p>
{error && (
<p className="feedback-error" role="alert">
{error}
</p>
)}
</div>
);
}
/**
* Immediate (not on-save) upload/replace of a session material — uploads the
* picked file and points the session at it in one go, removing the previous
* object. Used in the Sessions view's expanded row; the Schedule modal keeps
* its upload-on-save behavior instead.
*/
export function MaterialUploadRow(props: {
session: { id: string; material_path: string | null };
onUploaded: (path: string) => void;
}) {
const [busy, setBusy] = useState(false);
const [error, setError] = useState<string | null>(null);
const [uploadedName, setUploadedName] = useState<string | null>(null);
const previousPath = props.session.material_path;
async function upload(file: File) {
setBusy(true);
setError(null);
setUploadedName(null);
try {
const path = await uploadSessionMaterial(props.session.id, file, previousPath);
setUploadedName(file.name);
props.onUploaded(path);
} catch (cause) {
setError(cause instanceof Error ? cause.message : 'Upload failed');
} finally {
setBusy(false);
}
}
return (
<div className="material-upload">
<label className="btn small" style={{ cursor: 'pointer' }}>
<input
type="file"
style={{ display: 'none' }}
disabled={busy}
onChange={(e) => {
const file = e.target.files?.[0];
e.target.value = '';
if (file) void upload(file);
}}
/>
{busy ? 'Uploading…' : previousPath ? 'Replace file…' : 'Upload file…'}
</label>
{uploadedName && !busy && <span className="muted small">Uploaded “{uploadedName}”</span>}
{error && (
<span className="feedback-error small" role="alert">
{error}
</span>
)}
</div>
);
}