Compare commits

..

4 Commits

Author SHA1 Message Date
Levente Orban
1b79e6da58 fix: validating capacity limit when users add guests 2025-11-03 09:04:01 +01:00
Levente Orban
8cde1d44eb fix: error when editing the events, location_type 2025-10-29 10:15:12 +01:00
Levente Orban
7692f9d503 fix: error when editing the events, location_type 2025-10-28 19:16:36 +01:00
Levente Orban
baf3fcd923 fix: transparent modal & typo on footer userId text 2025-10-28 18:01:06 +01:00
4 changed files with 27 additions and 17 deletions

View File

@@ -104,14 +104,15 @@ export const actions: Actions = {
// Get current RSVPs
const currentRSVPs = await database.select().from(rsvps).where(eq(rsvps.eventId, eventId));
// Calculate total attendees (including guests)
const totalAttendees = currentRSVPs.length + numberOfGuests;
// Calculate remaining spots and ensure main attendee + guests fit
const newAttendeesCount = 1 + numberOfGuests;
const remainingSpots = (eventData.attendeeLimit ?? 0) - currentRSVPs.length;
// Check if event is full (for limited type events)
if (eventData.type === 'limited' && eventData.attendeeLimit) {
if (totalAttendees > eventData.attendeeLimit) {
if (newAttendeesCount > remainingSpots) {
return fail(400, {
error: `Event capacity exceeded. You're trying to add ${numberOfGuests + 1} attendees (including yourself), but only ${eventData.attendeeLimit - currentRSVPs.length} spots remain.`
error: `Event capacity exceeded. You're trying to add ${newAttendeesCount} attendee${newAttendeesCount === 1 ? '' : 's'} (including yourself), but only ${remainingSpots} spot${remainingSpots === 1 ? '' : 's'} remain.`
});
}
}

View File

@@ -76,7 +76,7 @@ export const actions: Actions = {
const date = formData.get('date') as string;
const time = formData.get('time') as string;
const location = formData.get('location') as string;
const locationType = formData.get('location_type') as 'none' | 'text' | 'maps';
const locationType = formData.get('locationType') as string;
const locationUrl = formData.get('location_url') as string;
const type = formData.get('type') as 'limited' | 'unlimited';
const attendeeLimit = formData.get('attendee_limit') as string;
@@ -109,7 +109,7 @@ export const actions: Actions = {
});
}
// Check if date is in the past using local timezone (but allow editing past events for corrections)
// Check if date is in the past using local timezone
const [year, month, day] = date.split('-').map(Number);
const eventDate = new Date(year, month - 1, day);
const today = new Date();
@@ -148,7 +148,6 @@ export const actions: Actions = {
}
});
}
// Update the event
await database
.update(events)
@@ -157,7 +156,7 @@ export const actions: Actions = {
date: date,
time: time,
location: location?.trim() || '',
locationType: locationType,
locationType: locationType as 'none' | 'text' | 'maps',
locationUrl: locationType === 'maps' ? locationUrl?.trim() : null,
type: type,
attendeeLimit: type === 'limited' ? parseInt(attendeeLimit) : null,

View File

@@ -1,5 +1,5 @@
<script lang="ts">
import type { EventType, LocationType } from '$lib/types';
import type { CreateEventData, EventType, LocationType } from '$lib/types';
import { enhance } from '$app/forms';
import { goto } from '$app/navigation';
import { t } from '$lib/i18n/i18n.js';
@@ -7,7 +7,7 @@
export let data;
export let form;
let eventData = {
let eventData: CreateEventData = {
name: data.event.name,
date: data.event.date,
time: data.event.time,
@@ -15,7 +15,7 @@
location_type: data.event.locationType || 'none',
location_url: data.event.locationUrl || '',
type: data.event.type,
attendee_limit: data.event.attendeeLimit,
attendee_limit: data.event.attendeeLimit || undefined,
visibility: data.event.visibility
};
@@ -44,14 +44,14 @@
attendee_limit: (values as any).attendee_limit
? // eslint-disable-next-line @typescript-eslint/no-explicit-any
parseInt(String((values as any).attendee_limit))
: null
: undefined
};
}
const handleTypeChange = (type: EventType) => {
eventData.type = type;
if (type === 'unlimited') {
eventData.attendee_limit = null;
eventData.attendee_limit = undefined;
}
};
@@ -189,6 +189,9 @@
<!-- Location Type -->
<div>
<!-- Hidden input to submit locationType value -->
<input type="hidden" name="locationType" bind:value={eventData.location_type} />
<fieldset>
<legend class="text-dark-800 mb-3 block text-sm font-semibold">
{t('create.locationTypeLabel')}
@@ -279,6 +282,9 @@
<!-- Event Type -->
<div>
<!-- Hidden input to submit type value -->
<input type="hidden" name="type" bind:value={eventData.type} />
<fieldset>
<legend class="text-dark-800 mb-3 block text-sm font-semibold">
{t('common.type')} <span class="text-red-400">{t('common.required')}</span>
@@ -333,6 +339,9 @@
<!-- Event Visibility -->
<div>
<!-- Hidden input to submit visibility value -->
<input type="hidden" name="visibility" bind:value={eventData.visibility} />
<fieldset>
<legend class="text-dark-800 mb-3 block text-sm font-semibold">
{t('common.visibility')} <span class="text-red-400">{t('common.required')}</span>

View File

@@ -129,14 +129,15 @@ export const actions: Actions = {
// Get current RSVPs
const currentRSVPs = await database.select().from(rsvps).where(eq(rsvps.eventId, eventId));
// Calculate total attendees (including guests)
const totalAttendees = currentRSVPs.length + numberOfGuests;
// Calculate remaining spots and ensure main attendee + guests fit
const newAttendeesCount = 1 + numberOfGuests;
const remainingSpots = (eventData.attendeeLimit ?? 0) - currentRSVPs.length;
// Check if event is full (for limited type events)
if (eventData.type === 'limited' && eventData.attendeeLimit) {
if (totalAttendees > eventData.attendeeLimit) {
if (newAttendeesCount > remainingSpots) {
return fail(400, {
error: `Event capacity exceeded. You're trying to add ${numberOfGuests + 1} attendees (including yourself), but only ${eventData.attendeeLimit - currentRSVPs.length} spots remain.`
error: `Event capacity exceeded. You're trying to add ${newAttendeesCount} attendee${newAttendeesCount === 1 ? '' : 's'} (including yourself), but only ${remainingSpots} spot${remainingSpots === 1 ? '' : 's'} remain.`
});
}
}