Refactor EventForm into sections and add thank you message field
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
|||||||
styled,
|
styled,
|
||||||
Checkbox,
|
Checkbox,
|
||||||
FormControlLabel,
|
FormControlLabel,
|
||||||
|
Divider, // Added Divider for visual separation
|
||||||
} from '@mui/material';
|
} from '@mui/material';
|
||||||
import WallpaperIcon from '@mui/icons-material/Wallpaper';
|
import WallpaperIcon from '@mui/icons-material/Wallpaper';
|
||||||
import DeleteIcon from '@mui/icons-material/Delete';
|
import DeleteIcon from '@mui/icons-material/Delete';
|
||||||
@@ -48,6 +49,7 @@ interface FormData {
|
|||||||
max_guests_per_rsvp: number;
|
max_guests_per_rsvp: number;
|
||||||
email_notifications_enabled: boolean;
|
email_notifications_enabled: boolean;
|
||||||
email_recipients: string;
|
email_recipients: string;
|
||||||
|
thank_you_message: string; // Added thank you message field
|
||||||
}
|
}
|
||||||
|
|
||||||
const EventForm: React.FC = () => {
|
const EventForm: React.FC = () => {
|
||||||
@@ -62,6 +64,7 @@ const EventForm: React.FC = () => {
|
|||||||
max_guests_per_rsvp: 0,
|
max_guests_per_rsvp: 0,
|
||||||
email_notifications_enabled: false,
|
email_notifications_enabled: false,
|
||||||
email_recipients: '',
|
email_recipients: '',
|
||||||
|
thank_you_message: '', // Added thank you message state
|
||||||
});
|
});
|
||||||
const [wallpaper, setWallpaper] = useState<File | null>(null);
|
const [wallpaper, setWallpaper] = useState<File | null>(null);
|
||||||
const [currentItem, setCurrentItem] = useState('');
|
const [currentItem, setCurrentItem] = useState('');
|
||||||
@@ -123,6 +126,9 @@ const EventForm: React.FC = () => {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Append thank you message
|
||||||
|
submitData.append('thank_you_message', formData.thank_you_message);
|
||||||
|
|
||||||
// Append wallpaper if selected
|
// Append wallpaper if selected
|
||||||
if (wallpaper) {
|
if (wallpaper) {
|
||||||
submitData.append('wallpaper', wallpaper);
|
submitData.append('wallpaper', wallpaper);
|
||||||
@@ -154,196 +160,215 @@ const EventForm: React.FC = () => {
|
|||||||
<Typography variant="h4" component="h2" gutterBottom color="primary" align="center" sx={{ color: '#90caf9' }}>
|
<Typography variant="h4" component="h2" gutterBottom color="primary" align="center" sx={{ color: '#90caf9' }}>
|
||||||
Create New Event
|
Create New Event
|
||||||
</Typography>
|
</Typography>
|
||||||
|
|
||||||
{error && (
|
{error && (
|
||||||
<Typography color="error" align="center" sx={{ mb: 2 }}>
|
<Typography color="error" align="center" sx={{ mb: 2 }}>
|
||||||
{error}
|
{error}
|
||||||
</Typography>
|
</Typography>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Box component="form" onSubmit={handleSubmit} sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}>
|
<Box component="form" onSubmit={handleSubmit} sx={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
|
||||||
<DarkTextField
|
{/* Part 1: Basic Event Details */}
|
||||||
fullWidth
|
<Box>
|
||||||
label="Title"
|
<Typography variant="h6" gutterBottom sx={{ color: 'rgba(255, 255, 255, 0.9)' }}>
|
||||||
name="title"
|
Basic Event Details
|
||||||
value={formData.title}
|
|
||||||
onChange={handleChange}
|
|
||||||
variant="outlined"
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
<DarkTextField
|
|
||||||
fullWidth
|
|
||||||
label="Description"
|
|
||||||
name="description"
|
|
||||||
value={formData.description}
|
|
||||||
onChange={handleChange}
|
|
||||||
variant="outlined"
|
|
||||||
multiline
|
|
||||||
rows={4}
|
|
||||||
/>
|
|
||||||
<DarkTextField
|
|
||||||
fullWidth
|
|
||||||
label="Date and Time"
|
|
||||||
name="date"
|
|
||||||
type="datetime-local"
|
|
||||||
value={formData.date}
|
|
||||||
onChange={handleChange}
|
|
||||||
variant="outlined"
|
|
||||||
required
|
|
||||||
InputLabelProps={{
|
|
||||||
shrink: true,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
<DarkTextField
|
|
||||||
fullWidth
|
|
||||||
label="RSVP Cut-off Date"
|
|
||||||
name="rsvp_cutoff_date"
|
|
||||||
type="datetime-local"
|
|
||||||
value={formData.rsvp_cutoff_date}
|
|
||||||
onChange={handleChange}
|
|
||||||
variant="outlined"
|
|
||||||
InputLabelProps={{
|
|
||||||
shrink: true,
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<DarkTextField
|
|
||||||
fullWidth
|
|
||||||
label="Maximum Additional Guests Per RSVP"
|
|
||||||
name="max_guests_per_rsvp"
|
|
||||||
type="number"
|
|
||||||
value={formData.max_guests_per_rsvp}
|
|
||||||
onChange={(e) => {
|
|
||||||
const value = parseInt(e.target.value);
|
|
||||||
setFormData((prev) => ({
|
|
||||||
...prev,
|
|
||||||
max_guests_per_rsvp: isNaN(value) ? 0 : value,
|
|
||||||
}));
|
|
||||||
}}
|
|
||||||
variant="outlined"
|
|
||||||
helperText="Set to 0 for no additional guests, -1 for unlimited"
|
|
||||||
inputProps={{ min: -1 }}
|
|
||||||
/>
|
|
||||||
<DarkTextField
|
|
||||||
fullWidth
|
|
||||||
label="Location"
|
|
||||||
name="location"
|
|
||||||
value={formData.location}
|
|
||||||
onChange={handleChange}
|
|
||||||
variant="outlined"
|
|
||||||
required
|
|
||||||
/>
|
|
||||||
|
|
||||||
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 1 }}>
|
|
||||||
<Typography variant="subtitle1" gutterBottom sx={{ color: 'rgba(255, 255, 255, 0.7)' }}>
|
|
||||||
Event Wallpaper
|
|
||||||
</Typography>
|
</Typography>
|
||||||
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2 }}>
|
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}>
|
||||||
<Button
|
|
||||||
variant="outlined"
|
|
||||||
component="span"
|
|
||||||
startIcon={<WallpaperIcon />}
|
|
||||||
onClick={handleWallpaperClick}
|
|
||||||
sx={{
|
|
||||||
flexGrow: 1,
|
|
||||||
borderColor: '#64b5f6',
|
|
||||||
color: '#64b5f6',
|
|
||||||
'&:hover': {
|
|
||||||
borderColor: '#90caf9',
|
|
||||||
backgroundColor: 'rgba(100, 181, 246, 0.08)',
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
{wallpaper ? 'Change Wallpaper' : 'Upload Wallpaper'}
|
|
||||||
</Button>
|
|
||||||
{wallpaper && (
|
|
||||||
<IconButton
|
|
||||||
color="error"
|
|
||||||
onClick={() => setWallpaper(null)}
|
|
||||||
size="small"
|
|
||||||
sx={{
|
|
||||||
color: '#f44336',
|
|
||||||
'&:hover': {
|
|
||||||
backgroundColor: 'rgba(244, 67, 54, 0.08)',
|
|
||||||
}
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<DeleteIcon />
|
|
||||||
</IconButton>
|
|
||||||
)}
|
|
||||||
</Box>
|
|
||||||
{wallpaper && (
|
|
||||||
<Typography variant="body2" sx={{ color: 'rgba(255, 255, 255, 0.6)', mt: 1 }}>
|
|
||||||
Selected: {wallpaper.name}
|
|
||||||
</Typography>
|
|
||||||
)}
|
|
||||||
<input
|
|
||||||
type="file"
|
|
||||||
ref={fileInputRef}
|
|
||||||
onChange={handleWallpaperChange}
|
|
||||||
accept="image/jpeg,image/png,image/gif"
|
|
||||||
style={{ display: 'none' }}
|
|
||||||
/>
|
|
||||||
</Box>
|
|
||||||
|
|
||||||
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}>
|
|
||||||
<Typography variant="subtitle1" sx={{ color: 'rgba(255, 255, 255, 0.7)' }}>
|
|
||||||
Needed Items
|
|
||||||
</Typography>
|
|
||||||
<Box sx={{ display: 'flex', gap: 1 }}>
|
|
||||||
<DarkTextField
|
<DarkTextField
|
||||||
fullWidth
|
fullWidth
|
||||||
label="Add Item"
|
label="Title"
|
||||||
value={currentItem}
|
name="title"
|
||||||
onChange={handleItemChange}
|
value={formData.title}
|
||||||
|
onChange={handleChange}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
size="small"
|
required
|
||||||
/>
|
/>
|
||||||
<Button
|
<DarkTextField
|
||||||
variant="contained"
|
fullWidth
|
||||||
onClick={handleAddItem}
|
label="Description"
|
||||||
disabled={!currentItem.trim()}
|
name="description"
|
||||||
startIcon={<AddIcon />}
|
value={formData.description}
|
||||||
sx={{
|
onChange={handleChange}
|
||||||
bgcolor: '#90caf9',
|
variant="outlined"
|
||||||
'&:hover': {
|
multiline
|
||||||
bgcolor: '#42a5f5',
|
rows={4}
|
||||||
},
|
/>
|
||||||
'&.Mui-disabled': {
|
<DarkTextField
|
||||||
bgcolor: 'rgba(144, 202, 249, 0.3)',
|
fullWidth
|
||||||
}
|
label="Location"
|
||||||
|
name="location"
|
||||||
|
value={formData.location}
|
||||||
|
onChange={handleChange}
|
||||||
|
variant="outlined"
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
<DarkTextField
|
||||||
|
fullWidth
|
||||||
|
label="Date and Time"
|
||||||
|
name="date"
|
||||||
|
type="datetime-local"
|
||||||
|
value={formData.date}
|
||||||
|
onChange={handleChange}
|
||||||
|
variant="outlined"
|
||||||
|
required
|
||||||
|
InputLabelProps={{
|
||||||
|
shrink: true,
|
||||||
}}
|
}}
|
||||||
>
|
/>
|
||||||
Add
|
<DarkTextField
|
||||||
</Button>
|
fullWidth
|
||||||
</Box>
|
label="RSVP Cut-off Date"
|
||||||
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 1 }}>
|
name="rsvp_cutoff_date"
|
||||||
{formData.needed_items.map((item, index) => (
|
type="datetime-local"
|
||||||
<Chip
|
value={formData.rsvp_cutoff_date}
|
||||||
key={index}
|
onChange={handleChange}
|
||||||
label={item}
|
variant="outlined"
|
||||||
onDelete={() => handleRemoveItem(index)}
|
InputLabelProps={{
|
||||||
sx={{
|
shrink: true,
|
||||||
bgcolor: 'rgba(144, 202, 249, 0.2)',
|
}}
|
||||||
color: 'rgba(255, 255, 255, 0.9)',
|
/>
|
||||||
'& .MuiChip-deleteIcon': {
|
<DarkTextField
|
||||||
color: 'rgba(255, 255, 255, 0.7)',
|
fullWidth
|
||||||
'&:hover': {
|
label="Maximum Additional Guests Per RSVP"
|
||||||
color: 'rgba(255, 255, 255, 0.9)',
|
name="max_guests_per_rsvp"
|
||||||
}
|
type="number"
|
||||||
}
|
value={formData.max_guests_per_rsvp}
|
||||||
}}
|
onChange={(e) => {
|
||||||
/>
|
const value = parseInt(e.target.value);
|
||||||
))}
|
setFormData((prev) => ({
|
||||||
|
...prev,
|
||||||
|
max_guests_per_rsvp: isNaN(value) ? 0 : value,
|
||||||
|
}));
|
||||||
|
}}
|
||||||
|
variant="outlined"
|
||||||
|
helperText="Set to 0 for no additional guests, -1 for unlimited"
|
||||||
|
inputProps={{ min: -1 }}
|
||||||
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<Box sx={{ mt: 4, mb: 3, borderTop: '1px solid rgba(255, 255, 255, 0.12)', pt: 3 }}>
|
<Divider sx={{ borderColor: 'rgba(255, 255, 255, 0.12)' }} />
|
||||||
<Typography variant="h6" sx={{ mb: 2, color: 'rgba(255, 255, 255, 0.9)' }}>
|
|
||||||
Email Notifications
|
{/* Part 2: Customization */}
|
||||||
|
<Box>
|
||||||
|
<Typography variant="h6" gutterBottom sx={{ color: 'rgba(255, 255, 255, 0.9)' }}>
|
||||||
|
Customization
|
||||||
</Typography>
|
</Typography>
|
||||||
|
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}>
|
||||||
<Box sx={{ display: 'flex', alignItems: 'center' }}>
|
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 1 }}>
|
||||||
|
<Typography variant="subtitle1" gutterBottom sx={{ color: 'rgba(255, 255, 255, 0.7)' }}>
|
||||||
|
Event Wallpaper
|
||||||
|
</Typography>
|
||||||
|
<Box sx={{ display: 'flex', alignItems: 'center', gap: 2 }}>
|
||||||
|
<Button
|
||||||
|
variant="outlined"
|
||||||
|
component="span"
|
||||||
|
startIcon={<WallpaperIcon />}
|
||||||
|
onClick={handleWallpaperClick}
|
||||||
|
sx={{
|
||||||
|
flexGrow: 1,
|
||||||
|
borderColor: '#64b5f6',
|
||||||
|
color: '#64b5f6',
|
||||||
|
'&:hover': {
|
||||||
|
borderColor: '#90caf9',
|
||||||
|
backgroundColor: 'rgba(100, 181, 246, 0.08)',
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
{wallpaper ? 'Change Wallpaper' : 'Upload Wallpaper'}
|
||||||
|
</Button>
|
||||||
|
{wallpaper && (
|
||||||
|
<IconButton
|
||||||
|
color="error"
|
||||||
|
onClick={() => setWallpaper(null)}
|
||||||
|
size="small"
|
||||||
|
sx={{
|
||||||
|
color: '#f44336',
|
||||||
|
'&:hover': {
|
||||||
|
backgroundColor: 'rgba(244, 67, 54, 0.08)',
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<DeleteIcon />
|
||||||
|
</IconButton>
|
||||||
|
)}
|
||||||
|
</Box>
|
||||||
|
{wallpaper && (
|
||||||
|
<Typography variant="body2" sx={{ color: 'rgba(255, 255, 255, 0.6)', mt: 1 }}>
|
||||||
|
Selected: {wallpaper.name}
|
||||||
|
</Typography>
|
||||||
|
)}
|
||||||
|
<input
|
||||||
|
type="file"
|
||||||
|
ref={fileInputRef}
|
||||||
|
onChange={handleWallpaperChange}
|
||||||
|
accept="image/jpeg,image/png,image/gif"
|
||||||
|
style={{ display: 'none' }}
|
||||||
|
/>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}>
|
||||||
|
<Typography variant="subtitle1" sx={{ color: 'rgba(255, 255, 255, 0.7)' }}>
|
||||||
|
Needed Items
|
||||||
|
</Typography>
|
||||||
|
<Box sx={{ display: 'flex', gap: 1 }}>
|
||||||
|
<DarkTextField
|
||||||
|
fullWidth
|
||||||
|
label="Add Item"
|
||||||
|
value={currentItem}
|
||||||
|
onChange={handleItemChange}
|
||||||
|
variant="outlined"
|
||||||
|
size="small"
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
variant="contained"
|
||||||
|
onClick={handleAddItem}
|
||||||
|
disabled={!currentItem.trim()}
|
||||||
|
startIcon={<AddIcon />}
|
||||||
|
sx={{
|
||||||
|
bgcolor: '#90caf9',
|
||||||
|
'&:hover': {
|
||||||
|
bgcolor: '#42a5f5',
|
||||||
|
},
|
||||||
|
'&.Mui-disabled': {
|
||||||
|
bgcolor: 'rgba(144, 202, 249, 0.3)',
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
Add
|
||||||
|
</Button>
|
||||||
|
</Box>
|
||||||
|
<Box sx={{ display: 'flex', flexWrap: 'wrap', gap: 1 }}>
|
||||||
|
{formData.needed_items.map((item, index) => (
|
||||||
|
<Chip
|
||||||
|
key={index}
|
||||||
|
label={item}
|
||||||
|
onDelete={() => handleRemoveItem(index)}
|
||||||
|
sx={{
|
||||||
|
bgcolor: 'rgba(144, 202, 249, 0.2)',
|
||||||
|
color: 'rgba(255, 255, 255, 0.9)',
|
||||||
|
'& .MuiChip-deleteIcon': {
|
||||||
|
color: 'rgba(255, 255, 255, 0.7)',
|
||||||
|
'&:hover': {
|
||||||
|
color: 'rgba(255, 255, 255, 0.9)',
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
</Box>
|
||||||
|
|
||||||
|
<Divider sx={{ borderColor: 'rgba(255, 255, 255, 0.12)' }} />
|
||||||
|
|
||||||
|
{/* Part 3: Notifications and Messaging */}
|
||||||
|
<Box>
|
||||||
|
<Typography variant="h6" gutterBottom sx={{ color: 'rgba(255, 255, 255, 0.9)' }}>
|
||||||
|
Notifications and Messaging
|
||||||
|
</Typography>
|
||||||
|
<Box sx={{ display: 'flex', flexDirection: 'column', gap: 2 }}>
|
||||||
<FormControlLabel
|
<FormControlLabel
|
||||||
control={
|
control={
|
||||||
<Checkbox
|
<Checkbox
|
||||||
@@ -367,21 +392,32 @@ const EventForm: React.FC = () => {
|
|||||||
color: 'rgba(255, 255, 255, 0.9)',
|
color: 'rgba(255, 255, 255, 0.9)',
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Box>
|
|
||||||
|
{formData.email_notifications_enabled && (
|
||||||
{formData.email_notifications_enabled && (
|
<DarkTextField
|
||||||
|
fullWidth
|
||||||
|
label="Email Recipients (comma separated)"
|
||||||
|
name="email_recipients"
|
||||||
|
value={formData.email_recipients}
|
||||||
|
onChange={handleChange}
|
||||||
|
variant="outlined"
|
||||||
|
placeholder="email1@example.com, email2@example.com"
|
||||||
|
helperText="Enter email addresses separated by commas"
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
|
||||||
<DarkTextField
|
<DarkTextField
|
||||||
fullWidth
|
fullWidth
|
||||||
label="Email Recipients (comma separated)"
|
label="Thank You Message (for email notifications)"
|
||||||
name="email_recipients"
|
name="thank_you_message"
|
||||||
value={formData.email_recipients}
|
value={formData.thank_you_message}
|
||||||
onChange={handleChange}
|
onChange={handleChange}
|
||||||
variant="outlined"
|
variant="outlined"
|
||||||
placeholder="email1@example.com, email2@example.com"
|
multiline
|
||||||
helperText="Enter email addresses separated by commas"
|
rows={4}
|
||||||
sx={{ mt: 2 }}
|
helperText="This message will be sent to attendees who opted for email notifications the day after the event."
|
||||||
/>
|
/>
|
||||||
)}
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<Button
|
<Button
|
||||||
@@ -389,7 +425,7 @@ const EventForm: React.FC = () => {
|
|||||||
variant="contained"
|
variant="contained"
|
||||||
color="primary"
|
color="primary"
|
||||||
size="large"
|
size="large"
|
||||||
sx={{
|
sx={{
|
||||||
mt: 2,
|
mt: 2,
|
||||||
bgcolor: '#90caf9',
|
bgcolor: '#90caf9',
|
||||||
'&:hover': {
|
'&:hover': {
|
||||||
|
|||||||
Reference in New Issue
Block a user