Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | 1x 3x 3x 3x 3x 3x 3x 3x 3x 2x 2x 1x | /**
* EventAppreciationTab (Story 7.7 — Curated Thank-You Notes)
*
* Organizer view of the thank-you notes left for this event (Story 7.4 stored them; this is the
* surface that finally lets organizers READ them). Each logged-in note can be ★-featured for the
* public curated marquee; anonymous notes are shown but cannot be featured (no name).
*/
import {
Alert,
Box,
Chip,
CircularProgress,
Paper,
Stack,
Switch,
Tooltip,
Typography,
} from '@mui/material';
import { Favorite as FavoriteIcon } from '@mui/icons-material';
import { useTranslation } from 'react-i18next';
import { useEventThanks, useSetThanksFeatured } from '@/hooks/useThanks/useThanks';
import { UserAvatar } from '@/components/shared/UserAvatar';
interface EventAppreciationTabProps {
eventCode: string;
}
export const EventAppreciationTab = ({ eventCode }: EventAppreciationTabProps) => {
const { t } = useTranslation('events');
const { data, isLoading, isError } = useEventThanks(eventCode);
const setFeatured = useSetThanksFeatured(eventCode);
Iif (isLoading) {
return (
<Box sx={{ display: 'flex', justifyContent: 'center', py: 6 }}>
<CircularProgress />
</Box>
);
}
Iif (isError) {
return <Alert severity="error">{t('appreciation.loadError')}</Alert>;
}
const notes = data?.notes ?? [];
const count = data?.count ?? 0;
return (
<Box>
<Typography variant="h6" gutterBottom>
{t('appreciation.title')}
</Typography>
<Typography variant="body2" color="text.secondary" sx={{ mb: 2 }}>
{t('appreciation.subtitle', { count })}
</Typography>
{notes.length === 0 ? (
<Alert severity="info" data-testid="appreciation-empty">
{t('appreciation.empty')}
</Alert>
) : (
<Stack spacing={1.5}>
{notes.map((n) => {
const anonymous = !n.thankedByUsername;
return (
<Paper key={n.id} variant="outlined" sx={{ p: 2 }} data-testid="appreciation-note">
<Stack
direction="row"
justifyContent="space-between"
alignItems="flex-start"
spacing={2}
>
<Box sx={{ minWidth: 0 }}>
{n.note ? (
<Typography variant="body1" sx={{ fontStyle: 'italic' }}>
“{n.note}”
</Typography>
) : (
<Typography variant="body2" color="text.secondary">
{t('appreciation.noNote')}
</Typography>
)}
<Stack direction="row" spacing={1} alignItems="center" sx={{ mt: 0.5 }}>
{anonymous ? (
<Chip size="small" label={t('appreciation.anonymous')} variant="outlined" />
) : (
<UserAvatar
firstName={n.thankedByFirstName ?? undefined}
lastName={n.thankedByLastName ?? undefined}
name={
!n.thankedByFirstName && !n.thankedByLastName
? (n.thankedByUsername ?? undefined)
: undefined
}
company={n.thankedByCompanyName ?? undefined}
size={24}
/>
)}
{n.featured && (
<Chip
size="small"
color="success"
icon={<FavoriteIcon fontSize="small" />}
label={t('appreciation.featured')}
/>
)}
</Stack>
</Box>
<Tooltip
title={
anonymous
? t('appreciation.cannotFeatureAnonymous')
: t('appreciation.featureToggle')
}
>
<span>
<Switch
checked={!!n.featured}
disabled={anonymous || setFeatured.isPending}
onChange={(e) =>
setFeatured.mutate({ id: n.id!, featured: e.target.checked })
}
inputProps={{ 'aria-label': t('appreciation.featureToggle') }}
data-testid={`appreciation-feature-toggle-${n.id}`}
/>
</span>
</Tooltip>
</Stack>
</Paper>
);
})}
</Stack>
)}
</Box>
);
};
|