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:
1 parent
22d2418125
commit
45ab567355
6 files changed
+210
-77
No files matched your search
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -354,6 +354,10 @@ tr.row-detail > td { padding: 0; background: var(--surface-2); border-bottom: 1p
|
||||
.session-detail { padding: 16px 18px 20px; }
|
||||
.session-desc { margin: 0 0 14px; font-size: 13.5px; line-height: 1.6; color: var(--text); max-width: 80ch; white-space: pre-wrap; }
|
||||
.detail-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 18px; align-items: start; }
|
||||
.material-panel { display: flex; flex-direction: column; gap: 8px; }
|
||||
.material-panel .material-file { font-size: 12.5px; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 340px; }
|
||||
.material-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
|
||||
.material-upload { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
|
||||
.detail-cols h3 { font-size: 12px; font-weight: 800; text-transform: uppercase; letter-spacing: .4px; color: #5a5555; margin: 0 0 9px; }
|
||||
.detail-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 7px; max-height: 280px; overflow-y: auto; }
|
||||
.detail-list li { display: flex; align-items: center; gap: 9px; font-size: 13px; }
|
||||
|
||||
@@ -2,21 +2,18 @@ import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { supabase } from '../lib/supabase';
|
||||
import {
|
||||
deleteEventSchedule,
|
||||
downloadSessionMaterial,
|
||||
getAllContacts,
|
||||
getAllSessionSpeakers,
|
||||
getActiveEvent,
|
||||
getSessions,
|
||||
getSlots,
|
||||
removeSessionMaterial,
|
||||
openSessionMaterial,
|
||||
sessionMaterialName,
|
||||
setSessionSpeakers,
|
||||
uploadSessionMaterial,
|
||||
} from '../lib/api';
|
||||
import type { Contact, Event, Session, SessionSpeaker, Slot, SlotType } from '../lib/types';
|
||||
import { useSilentRefresh } from '../lib/useSilentRefresh';
|
||||
import { useToast } from '../context/ToastContext';
|
||||
import { MaterialPanel } from '../components/MaterialPanel';
|
||||
import { Empty, Modal, Spinner, TypeBadge } from '../components/ui';
|
||||
|
||||
const SLOT_TYPES: SlotType[] = ['session', 'service_session'];
|
||||
@@ -470,8 +467,6 @@ function SessionModal({
|
||||
const [area, setArea] = useState(session?.area ?? '');
|
||||
const [speakerEmails, setSpeakerEmails] = useState<string[]>(currentSpeakers);
|
||||
const [material, setMaterial] = useState<File | null>(null);
|
||||
const [matBusy, setMatBusy] = useState(false);
|
||||
const [matError, setMatError] = useState<string | null>(null);
|
||||
const [busy, setBusy] = useState(false);
|
||||
|
||||
async function save() {
|
||||
@@ -580,66 +575,11 @@ function SessionModal({
|
||||
{session && (
|
||||
<div className="field" data-testid="session-material">
|
||||
<label>Material</label>
|
||||
{session.material_path ? (
|
||||
<div style={{ display: 'flex', flexDirection: 'column', gap: 8 }}>
|
||||
<div className="muted small">📎 {sessionMaterialName(session.material_path)}</div>
|
||||
<div className="row" style={{ gap: 10, flexWrap: 'wrap' }}>
|
||||
<button
|
||||
className="btn small"
|
||||
disabled={busy || matBusy}
|
||||
onClick={async () => {
|
||||
setMatBusy(true);
|
||||
setMatError(null);
|
||||
try {
|
||||
await openSessionMaterial(session.material_path!);
|
||||
} catch (e) {
|
||||
setMatError(e instanceof Error ? e.message : 'Could not open material');
|
||||
} finally {
|
||||
setMatBusy(false);
|
||||
}
|
||||
}}
|
||||
>
|
||||
Open
|
||||
</button>
|
||||
<button
|
||||
className="btn small"
|
||||
disabled={busy || matBusy}
|
||||
onClick={async () => {
|
||||
setMatBusy(true);
|
||||
setMatError(null);
|
||||
try {
|
||||
await downloadSessionMaterial(session.material_path!);
|
||||
} catch (e) {
|
||||
setMatError(e instanceof Error ? e.message : 'Download failed');
|
||||
} finally {
|
||||
setMatBusy(false);
|
||||
}
|
||||
}}
|
||||
>
|
||||
⬇ Download
|
||||
</button>
|
||||
<button
|
||||
className="btn small danger"
|
||||
disabled={busy || matBusy}
|
||||
onClick={async () => {
|
||||
if (!confirm(`Delete material "${sessionMaterialName(session.material_path!)}"? Attendees and speakers lose access immediately.`)) return;
|
||||
setMatBusy(true);
|
||||
try {
|
||||
await removeSessionMaterial(session.id);
|
||||
onSaved('Material removed');
|
||||
} catch (e) {
|
||||
setMatBusy(false);
|
||||
setMatError(e instanceof Error ? e.message : 'Delete failed');
|
||||
}
|
||||
}}
|
||||
>
|
||||
Delete
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<span className="muted small">No material uploaded yet.</span>
|
||||
)}
|
||||
<MaterialPanel
|
||||
session={session}
|
||||
unlocksAt={slot ? `${fmtDate(slot.slot_date)}, ${fmtTime(slot.end_time)}` : null}
|
||||
onChanged={() => onSaved('Material removed')}
|
||||
/>
|
||||
<input
|
||||
className="input"
|
||||
type="file"
|
||||
@@ -650,14 +590,6 @@ function SessionModal({
|
||||
{session.material_path ? 'Replaces current file on Save' : 'Uploads on Save'}: {material.name}
|
||||
</span>
|
||||
)}
|
||||
{slot && (
|
||||
<span className="muted small">
|
||||
{session.material_path
|
||||
? `Attendees can download it once the session ends (${fmtDate(slot.slot_date)}, ${fmtTime(slot.end_time)}).`
|
||||
: `Once uploaded, attendees can download it when the session ends (${fmtDate(slot.slot_date)}, ${fmtTime(slot.end_time)}).`}
|
||||
</span>
|
||||
)}
|
||||
{matError && <span className="feedback-error small">{matError}</span>}
|
||||
</div>
|
||||
)}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import {
|
||||
getLlmSettings,
|
||||
getSessions,
|
||||
getSlots,
|
||||
sessionMaterialName,
|
||||
} from '../lib/api';
|
||||
import type {
|
||||
Checkin,
|
||||
@@ -24,6 +25,7 @@ import type {
|
||||
Slot,
|
||||
} from '../lib/types';
|
||||
import { Avatar, Empty, Spinner, Tooltip } from '../components/ui';
|
||||
import { MaterialPanel, MaterialUploadRow } from '../components/MaterialPanel';
|
||||
import { useSilentRefresh } from '../lib/useSilentRefresh';
|
||||
|
||||
const timeLabel = (slot?: Slot) => (slot ? `${slot.start_time.slice(0, 5)}–${slot.end_time.slice(0, 5)}` : '');
|
||||
@@ -429,6 +431,7 @@ export function Sessions() {
|
||||
<th>When</th>
|
||||
<th>Session</th>
|
||||
<th>Speakers</th>
|
||||
<th>Material</th>
|
||||
<th style={{ textAlign: 'right' }}>Check-ins</th>
|
||||
<th style={{ textAlign: 'right' }}>Feedback</th>
|
||||
<th>AI summary</th>
|
||||
@@ -478,6 +481,19 @@ export function Sessions() {
|
||||
</div>
|
||||
)}
|
||||
</td>
|
||||
<td>
|
||||
{s.material_path ? (
|
||||
<Tooltip title={sessionMaterialName(s.material_path)} content="Manage it in the expanded row">
|
||||
<span className="pill green" data-testid={`material-yes-${s.id}`}>
|
||||
uploaded
|
||||
</span>
|
||||
</Tooltip>
|
||||
) : (
|
||||
<span className="muted small" data-testid={`material-none-${s.id}`}>
|
||||
—
|
||||
</span>
|
||||
)}
|
||||
</td>
|
||||
<td style={{ textAlign: 'right' }}>
|
||||
<span className={att.length > 0 ? 'att-count' : 'muted'}>{att.length}</span>
|
||||
{s.capacity ? <span className="muted small"> / {s.capacity}</span> : null}
|
||||
@@ -507,7 +523,7 @@ export function Sessions() {
|
||||
</tr>
|
||||
{open && (
|
||||
<tr className="row-detail">
|
||||
<td colSpan={6}>
|
||||
<td colSpan={7}>
|
||||
<div className="session-detail">
|
||||
{s.description && <p className="session-desc">{s.description}</p>}
|
||||
<div className="detail-cols">
|
||||
@@ -568,6 +584,15 @@ export function Sessions() {
|
||||
</p>
|
||||
)}
|
||||
</section>
|
||||
<section>
|
||||
<h3 className="h3">Material</h3>
|
||||
<MaterialPanel
|
||||
session={s}
|
||||
unlocksAt={slot ? `${fmtDay(slot.slot_date)}, ${slot.end_time.slice(0, 5)}` : null}
|
||||
onChanged={() => void load(true)}
|
||||
/>
|
||||
<MaterialUploadRow session={s} onUploaded={() => void load(true)} />
|
||||
</section>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
Reference in new issue
Block a user