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 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | 2x 2x 2x | /**
* VenueCateringContactsTab
*
* Singleton config edited in Administration: the one venue contact, the one
* catering contact, and the organizer who acts as venue coordinator (reply-to
* on every venue-coordination email sent from the Event Detail Venue tab).
*
* Persisted as a single JSON blob under app_settings key
* `venue.coordination.config` via the existing key/value AdminSettings API —
* no new backend endpoint required.
*/
import React, { useEffect, useState } from 'react';
import {
Alert,
Box,
Button,
CircularProgress,
Divider,
Snackbar,
Stack,
TextField,
Typography,
} from '@mui/material';
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import { useTranslation } from 'react-i18next';
import { getAdminSetting, updateAdminSetting } from '@/services/adminSettingsService';
import { OrganizerSelect } from '@/components/shared/OrganizerSelect';
export const VENUE_COORDINATION_CONFIG_KEY = 'venue.coordination.config';
export interface VenueContact {
salutation: string;
name: string;
email: string;
}
export interface VenueCoordinationConfig {
venue: VenueContact;
catering: VenueContact;
coordinatorUsername: string;
}
const EMPTY_CONFIG: VenueCoordinationConfig = {
venue: { salutation: '', name: '', email: '' },
catering: { salutation: '', name: '', email: '' },
coordinatorUsername: '',
};
function parseConfig(raw: string | null | undefined): VenueCoordinationConfig {
if (!raw) return EMPTY_CONFIG;
try {
const parsed = JSON.parse(raw) as Partial<VenueCoordinationConfig>;
return {
venue: { ...EMPTY_CONFIG.venue, ...(parsed.venue ?? {}) },
catering: { ...EMPTY_CONFIG.catering, ...(parsed.catering ?? {}) },
coordinatorUsername: parsed.coordinatorUsername ?? '',
};
} catch {
return EMPTY_CONFIG;
}
}
export const VenueCateringContactsTab: React.FC = () => {
const { t } = useTranslation('admin');
const queryClient = useQueryClient();
const { data: setting, isLoading } = useQuery({
queryKey: ['admin-settings', VENUE_COORDINATION_CONFIG_KEY],
queryFn: () => getAdminSetting(VENUE_COORDINATION_CONFIG_KEY),
});
const [config, setConfig] = useState<VenueCoordinationConfig>(EMPTY_CONFIG);
const [snackbarOpen, setSnackbarOpen] = useState(false);
const [snackbarError, setSnackbarError] = useState(false);
useEffect(() => {
if (setting) {
setConfig(parseConfig(setting.value));
}
}, [setting]);
const mutation = useMutation({
mutationFn: () => updateAdminSetting(VENUE_COORDINATION_CONFIG_KEY, JSON.stringify(config)),
onSuccess: () => {
void queryClient.invalidateQueries({
queryKey: ['admin-settings', VENUE_COORDINATION_CONFIG_KEY],
});
setSnackbarError(false);
setSnackbarOpen(true);
},
onError: () => {
setSnackbarError(true);
setSnackbarOpen(true);
},
});
const updateContact = (role: 'venue' | 'catering', field: keyof VenueContact, value: string) => {
setConfig((prev) => ({ ...prev, [role]: { ...prev[role], [field]: value } }));
};
if (isLoading) {
return (
<Box sx={{ display: 'flex', justifyContent: 'center', mt: 4 }}>
<CircularProgress />
</Box>
);
}
return (
<Box sx={{ maxWidth: 760 }} data-testid="venue-catering-contacts-tab">
<Typography variant="h6" gutterBottom>
{t('settings.venueCoordination.title', 'Venue & Catering Contacts')}
</Typography>
<Typography variant="body2" color="text.secondary" sx={{ mb: 3 }}>
{t(
'settings.venueCoordination.subtitle',
'These contacts receive the offerte and timetable emails sent from the Event Detail Venue tab. They are the same across every event — define them once here.'
)}
</Typography>
<Typography variant="subtitle1" sx={{ mb: 1, fontWeight: 600 }}>
{t('settings.venueCoordination.venueSection', 'Venue contact')}
</Typography>
<Stack direction={{ xs: 'column', sm: 'row' }} spacing={2} sx={{ mb: 3 }}>
<TextField
label={t('settings.venueCoordination.salutation', 'Salutation')}
placeholder="Frau"
value={config.venue.salutation}
onChange={(e) => updateContact('venue', 'salutation', e.target.value)}
sx={{ minWidth: 120 }}
/>
<TextField
label={t('settings.venueCoordination.name', 'Name')}
placeholder="Gabriela Senn"
value={config.venue.name}
onChange={(e) => updateContact('venue', 'name', e.target.value)}
fullWidth
/>
<TextField
label={t('settings.venueCoordination.email', 'Email')}
placeholder="contact@venue.example"
type="email"
value={config.venue.email}
onChange={(e) => updateContact('venue', 'email', e.target.value)}
fullWidth
/>
</Stack>
<Divider sx={{ mb: 3 }} />
<Typography variant="subtitle1" sx={{ mb: 1, fontWeight: 600 }}>
{t('settings.venueCoordination.cateringSection', 'Catering contact')}
</Typography>
<Stack direction={{ xs: 'column', sm: 'row' }} spacing={2} sx={{ mb: 3 }}>
<TextField
label={t('settings.venueCoordination.salutation', 'Salutation')}
placeholder="Herr"
value={config.catering.salutation}
onChange={(e) => updateContact('catering', 'salutation', e.target.value)}
sx={{ minWidth: 120 }}
/>
<TextField
label={t('settings.venueCoordination.name', 'Name')}
placeholder="Stefan Oppliger"
value={config.catering.name}
onChange={(e) => updateContact('catering', 'name', e.target.value)}
fullWidth
/>
<TextField
label={t('settings.venueCoordination.email', 'Email')}
placeholder="contact@catering.example"
type="email"
value={config.catering.email}
onChange={(e) => updateContact('catering', 'email', e.target.value)}
fullWidth
/>
</Stack>
<Divider sx={{ mb: 3 }} />
<Typography variant="subtitle1" sx={{ mb: 1, fontWeight: 600 }}>
{t('settings.venueCoordination.coordinatorSection', 'Venue coordinator')}
</Typography>
<Alert severity="info" sx={{ mb: 2 }}>
{t(
'settings.venueCoordination.coordinatorHelp',
'The organizer username (e.g. nissim.buchs) whose email address will appear as Reply-To on every venue/catering message. Replies from the recipient go straight to them.'
)}
</Alert>
<OrganizerSelect
value={config.coordinatorUsername}
onChange={(username) => setConfig((prev) => ({ ...prev, coordinatorUsername: username }))}
label={t('settings.venueCoordination.coordinatorUsername', 'Coordinator')}
includeUnassigned={false}
size="medium"
fullWidth
sx={{ mb: 3 }}
data-testid="venue-coord-coordinator-select"
/>
<Box>
<Button
variant="contained"
onClick={() => {
mutation.mutate();
}}
disabled={mutation.isPending}
startIcon={
mutation.isPending ? <CircularProgress size={16} color="inherit" /> : undefined
}
>
{t('settings.save', 'Save')}
</Button>
</Box>
<Snackbar
open={snackbarOpen}
autoHideDuration={4000}
onClose={() => setSnackbarOpen(false)}
anchorOrigin={{ vertical: 'bottom', horizontal: 'center' }}
>
<Alert
severity={snackbarError ? 'error' : 'success'}
onClose={() => setSnackbarOpen(false)}
>
{snackbarError
? t('settings.saveFailed', 'Save failed. Please try again.')
: t('settings.saved', 'Settings saved.')}
</Alert>
</Snackbar>
</Box>
);
};
|