Add compact control room photo grid
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import React from 'react';
|
||||
import { useLocation, useNavigate, useParams } from 'react-router-dom';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Image as ImageIcon, RefreshCcw, Settings } from 'lucide-react';
|
||||
import { Check, Eye, EyeOff, Image as ImageIcon, RefreshCcw, Settings, Sparkles } from 'lucide-react';
|
||||
import { YStack, XStack } from '@tamagui/stacks';
|
||||
import { SizableText as Text } from '@tamagui/text';
|
||||
import { Pressable } from '@tamagui/react-native-web-lite';
|
||||
import { MobileShell, HeaderActionButton } from './components/MobileShell';
|
||||
import { MobileCard, CTAButton, PillBadge, SkeletonCard } from './components/Primitives';
|
||||
import { MobileCard, CTAButton, SkeletonCard } from './components/Primitives';
|
||||
import { MobileField, MobileSelect } from './components/FormControls';
|
||||
import { useEventContext } from '../context/EventContext';
|
||||
import {
|
||||
@@ -37,6 +37,7 @@ import { useBackNavigation } from './hooks/useBackNavigation';
|
||||
import { useAdminTheme } from './theme';
|
||||
import { useOnlineStatus } from './hooks/useOnlineStatus';
|
||||
import { useAuth } from '../auth/context';
|
||||
import { withAlpha } from './components/colors';
|
||||
import {
|
||||
enqueuePhotoAction,
|
||||
loadPhotoQueue,
|
||||
@@ -45,7 +46,7 @@ import {
|
||||
type PhotoModerationAction,
|
||||
} from './lib/photoModerationQueue';
|
||||
import { triggerHaptic } from './lib/haptics';
|
||||
import { normalizeLiveStatus, resolveLiveShowApproveMode, resolveStatusTone } from './lib/controlRoom';
|
||||
import { normalizeLiveStatus, resolveLiveShowApproveMode } from './lib/controlRoom';
|
||||
import { LegalConsentSheet } from './components/LegalConsentSheet';
|
||||
import { selectAddonKeyForScope } from './addons';
|
||||
import { LimitWarnings } from './components/LimitWarnings';
|
||||
@@ -86,6 +87,167 @@ function translateLimits(t: (key: string, defaultValue?: string, options?: Recor
|
||||
return (key, options) => t(`limits.${key}`, defaults[key] ?? key, options);
|
||||
}
|
||||
|
||||
type PhotoGridAction = {
|
||||
key: string;
|
||||
label: string;
|
||||
icon: React.ComponentType<{ size?: number; color?: string }>;
|
||||
onPress: () => void;
|
||||
disabled?: boolean;
|
||||
};
|
||||
|
||||
function PhotoGrid({
|
||||
photos,
|
||||
actionsForPhoto,
|
||||
badgesForPhoto,
|
||||
isBusy,
|
||||
}: {
|
||||
photos: TenantPhoto[];
|
||||
actionsForPhoto: (photo: TenantPhoto) => PhotoGridAction[];
|
||||
badgesForPhoto?: (photo: TenantPhoto) => string[];
|
||||
isBusy?: (photo: TenantPhoto) => boolean;
|
||||
}) {
|
||||
const gridStyle: React.CSSProperties = {
|
||||
display: 'grid',
|
||||
gridTemplateColumns: 'repeat(auto-fill, minmax(120px, 1fr))',
|
||||
gap: 10,
|
||||
};
|
||||
|
||||
return (
|
||||
<div style={gridStyle}>
|
||||
{photos.map((photo) => (
|
||||
<PhotoGridTile
|
||||
key={photo.id}
|
||||
photo={photo}
|
||||
actions={actionsForPhoto(photo)}
|
||||
badges={badgesForPhoto ? badgesForPhoto(photo) : []}
|
||||
isBusy={isBusy ? isBusy(photo) : false}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function PhotoGridTile({
|
||||
photo,
|
||||
actions,
|
||||
badges,
|
||||
isBusy,
|
||||
}: {
|
||||
photo: TenantPhoto;
|
||||
actions: PhotoGridAction[];
|
||||
badges: string[];
|
||||
isBusy: boolean;
|
||||
}) {
|
||||
const { border, muted, surfaceMuted } = useAdminTheme();
|
||||
const overlayBg = withAlpha('#0f172a', 0.65);
|
||||
const actionBg = withAlpha('#ffffff', 0.14);
|
||||
|
||||
return (
|
||||
<div
|
||||
style={{
|
||||
position: 'relative',
|
||||
borderRadius: 16,
|
||||
overflow: 'hidden',
|
||||
border: `1px solid ${border}`,
|
||||
aspectRatio: '1 / 1',
|
||||
backgroundColor: surfaceMuted,
|
||||
opacity: isBusy ? 0.7 : 1,
|
||||
}}
|
||||
>
|
||||
{photo.thumbnail_url ? (
|
||||
<img
|
||||
src={photo.thumbnail_url}
|
||||
alt={photo.original_name ?? 'Photo'}
|
||||
loading="lazy"
|
||||
decoding="async"
|
||||
style={{ width: '100%', height: '100%', objectFit: 'cover' }}
|
||||
/>
|
||||
) : (
|
||||
<XStack alignItems="center" justifyContent="center" height="100%" backgroundColor={surfaceMuted}>
|
||||
<ImageIcon size={22} color={muted} />
|
||||
</XStack>
|
||||
)}
|
||||
|
||||
{badges.length ? (
|
||||
<XStack position="absolute" top={6} left={6} space="$1.5">
|
||||
{badges.map((label) => (
|
||||
<PhotoStatusTag key={`${photo.id}-${label}`} label={label} />
|
||||
))}
|
||||
</XStack>
|
||||
) : null}
|
||||
|
||||
<XStack
|
||||
position="absolute"
|
||||
left={6}
|
||||
right={6}
|
||||
bottom={6}
|
||||
padding="$1"
|
||||
borderRadius={12}
|
||||
backgroundColor={overlayBg}
|
||||
space="$1.5"
|
||||
>
|
||||
{actions.map((action) => (
|
||||
<PhotoActionButton
|
||||
key={action.key}
|
||||
label={action.label}
|
||||
icon={action.icon}
|
||||
onPress={action.onPress}
|
||||
disabled={action.disabled}
|
||||
backgroundColor={actionBg}
|
||||
/>
|
||||
))}
|
||||
</XStack>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function PhotoActionButton({
|
||||
label,
|
||||
icon: Icon,
|
||||
onPress,
|
||||
disabled = false,
|
||||
backgroundColor,
|
||||
}: {
|
||||
label: string;
|
||||
icon: React.ComponentType<{ size?: number; color?: string }>;
|
||||
onPress: () => void;
|
||||
disabled?: boolean;
|
||||
backgroundColor: string;
|
||||
}) {
|
||||
return (
|
||||
<Pressable
|
||||
onPress={disabled ? undefined : onPress}
|
||||
disabled={disabled}
|
||||
style={{ flex: 1, opacity: disabled ? 0.55 : 1 }}
|
||||
>
|
||||
<YStack
|
||||
alignItems="center"
|
||||
justifyContent="center"
|
||||
paddingVertical={6}
|
||||
paddingHorizontal={4}
|
||||
borderRadius={10}
|
||||
minHeight={36}
|
||||
style={{ backgroundColor }}
|
||||
>
|
||||
<Icon size={14} color="#fff" />
|
||||
<Text fontSize={9} fontWeight="700" color="#fff" textAlign="center">
|
||||
{label}
|
||||
</Text>
|
||||
</YStack>
|
||||
</Pressable>
|
||||
);
|
||||
}
|
||||
|
||||
function PhotoStatusTag({ label }: { label: string }) {
|
||||
return (
|
||||
<XStack paddingHorizontal={6} paddingVertical={2} borderRadius={999} backgroundColor={withAlpha('#0f172a', 0.7)}>
|
||||
<Text fontSize={9} fontWeight="700" color="#fff">
|
||||
{label}
|
||||
</Text>
|
||||
</XStack>
|
||||
);
|
||||
}
|
||||
|
||||
export default function MobileEventControlRoomPage() {
|
||||
const { slug: slugParam } = useParams<{ slug?: string }>();
|
||||
const navigate = useNavigate();
|
||||
@@ -288,9 +450,13 @@ export default function MobileEventControlRoomPage() {
|
||||
setQueuedActions(queue);
|
||||
}, []);
|
||||
|
||||
const updatePhotoInCollections = React.useCallback((updated: TenantPhoto) => {
|
||||
setModerationPhotos((prev) => prev.map((photo) => (photo.id === updated.id ? updated : photo)));
|
||||
setLivePhotos((prev) => prev.map((photo) => (photo.id === updated.id ? updated : photo)));
|
||||
}, []);
|
||||
|
||||
const applyOptimisticUpdate = React.useCallback((photoId: number, action: PhotoModerationAction['action']) => {
|
||||
setModerationPhotos((prev) =>
|
||||
prev.map((photo) => {
|
||||
const applyUpdate = (photo: TenantPhoto) => {
|
||||
if (photo.id !== photoId) {
|
||||
return photo;
|
||||
}
|
||||
@@ -307,9 +473,19 @@ export default function MobileEventControlRoomPage() {
|
||||
return { ...photo, status: 'approved' };
|
||||
}
|
||||
|
||||
if (action === 'feature') {
|
||||
return { ...photo, is_featured: true };
|
||||
}
|
||||
|
||||
if (action === 'unfeature') {
|
||||
return { ...photo, is_featured: false };
|
||||
}
|
||||
|
||||
return photo;
|
||||
}),
|
||||
);
|
||||
};
|
||||
|
||||
setModerationPhotos((prev) => prev.map(applyUpdate));
|
||||
setLivePhotos((prev) => prev.map(applyUpdate));
|
||||
}, []);
|
||||
|
||||
const enqueueModerationAction = React.useCallback(
|
||||
@@ -359,7 +535,7 @@ export default function MobileEventControlRoomPage() {
|
||||
remaining = removePhotoAction(remaining, entry.id);
|
||||
|
||||
if (updated && entry.eventSlug === slug) {
|
||||
setModerationPhotos((prev) => prev.map((photo) => (photo.id === updated!.id ? updated! : photo)));
|
||||
updatePhotoInCollections(updated);
|
||||
}
|
||||
} catch (err) {
|
||||
toast.error(t('mobilePhotos.syncFailed', 'Sync failed. Please try again later.'));
|
||||
@@ -372,7 +548,7 @@ export default function MobileEventControlRoomPage() {
|
||||
updateQueueState(remaining);
|
||||
setSyncingQueue(false);
|
||||
syncingQueueRef.current = false;
|
||||
}, [online, slug, t, updateQueueState]);
|
||||
}, [online, slug, t, updatePhotoInCollections, updateQueueState]);
|
||||
|
||||
React.useEffect(() => {
|
||||
if (online) {
|
||||
@@ -399,15 +575,25 @@ export default function MobileEventControlRoomPage() {
|
||||
updated = await updatePhotoStatus(slug, photo.id, 'approved');
|
||||
} else if (action === 'hide') {
|
||||
updated = await updatePhotoVisibility(slug, photo.id, true);
|
||||
} else {
|
||||
} else if (action === 'show') {
|
||||
updated = await updatePhotoVisibility(slug, photo.id, false);
|
||||
} else if (action === 'feature') {
|
||||
updated = await featurePhoto(slug, photo.id);
|
||||
} else {
|
||||
updated = await unfeaturePhoto(slug, photo.id);
|
||||
}
|
||||
|
||||
setModerationPhotos((prev) => prev.map((item) => (item.id === photo.id ? updated : item)));
|
||||
triggerHaptic(action === 'approve' ? 'success' : 'medium');
|
||||
updatePhotoInCollections(updated);
|
||||
triggerHaptic(action === 'approve' || action === 'feature' ? 'success' : 'medium');
|
||||
} catch (err) {
|
||||
if (!isAuthError(err)) {
|
||||
const message = getApiErrorMessage(err, t('mobilePhotos.visibilityFailed', 'Visibility could not be changed.'));
|
||||
const fallbackMessage =
|
||||
action === 'approve'
|
||||
? t('mobilePhotos.approveFailed', 'Approval failed.')
|
||||
: action === 'feature' || action === 'unfeature'
|
||||
? t('mobilePhotos.featureFailed', 'Highlight could not be changed.')
|
||||
: t('mobilePhotos.visibilityFailed', 'Visibility could not be changed.');
|
||||
const message = getApiErrorMessage(err, fallbackMessage);
|
||||
setModerationError(message);
|
||||
toast.error(message);
|
||||
}
|
||||
@@ -415,7 +601,7 @@ export default function MobileEventControlRoomPage() {
|
||||
setModerationBusyId(null);
|
||||
}
|
||||
},
|
||||
[enqueueModerationAction, online, slug, t],
|
||||
[enqueueModerationAction, online, slug, t, updatePhotoInCollections],
|
||||
);
|
||||
|
||||
function resolveScopeAndAddonKey(scopeOrKey: 'photos' | 'gallery' | 'guests' | string) {
|
||||
@@ -691,67 +877,57 @@ export default function MobileEventControlRoomPage() {
|
||||
</Text>
|
||||
</MobileCard>
|
||||
) : (
|
||||
<YStack space="$2">
|
||||
{moderationPhotos.map((photo) => {
|
||||
<PhotoGrid
|
||||
photos={moderationPhotos}
|
||||
isBusy={(photo) => moderationBusyId === photo.id}
|
||||
badgesForPhoto={(photo) => {
|
||||
const badges: string[] = [];
|
||||
if (photo.status === 'hidden') {
|
||||
badges.push(t('photos.filters.hidden', 'Hidden'));
|
||||
}
|
||||
if (photo.is_featured) {
|
||||
badges.push(t('photos.filters.featured', 'Highlights'));
|
||||
}
|
||||
return badges;
|
||||
}}
|
||||
actionsForPhoto={(photo) => {
|
||||
const isBusy = moderationBusyId === photo.id;
|
||||
const galleryStatus = photo.status ?? 'pending';
|
||||
const liveStatus = normalizeLiveStatus(photo.live_status);
|
||||
const canApprove = galleryStatus === 'pending';
|
||||
const canShow = galleryStatus === 'hidden';
|
||||
const visibilityAction: PhotoModerationAction['action'] = canShow ? 'show' : 'hide';
|
||||
const visibilityLabel = canShow
|
||||
? t('photos.actions.show', 'Show')
|
||||
: t('photos.actions.hide', 'Hide');
|
||||
return (
|
||||
<MobileCard key={photo.id}>
|
||||
<XStack space="$3" alignItems="center">
|
||||
{photo.thumbnail_url ? (
|
||||
<img
|
||||
src={photo.thumbnail_url}
|
||||
alt={photo.original_name ?? 'Photo'}
|
||||
style={{
|
||||
width: 72,
|
||||
height: 72,
|
||||
borderRadius: 14,
|
||||
objectFit: 'cover',
|
||||
border: `1px solid ${border}`,
|
||||
const featureAction: PhotoModerationAction['action'] = photo.is_featured ? 'unfeature' : 'feature';
|
||||
const featureLabel = photo.is_featured
|
||||
? t('photos.actions.unfeature', 'Remove highlight')
|
||||
: t('photos.actions.feature', 'Set highlight');
|
||||
return [
|
||||
{
|
||||
key: 'approve',
|
||||
label: t('photos.actions.approve', 'Approve'),
|
||||
icon: Check,
|
||||
onPress: () => handleModerationAction('approve', photo),
|
||||
disabled: !canApprove || isBusy,
|
||||
},
|
||||
{
|
||||
key: 'visibility',
|
||||
label: visibilityLabel,
|
||||
icon: canShow ? Eye : EyeOff,
|
||||
onPress: () => handleModerationAction(visibilityAction, photo),
|
||||
disabled: isBusy,
|
||||
},
|
||||
{
|
||||
key: 'feature',
|
||||
label: featureLabel,
|
||||
icon: Sparkles,
|
||||
onPress: () => handleModerationAction(featureAction, photo),
|
||||
disabled: isBusy,
|
||||
},
|
||||
];
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
<YStack flex={1} space="$2">
|
||||
<Text fontSize="$sm" fontWeight="700" color={text}>
|
||||
{photo.original_name ?? t('common.photo', 'Photo')}
|
||||
</Text>
|
||||
<XStack alignItems="center" space="$2">
|
||||
<PillBadge tone={resolveStatusTone(galleryStatus)}>
|
||||
{resolveGalleryLabel(galleryStatus)}
|
||||
</PillBadge>
|
||||
<PillBadge tone={resolveStatusTone(liveStatus)}>
|
||||
{resolveLiveLabel(liveStatus)}
|
||||
</PillBadge>
|
||||
</XStack>
|
||||
</YStack>
|
||||
</XStack>
|
||||
<XStack space="$2" marginTop="$2">
|
||||
<CTAButton
|
||||
label={t('photos.actions.approve', 'Approve')}
|
||||
onPress={() => handleModerationAction('approve', photo)}
|
||||
disabled={!canApprove}
|
||||
loading={isBusy}
|
||||
tone="primary"
|
||||
/>
|
||||
<CTAButton
|
||||
label={visibilityLabel}
|
||||
onPress={() => handleModerationAction(visibilityAction, photo)}
|
||||
disabled={false}
|
||||
loading={isBusy}
|
||||
tone="ghost"
|
||||
/>
|
||||
</XStack>
|
||||
</MobileCard>
|
||||
);
|
||||
})}
|
||||
</YStack>
|
||||
)}
|
||||
|
||||
{moderationHasMore ? (
|
||||
@@ -816,56 +992,43 @@ export default function MobileEventControlRoomPage() {
|
||||
</Text>
|
||||
</MobileCard>
|
||||
) : (
|
||||
<YStack space="$2">
|
||||
{livePhotos.map((photo) => {
|
||||
const isBusy = liveBusyId === photo.id;
|
||||
<PhotoGrid
|
||||
photos={livePhotos}
|
||||
isBusy={(photo) => moderationBusyId === photo.id || liveBusyId === photo.id}
|
||||
badgesForPhoto={(photo) => {
|
||||
const badges: string[] = [];
|
||||
const liveStatus = normalizeLiveStatus(photo.live_status);
|
||||
if (liveStatus !== 'pending') {
|
||||
badges.push(resolveLiveLabel(liveStatus));
|
||||
}
|
||||
if (photo.status === 'hidden') {
|
||||
badges.push(t('photos.filters.hidden', 'Hidden'));
|
||||
}
|
||||
if (photo.is_featured) {
|
||||
badges.push(t('photos.filters.featured', 'Highlights'));
|
||||
}
|
||||
return badges;
|
||||
}}
|
||||
actionsForPhoto={(photo) => {
|
||||
const isLiveBusy = liveBusyId === photo.id;
|
||||
const isModerationBusy = moderationBusyId === photo.id;
|
||||
const liveStatus = normalizeLiveStatus(photo.live_status);
|
||||
const galleryStatus = photo.status ?? 'pending';
|
||||
const approveMode = resolveLiveShowApproveMode(galleryStatus);
|
||||
const canApproveLive = approveMode !== 'not-eligible';
|
||||
const showApproveAction = liveStatus !== 'approved';
|
||||
const approveLabel =
|
||||
approveMode === 'approve-and-live'
|
||||
? t('liveShowQueue.approveAndLive', 'Approve + Live')
|
||||
: approveMode === 'approve-only'
|
||||
? t('liveShowQueue.approve', 'Approve for Live Show')
|
||||
: t('liveShowQueue.notEligible', 'Not eligible');
|
||||
const approveDisabled = !online || !canApproveLive || liveStatus === 'approved' || isLiveBusy;
|
||||
const visibilityLabel = t('photos.actions.hide', 'Hide');
|
||||
const featureAction: PhotoModerationAction['action'] = photo.is_featured ? 'unfeature' : 'feature';
|
||||
const featureLabel = photo.is_featured
|
||||
? t('photos.actions.unfeature', 'Remove highlight')
|
||||
: t('photos.actions.feature', 'Set highlight');
|
||||
|
||||
return (
|
||||
<MobileCard key={photo.id}>
|
||||
<XStack space="$3" alignItems="center">
|
||||
{photo.thumbnail_url ? (
|
||||
<img
|
||||
src={photo.thumbnail_url}
|
||||
alt={photo.original_name ?? 'Photo'}
|
||||
style={{
|
||||
width: 72,
|
||||
height: 72,
|
||||
borderRadius: 14,
|
||||
objectFit: 'cover',
|
||||
border: `1px solid ${border}`,
|
||||
}}
|
||||
/>
|
||||
) : null}
|
||||
<YStack flex={1} space="$2">
|
||||
<Text fontSize="$sm" fontWeight="700" color={text}>
|
||||
{photo.original_name ?? t('common.photo', 'Photo')}
|
||||
</Text>
|
||||
<XStack alignItems="center" space="$2">
|
||||
<PillBadge tone={resolveStatusTone(galleryStatus)}>
|
||||
{resolveGalleryLabel(galleryStatus)}
|
||||
</PillBadge>
|
||||
<PillBadge tone={resolveStatusTone(liveStatus)}>
|
||||
{resolveLiveLabel(liveStatus)}
|
||||
</PillBadge>
|
||||
</XStack>
|
||||
</YStack>
|
||||
</XStack>
|
||||
<XStack space="$2" marginTop="$2">
|
||||
{showApproveAction ? (
|
||||
<CTAButton
|
||||
label={approveLabel}
|
||||
onPress={() => {
|
||||
return [
|
||||
{
|
||||
key: 'approve',
|
||||
label: t('photos.actions.approve', 'Approve'),
|
||||
icon: Check,
|
||||
onPress: () => {
|
||||
if (approveMode === 'approve-and-live') {
|
||||
void handleApproveAndLive(photo);
|
||||
return;
|
||||
@@ -873,42 +1036,32 @@ export default function MobileEventControlRoomPage() {
|
||||
if (approveMode === 'approve-only') {
|
||||
void handleApprove(photo);
|
||||
}
|
||||
},
|
||||
disabled: approveDisabled,
|
||||
},
|
||||
{
|
||||
key: 'visibility',
|
||||
label: visibilityLabel,
|
||||
icon: EyeOff,
|
||||
onPress: () => {
|
||||
if (liveStatus === 'approved' || liveStatus === 'rejected') {
|
||||
void handleClear(photo);
|
||||
return;
|
||||
}
|
||||
void handleReject(photo);
|
||||
},
|
||||
disabled: !online || isLiveBusy || isModerationBusy,
|
||||
},
|
||||
{
|
||||
key: 'feature',
|
||||
label: featureLabel,
|
||||
icon: Sparkles,
|
||||
onPress: () => handleModerationAction(featureAction, photo),
|
||||
disabled: isModerationBusy,
|
||||
},
|
||||
];
|
||||
}}
|
||||
disabled={!online || !canApproveLive}
|
||||
loading={isBusy}
|
||||
tone="primary"
|
||||
/>
|
||||
) : (
|
||||
<CTAButton
|
||||
label={t('liveShowQueue.clear', 'Remove from Live Show')}
|
||||
onPress={() => handleClear(photo)}
|
||||
disabled={!online}
|
||||
loading={isBusy}
|
||||
tone="ghost"
|
||||
/>
|
||||
)}
|
||||
{liveStatus !== 'rejected' ? (
|
||||
<CTAButton
|
||||
label={t('liveShowQueue.reject', 'Reject')}
|
||||
onPress={() => handleReject(photo)}
|
||||
disabled={!online}
|
||||
loading={isBusy}
|
||||
tone="danger"
|
||||
/>
|
||||
) : (
|
||||
<CTAButton
|
||||
label={t('liveShowQueue.clear', 'Remove from Live Show')}
|
||||
onPress={() => handleClear(photo)}
|
||||
disabled={!online}
|
||||
loading={isBusy}
|
||||
tone="ghost"
|
||||
/>
|
||||
)}
|
||||
</XStack>
|
||||
</MobileCard>
|
||||
);
|
||||
})}
|
||||
</YStack>
|
||||
)}
|
||||
|
||||
{liveHasMore ? (
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
import React from 'react';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import { render, screen } from '@testing-library/react';
|
||||
|
||||
const navigateMock = vi.fn();
|
||||
const selectEventMock = vi.fn();
|
||||
|
||||
vi.mock('react-router-dom', () => ({
|
||||
useNavigate: () => navigateMock,
|
||||
useLocation: () => ({ search: '', pathname: '/event-admin/mobile/events/demo-event/control-room' }),
|
||||
useParams: () => ({ slug: 'demo-event' }),
|
||||
}));
|
||||
|
||||
const tMock = (key: string, fallback?: string | Record<string, unknown>, options?: Record<string, unknown>) => {
|
||||
if (typeof fallback === 'string') {
|
||||
return fallback;
|
||||
}
|
||||
if (fallback && typeof fallback === 'object' && typeof fallback.defaultValue === 'string') {
|
||||
return fallback.defaultValue;
|
||||
}
|
||||
if (options?.defaultValue) {
|
||||
return String(options.defaultValue);
|
||||
}
|
||||
return key;
|
||||
};
|
||||
|
||||
vi.mock('react-i18next', () => ({
|
||||
useTranslation: () => ({
|
||||
t: tMock,
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock('../../auth/context', () => ({
|
||||
useAuth: () => ({ user: { role: 'tenant_admin' } }),
|
||||
}));
|
||||
|
||||
vi.mock('../../context/EventContext', () => ({
|
||||
useEventContext: () => ({
|
||||
activeEvent: { slug: 'demo-event' },
|
||||
selectEvent: selectEventMock,
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock('../hooks/useOnlineStatus', () => ({
|
||||
useOnlineStatus: () => true,
|
||||
}));
|
||||
|
||||
vi.mock('../hooks/useBackNavigation', () => ({
|
||||
useBackNavigation: () => undefined,
|
||||
}));
|
||||
|
||||
vi.mock('../components/MobileShell', () => ({
|
||||
MobileShell: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
||||
HeaderActionButton: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
||||
}));
|
||||
|
||||
vi.mock('../components/Primitives', () => ({
|
||||
MobileCard: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
||||
CTAButton: ({ label, onPress }: { label: string; onPress?: () => void }) => (
|
||||
<button type="button" onClick={onPress}>
|
||||
{label}
|
||||
</button>
|
||||
),
|
||||
SkeletonCard: () => <div>Loading...</div>,
|
||||
}));
|
||||
|
||||
vi.mock('../components/FormControls', () => ({
|
||||
MobileField: ({ label, children }: { label: string; children: React.ReactNode }) => (
|
||||
<label>
|
||||
{label}
|
||||
{children}
|
||||
</label>
|
||||
),
|
||||
MobileSelect: (props: React.SelectHTMLAttributes<HTMLSelectElement>) => <select {...props} />,
|
||||
}));
|
||||
|
||||
vi.mock('../components/LegalConsentSheet', () => ({
|
||||
LegalConsentSheet: () => null,
|
||||
}));
|
||||
|
||||
vi.mock('../components/LimitWarnings', () => ({
|
||||
LimitWarnings: () => null,
|
||||
}));
|
||||
|
||||
vi.mock('react-hot-toast', () => ({
|
||||
default: {
|
||||
error: vi.fn(),
|
||||
success: vi.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
vi.mock('@tamagui/stacks', () => ({
|
||||
YStack: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
||||
XStack: ({ children }: { children: React.ReactNode }) => <div>{children}</div>,
|
||||
}));
|
||||
|
||||
vi.mock('@tamagui/text', () => ({
|
||||
SizableText: ({ children }: { children: React.ReactNode }) => <span>{children}</span>,
|
||||
}));
|
||||
|
||||
vi.mock('@tamagui/react-native-web-lite', () => ({
|
||||
Pressable: ({ children, onPress }: { children: React.ReactNode; onPress?: () => void }) => (
|
||||
<button type="button" onClick={onPress}>
|
||||
{children}
|
||||
</button>
|
||||
),
|
||||
}));
|
||||
|
||||
vi.mock('../theme', () => ({
|
||||
useAdminTheme: () => ({
|
||||
textStrong: '#111827',
|
||||
text: '#111827',
|
||||
muted: '#6b7280',
|
||||
border: '#e5e7eb',
|
||||
accentSoft: '#eef2ff',
|
||||
accent: '#6366f1',
|
||||
danger: '#dc2626',
|
||||
surfaceMuted: '#f9fafb',
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock('../lib/photoModerationQueue', () => ({
|
||||
enqueuePhotoAction: vi.fn().mockReturnValue([]),
|
||||
loadPhotoQueue: () => [],
|
||||
removePhotoAction: vi.fn((queue: unknown[]) => queue),
|
||||
replacePhotoQueue: vi.fn((queue: unknown[]) => queue),
|
||||
}));
|
||||
|
||||
vi.mock('../lib/haptics', () => ({
|
||||
triggerHaptic: () => undefined,
|
||||
}));
|
||||
|
||||
vi.mock('../../api', () => ({
|
||||
approveAndLiveShowPhoto: vi.fn(),
|
||||
approveLiveShowPhoto: vi.fn(),
|
||||
clearLiveShowPhoto: vi.fn(),
|
||||
createEventAddonCheckout: vi.fn(),
|
||||
featurePhoto: vi.fn(),
|
||||
getAddonCatalog: vi.fn().mockResolvedValue([]),
|
||||
getEventPhotos: vi.fn().mockResolvedValue({
|
||||
photos: [
|
||||
{
|
||||
id: 1,
|
||||
filename: 'photo.jpg',
|
||||
original_name: 'Photo 1',
|
||||
mime_type: 'image/jpeg',
|
||||
size: 120,
|
||||
url: '/full.jpg',
|
||||
thumbnail_url: '/thumb.jpg',
|
||||
status: 'pending',
|
||||
live_status: null,
|
||||
is_featured: false,
|
||||
likes_count: 0,
|
||||
uploaded_at: '2024-01-01T00:00:00Z',
|
||||
uploader_name: 'Guest',
|
||||
},
|
||||
],
|
||||
limits: null,
|
||||
meta: { last_page: 1 },
|
||||
}),
|
||||
getEvents: vi.fn().mockResolvedValue([]),
|
||||
getLiveShowQueue: vi.fn().mockResolvedValue({ photos: [], meta: { last_page: 1 } }),
|
||||
rejectLiveShowPhoto: vi.fn(),
|
||||
unfeaturePhoto: vi.fn(),
|
||||
updatePhotoStatus: vi.fn(),
|
||||
updatePhotoVisibility: vi.fn(),
|
||||
}));
|
||||
|
||||
import MobileEventControlRoomPage from '../EventControlRoomPage';
|
||||
|
||||
describe('MobileEventControlRoomPage', () => {
|
||||
it('renders compact grid actions for moderation photos', async () => {
|
||||
render(<MobileEventControlRoomPage />);
|
||||
|
||||
expect(await screen.findByText('Approve')).toBeInTheDocument();
|
||||
expect(screen.getByText('Hide')).toBeInTheDocument();
|
||||
expect(screen.getByText('Set highlight')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user