feat(admin): full session material management in the session editor
See the attached file (clean name), Open (signed-URL preview), Download (authenticated blob under the original filename), Delete (confirm, storage object + path, errors surface), and Upload/Replace with previous-object cleanup and upload rollback on DB failure. Admins already passed every storage RLS gate for material writes, so no migration; this also documents and smoke-verifies insert/read/update/delete as an impersonated admin. Also fixes the stale e2e expectation that the speaker-portal download is an <a href> (it became an authenticated blob button with the private bucket). 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
ea1ed87fc9
commit
5619b94c97
5 files changed
+150
-43
No files matched your search
@@ -2,6 +2,7 @@ import { useEffect, useMemo, useRef, useState } from 'react';
|
||||
import { supabase } from '../lib/supabase';
|
||||
import {
|
||||
deleteEventSchedule,
|
||||
downloadSessionMaterial,
|
||||
getAllContacts,
|
||||
getAllSessionSpeakers,
|
||||
getActiveEvent,
|
||||
@@ -9,6 +10,7 @@ import {
|
||||
getSlots,
|
||||
removeSessionMaterial,
|
||||
openSessionMaterial,
|
||||
sessionMaterialName,
|
||||
setSessionSpeakers,
|
||||
uploadSessionMaterial,
|
||||
} from '../lib/api';
|
||||
@@ -338,6 +340,7 @@ export function Schedule() {
|
||||
<SessionModal
|
||||
session={sessModal.session}
|
||||
slotId={sessModal.slotId}
|
||||
slot={slots.find((s) => s.id === sessModal.slotId)}
|
||||
eventId={event.id}
|
||||
contacts={contacts}
|
||||
currentSpeakers={speakersFor.get(sessModal.session?.id ?? '') ?? []}
|
||||
@@ -442,6 +445,7 @@ function SlotModal({
|
||||
function SessionModal({
|
||||
session,
|
||||
slotId,
|
||||
slot,
|
||||
eventId,
|
||||
contacts,
|
||||
currentSpeakers,
|
||||
@@ -450,6 +454,8 @@ function SessionModal({
|
||||
}: {
|
||||
session: Session | null;
|
||||
slotId: number;
|
||||
/** Slot this session belongs to; used to show when material unlocks for attendees. */
|
||||
slot?: Slot;
|
||||
eventId: string;
|
||||
contacts: Contact[];
|
||||
currentSpeakers: string[];
|
||||
@@ -464,6 +470,8 @@ 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() {
|
||||
@@ -493,9 +501,10 @@ function SessionModal({
|
||||
if (sessionId && speakerEmails.length > 0) {
|
||||
await setSessionSpeakers(sessionId, speakerEmails);
|
||||
}
|
||||
// Material upload (if a new file was chosen).
|
||||
// Material upload (if a new file was chosen). Passes the old path so a
|
||||
// replacement removes the previous object instead of orphaning it.
|
||||
if (sessionId && material) {
|
||||
await uploadSessionMaterial(sessionId, material);
|
||||
await uploadSessionMaterial(sessionId, material, session?.material_path);
|
||||
}
|
||||
onSaved(session ? 'Session updated' : 'Session created');
|
||||
} catch (e) {
|
||||
@@ -569,37 +578,64 @@ function SessionModal({
|
||||
</div>
|
||||
|
||||
{session && (
|
||||
<div className="field">
|
||||
<div className="field" data-testid="session-material">
|
||||
<label>Material</label>
|
||||
{session.material_path ? (
|
||||
<div className="row" style={{ gap: 10 }}>
|
||||
<button
|
||||
className="btn small"
|
||||
disabled={busy}
|
||||
onClick={async () => {
|
||||
try {
|
||||
await openSessionMaterial(session.material_path!);
|
||||
} catch (e) {
|
||||
onSaved(e instanceof Error ? e.message : 'Could not open material');
|
||||
}
|
||||
}}
|
||||
>
|
||||
📎 View current
|
||||
</button>
|
||||
<button
|
||||
className="btn small danger"
|
||||
disabled={busy}
|
||||
onClick={async () => {
|
||||
try {
|
||||
await removeSessionMaterial(session.id);
|
||||
onSaved('Material removed');
|
||||
} catch (e) {
|
||||
onSaved(e instanceof Error ? e.message : 'Remove failed');
|
||||
}
|
||||
}}
|
||||
>
|
||||
Remove
|
||||
</button>
|
||||
<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>
|
||||
@@ -609,7 +645,19 @@ function SessionModal({
|
||||
type="file"
|
||||
onChange={(e) => setMaterial(e.target.files?.[0] ?? null)}
|
||||
/>
|
||||
{material && <span className="muted small">Will upload: {material.name}</span>}
|
||||
{material && (
|
||||
<span className="muted small">
|
||||
{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>
|
||||
)}
|
||||
|
||||
|
||||
Reference in new issue
Block a user