Add guest Live Show opt-in toggle
This commit is contained in:
@@ -6,6 +6,7 @@ use App\Enums\GuestNotificationAudience;
|
||||
use App\Enums\GuestNotificationDeliveryStatus;
|
||||
use App\Enums\GuestNotificationState;
|
||||
use App\Enums\GuestNotificationType;
|
||||
use App\Enums\PhotoLiveStatus;
|
||||
use App\Events\GuestPhotoUploaded;
|
||||
use App\Jobs\ProcessPhotoSecurityScan;
|
||||
use App\Models\Event;
|
||||
@@ -1899,6 +1900,8 @@ class EventPublicController extends BaseController
|
||||
$branding = $this->buildGalleryBranding($event);
|
||||
$settings = $this->normalizeSettings($event->settings ?? []);
|
||||
$engagementMode = $settings['engagement_mode'] ?? 'tasks';
|
||||
$liveShowSettings = Arr::get($settings, 'live_show', []);
|
||||
$liveShowSettings = is_array($liveShowSettings) ? $liveShowSettings : [];
|
||||
$event->loadMissing('photoboothSetting');
|
||||
$policy = $this->guestPolicy();
|
||||
|
||||
@@ -1921,6 +1924,9 @@ class EventPublicController extends BaseController
|
||||
'photobooth_enabled' => (bool) ($event->photoboothSetting?->enabled),
|
||||
'branding' => $branding,
|
||||
'guest_upload_visibility' => Arr::get($event->settings ?? [], 'guest_upload_visibility', $policy->guest_upload_visibility),
|
||||
'live_show' => [
|
||||
'moderation_mode' => $liveShowSettings['moderation_mode'] ?? 'manual',
|
||||
],
|
||||
'engagement_mode' => $engagementMode,
|
||||
])->header('Cache-Control', 'no-store');
|
||||
}
|
||||
@@ -2987,6 +2993,7 @@ class EventPublicController extends BaseController
|
||||
'emotion_slug' => ['nullable', 'string'],
|
||||
'task_id' => ['nullable', 'integer'],
|
||||
'guest_name' => ['nullable', 'string', 'max:255'],
|
||||
'live_show_opt_in' => ['nullable', 'boolean'],
|
||||
]);
|
||||
|
||||
$file = $validated['photo'];
|
||||
@@ -3022,6 +3029,26 @@ class EventPublicController extends BaseController
|
||||
$url = $this->resolveDiskUrl($disk, $watermarkedPath);
|
||||
$thumbUrl = $this->resolveDiskUrl($disk, $watermarkedThumb);
|
||||
|
||||
$liveShowSettings = Arr::get($eventModel->settings ?? [], 'live_show', []);
|
||||
$liveShowSettings = is_array($liveShowSettings) ? $liveShowSettings : [];
|
||||
$liveModerationMode = $liveShowSettings['moderation_mode'] ?? 'manual';
|
||||
$liveOptIn = $request->boolean('live_show_opt_in');
|
||||
$liveSubmittedAt = null;
|
||||
$liveApprovedAt = null;
|
||||
$liveReviewedAt = null;
|
||||
$liveStatus = PhotoLiveStatus::NONE->value;
|
||||
|
||||
if ($liveOptIn) {
|
||||
$liveSubmittedAt = now();
|
||||
if ($liveModerationMode === 'off') {
|
||||
$liveStatus = PhotoLiveStatus::APPROVED->value;
|
||||
$liveApprovedAt = $liveSubmittedAt;
|
||||
$liveReviewedAt = $liveSubmittedAt;
|
||||
} else {
|
||||
$liveStatus = PhotoLiveStatus::PENDING->value;
|
||||
}
|
||||
}
|
||||
|
||||
$photoId = DB::table('photos')->insertGetId([
|
||||
'event_id' => $eventId,
|
||||
'tenant_id' => $tenantModel->id,
|
||||
@@ -3033,6 +3060,12 @@ class EventPublicController extends BaseController
|
||||
'likes_count' => 0,
|
||||
'ingest_source' => Photo::SOURCE_GUEST_PWA,
|
||||
'status' => $autoApproveUploads ? 'approved' : 'pending',
|
||||
'live_status' => $liveStatus,
|
||||
'live_submitted_at' => $liveSubmittedAt,
|
||||
'live_approved_at' => $liveApprovedAt,
|
||||
'live_reviewed_at' => $liveReviewedAt,
|
||||
'live_reviewed_by' => null,
|
||||
'live_rejection_reason' => null,
|
||||
|
||||
// Handle emotion_id: prefer explicit ID, fallback to slug lookup, then default
|
||||
'emotion_id' => $this->resolveEmotionId($validated, $eventId),
|
||||
|
||||
@@ -522,6 +522,13 @@ export const messages: Record<LocaleCode, NestedMessages> = {
|
||||
keep: 'Foto verwenden',
|
||||
readyAnnouncement: 'Foto aufgenommen. Bitte Vorschau prüfen.',
|
||||
},
|
||||
liveShow: {
|
||||
title: 'Live-Show',
|
||||
description: 'Zeige dieses Foto direkt auf der Live-Show.',
|
||||
toggle: 'Live-Show aktivieren',
|
||||
immediate: 'Erscheint sofort auf der Leinwand.',
|
||||
reviewed: 'Wird nach Freigabe für die Live-Show angezeigt.',
|
||||
},
|
||||
status: {
|
||||
saving: 'Speichere Foto...',
|
||||
processing: 'Verarbeite Foto...',
|
||||
@@ -1220,6 +1227,13 @@ export const messages: Record<LocaleCode, NestedMessages> = {
|
||||
keep: 'Use this photo',
|
||||
readyAnnouncement: 'Photo captured. Please review the preview.',
|
||||
},
|
||||
liveShow: {
|
||||
title: 'Live Show',
|
||||
description: 'Show this photo on the live screen.',
|
||||
toggle: 'Enable Live Show',
|
||||
immediate: 'Shows immediately on the big screen.',
|
||||
reviewed: 'Shown after approval for the Live Show.',
|
||||
},
|
||||
status: {
|
||||
saving: 'Saving photo...',
|
||||
processing: 'Processing photo...',
|
||||
|
||||
@@ -4,6 +4,7 @@ import { useNavigate, useParams, useSearchParams } from 'react-router-dom';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Alert, AlertDescription } from '@/components/ui/alert';
|
||||
import { Switch } from '@/components/ui/switch';
|
||||
import { motion } from 'framer-motion';
|
||||
import {
|
||||
Dialog,
|
||||
@@ -149,6 +150,7 @@ export default function UploadPage() {
|
||||
const uploadsRequireApproval =
|
||||
(event?.guest_upload_visibility as 'immediate' | 'review' | undefined) !== 'immediate';
|
||||
const demoReadOnly = Boolean(event?.demo_read_only);
|
||||
const liveShowModeration = event?.live_show?.moderation_mode ?? 'manual';
|
||||
const motionEnabled = !prefersReducedMotion();
|
||||
const overlayMotion = motionEnabled ? { initial: 'hidden', animate: 'show', variants: FADE_SCALE } : {};
|
||||
const fadeUpMotion = motionEnabled ? { initial: 'hidden', animate: 'show', variants: FADE_UP } : {};
|
||||
@@ -187,6 +189,7 @@ const navSentinelRef = useRef<HTMLDivElement | null>(null);
|
||||
|
||||
const [eventPackage, setEventPackage] = useState<EventPackage | null>(null);
|
||||
const [canUpload, setCanUpload] = useState(true);
|
||||
const [submitToLive, setSubmitToLive] = useState(true);
|
||||
|
||||
const limitCards = useMemo<LimitSummaryCard[]>(
|
||||
() => buildLimitSummaries(eventPackage?.limits ?? null, t),
|
||||
@@ -227,6 +230,11 @@ const [canUpload, setCanUpload] = useState(true);
|
||||
};
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!event) return;
|
||||
setSubmitToLive(true);
|
||||
}, [event?.slug]);
|
||||
|
||||
const updateNavVisibility = useCallback(() => {
|
||||
if (typeof document === 'undefined') {
|
||||
return;
|
||||
@@ -776,6 +784,7 @@ const [canUpload, setCanUpload] = useState(true);
|
||||
const photoId = await uploadPhoto(eventKey, fileForUpload, task?.id, emotionSlug || undefined, {
|
||||
maxRetries: 2,
|
||||
guestName: identity.name || undefined,
|
||||
liveShowOptIn: submitToLive,
|
||||
onProgress: (percent) => {
|
||||
setUploadProgress(Math.max(15, Math.min(98, percent)));
|
||||
setStatusMessage(t('upload.status.uploading'));
|
||||
@@ -840,7 +849,7 @@ const [canUpload, setCanUpload] = useState(true);
|
||||
} finally {
|
||||
setStatusMessage('');
|
||||
}
|
||||
}, [emotionSlug, markCompleted, navigateAfterUpload, reviewPhoto, eventKey, stopStream, task, canUpload, t, identity.name, triggerConfetti]);
|
||||
}, [emotionSlug, markCompleted, navigateAfterUpload, reviewPhoto, eventKey, stopStream, task, canUpload, t, identity.name, triggerConfetti, submitToLive]);
|
||||
|
||||
const handleGalleryPick = useCallback(async (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
if (!canUpload) return;
|
||||
@@ -1446,6 +1455,26 @@ const renderWithDialog = (content: ReactNode, wrapperClassName = 'space-y-6 pb-[
|
||||
<p className="text-xs">{t('upload.review.noticeBody', 'Dein Foto erscheint, sobald es freigegeben wurde.')}</p>
|
||||
</div>
|
||||
) : null}
|
||||
<div className="rounded-xl border border-white/20 bg-white/10 p-3 text-white shadow-sm backdrop-blur">
|
||||
<div className="flex items-start justify-between gap-3">
|
||||
<div>
|
||||
<p className="text-sm font-semibold">{t('upload.liveShow.title', 'Live-Show')}</p>
|
||||
<p className="text-xs text-white/70">
|
||||
{t('upload.liveShow.description', 'Zeige dieses Foto direkt auf der Live-Show.')}
|
||||
</p>
|
||||
</div>
|
||||
<Switch
|
||||
checked={submitToLive}
|
||||
onCheckedChange={(checked) => setSubmitToLive(checked)}
|
||||
aria-label={t('upload.liveShow.toggle', 'Live-Show aktivieren')}
|
||||
/>
|
||||
</div>
|
||||
<p className="mt-2 text-[11px] text-white/70">
|
||||
{liveShowModeration === 'off'
|
||||
? t('upload.liveShow.immediate', 'Erscheint sofort auf der Leinwand.')
|
||||
: t('upload.liveShow.reviewed', 'Wird nach Freigabe für die Live-Show angezeigt.')}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex flex-col gap-3 sm:flex-row">
|
||||
<Button variant="secondary" className="flex-1" onClick={handleRetake}>
|
||||
{t('upload.review.retake')}
|
||||
|
||||
@@ -12,6 +12,7 @@ export type QueueItem = {
|
||||
blob: Blob;
|
||||
emotion_id?: number | null;
|
||||
task_id?: number | null;
|
||||
live_show_opt_in?: boolean | null;
|
||||
status: 'pending' | 'uploading' | 'done' | 'error';
|
||||
retries: number;
|
||||
nextAttemptAt?: number | null;
|
||||
|
||||
@@ -14,6 +14,9 @@ export async function createUpload(
|
||||
form.append('photo', it.blob, it.fileName);
|
||||
if (it.emotion_id) form.append('emotion_id', String(it.emotion_id));
|
||||
if (it.task_id) form.append('task_id', String(it.task_id));
|
||||
if (typeof it.live_show_opt_in === 'boolean') {
|
||||
form.append('live_show_opt_in', it.live_show_opt_in ? '1' : '0');
|
||||
}
|
||||
xhr.upload.onprogress = (ev) => {
|
||||
if (onProgress && ev.lengthComputable) {
|
||||
const pct = Math.min(100, Math.round((ev.loaded / ev.total) * 100));
|
||||
|
||||
@@ -67,6 +67,9 @@ export interface EventData {
|
||||
};
|
||||
branding?: EventBrandingPayload | null;
|
||||
guest_upload_visibility?: 'immediate' | 'review';
|
||||
live_show?: {
|
||||
moderation_mode?: 'off' | 'manual' | 'trusted_only';
|
||||
};
|
||||
}
|
||||
|
||||
export interface PackageData {
|
||||
@@ -262,6 +265,7 @@ export async function fetchEvent(eventKey: string): Promise<EventData> {
|
||||
|
||||
const json = await res.json();
|
||||
|
||||
const moderationMode = json?.live_show?.moderation_mode;
|
||||
const normalized: EventData = {
|
||||
...json,
|
||||
name: coerceLocalized(json?.name, 'Fotospiel Event'),
|
||||
@@ -271,6 +275,11 @@ export async function fetchEvent(eventKey: string): Promise<EventData> {
|
||||
engagement_mode: (json?.engagement_mode as 'tasks' | 'photo_only' | undefined) ?? 'tasks',
|
||||
guest_upload_visibility:
|
||||
json?.guest_upload_visibility === 'immediate' ? 'immediate' : 'review',
|
||||
live_show: {
|
||||
moderation_mode: moderationMode === 'off' || moderationMode === 'manual' || moderationMode === 'trusted_only'
|
||||
? moderationMode
|
||||
: 'manual',
|
||||
},
|
||||
demo_read_only: Boolean(json?.demo_read_only),
|
||||
};
|
||||
|
||||
|
||||
@@ -100,6 +100,7 @@ type UploadOptions = {
|
||||
signal?: AbortSignal;
|
||||
maxRetries?: number;
|
||||
onRetry?: (attempt: number) => void;
|
||||
liveShowOptIn?: boolean;
|
||||
};
|
||||
|
||||
export async function uploadPhoto(
|
||||
@@ -114,6 +115,9 @@ export async function uploadPhoto(
|
||||
if (taskId) formData.append('task_id', taskId.toString());
|
||||
if (emotionSlug) formData.append('emotion_slug', emotionSlug);
|
||||
if (options.guestName) formData.append('guest_name', options.guestName);
|
||||
if (typeof options.liveShowOptIn === 'boolean') {
|
||||
formData.append('live_show_opt_in', options.liveShowOptIn ? '1' : '0');
|
||||
}
|
||||
formData.append('device_id', getDeviceId());
|
||||
|
||||
const maxRetries = options.maxRetries ?? 2;
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Enums\PhotoLiveStatus;
|
||||
use App\Models\Event;
|
||||
use App\Models\EventPackage;
|
||||
use App\Models\GuestPolicySetting;
|
||||
@@ -98,6 +99,7 @@ class GuestJoinTokenFlowTest extends TestCase
|
||||
$response = $this->withHeader('X-Device-Id', 'token-device')
|
||||
->postJson("/api/v1/events/{$token->token}/upload", [
|
||||
'photo' => $file,
|
||||
'live_show_opt_in' => true,
|
||||
]);
|
||||
|
||||
$response->assertCreated()
|
||||
@@ -108,6 +110,8 @@ class GuestJoinTokenFlowTest extends TestCase
|
||||
$saved = Photo::first();
|
||||
$this->assertNotNull($saved);
|
||||
$this->assertEquals($event->id, $saved->event_id);
|
||||
$this->assertSame(PhotoLiveStatus::PENDING, $saved->live_status);
|
||||
$this->assertNotNull($saved->live_submitted_at);
|
||||
|
||||
$storedPath = $saved->file_path
|
||||
? ltrim(str_replace('/storage/', '', $saved->file_path), '/')
|
||||
@@ -134,6 +138,24 @@ class GuestJoinTokenFlowTest extends TestCase
|
||||
->assertJsonPath('demo_read_only', true);
|
||||
}
|
||||
|
||||
public function test_guest_event_response_includes_live_show_settings(): void
|
||||
{
|
||||
$event = $this->createPublishedEvent();
|
||||
$event->update([
|
||||
'settings' => [
|
||||
'live_show' => [
|
||||
'moderation_mode' => 'manual',
|
||||
],
|
||||
],
|
||||
]);
|
||||
$token = $this->tokenService->createToken($event);
|
||||
|
||||
$response = $this->getJson("/api/v1/events/{$token->token}");
|
||||
|
||||
$response->assertOk()
|
||||
->assertJsonPath('live_show.moderation_mode', 'manual');
|
||||
}
|
||||
|
||||
public function test_guest_cannot_upload_photo_with_demo_token(): void
|
||||
{
|
||||
Storage::fake('public');
|
||||
|
||||
Reference in New Issue
Block a user