🔥 Remove unused tests, update factories, and introduce recurrence features

- **Removed:** Unused feature and component tests to clean up the codebase.
- **Added:** `RecurrenceType` enum for handling event recurrence modes.
- **Introduced:** City, Country, and Meetup factories for test data generation.
- **Implemented:** Migration to support recurring event fields in `meetup_events` table.
- **Enhanced:** Livewire meetup events creation with recurrence validation and preview logic.
- **Updated:** PHPUnit test suite configuration and composer dependencies for `pestphp/pest@v4.3`.
- **Refined:** SEO configuration (`favicon`) to standardize icon format.
This commit is contained in:
HolgerHatGarKeineNode
2026-01-17 21:00:46 +01:00
parent 74263a4581
commit 7f92e77684
28 changed files with 632 additions and 473 deletions

View File

@@ -1,6 +1,7 @@
<?php
use App\Attributes\SeoDataAttribute;
use App\Enums\RecurrenceType;
use App\Models\Meetup;
use App\Models\MeetupEvent;
use App\Traits\SeoTrait;
@@ -20,9 +21,15 @@ class extends Component {
public string $startDate = '';
public string $startTime = '';
// Explicitly track timezone for reactivity
public string $userTimezone = '';
public bool $seriesMode = false;
public string $endDate = '';
public string $interval = 'monthly';
public ?RecurrenceType $recurrenceType = null;
public ?string $recurrenceDayOfWeek = null;
public ?string $recurrenceDayPosition = null;
public function getPreviewDatesProperty(): array
{
@@ -31,12 +38,44 @@ class extends Component {
}
try {
$timezone = auth()->user()->timezone ?? 'Europe/Berlin';
// Ensure timezone is always set - use fallback if not initialized yet
$timezone = $this->userTimezone ?: (auth()->user()->timezone ?? 'Europe/Berlin');
$startDate = \Carbon\Carbon::createFromFormat('Y-m-d H:i', $this->startDate . ' ' . $this->startTime, $timezone);
$endDate = \Carbon\Carbon::createFromFormat('Y-m-d', $this->endDate, $timezone);
$dates = [];
// Use custom recurrence when dayOfWeek and dayPosition are set (e.g., "last Friday of month")
if ($this->recurrenceDayOfWeek && $this->recurrenceDayPosition) {
return $this->generateCustomRecurrenceDates($startDate, $endDate, $timezone, true);
}
// For weekly recurrence with a specific day of week (no position),
// shift start date to the next occurrence of that weekday
if ($this->recurrenceType === RecurrenceType::Weekly && $this->recurrenceDayOfWeek) {
$dayOfWeekNumber = $this->getDayOfWeekNumber($this->recurrenceDayOfWeek);
if ($dayOfWeekNumber !== null) {
$adjustedStartDate = $startDate->copy();
// Find the next occurrence of the specified weekday
while ($adjustedStartDate->dayOfWeek !== $dayOfWeekNumber) {
$adjustedStartDate->addDay();
}
// Generate weekly dates from the adjusted start
$dates = [];
$currentDate = $adjustedStartDate->copy();
while ($currentDate->lessThanOrEqualTo($endDate) && count($dates) < 100) {
$dates[] = [
'date' => $currentDate->copy(),
'formatted' => $currentDate->translatedFormat('l, d.m.Y'),
'time' => $currentDate->format('H:i'),
];
$currentDate->addWeek();
}
return $dates;
}
}
// Default: generate dates based on recurrence type
$currentDate = $startDate->copy();
$dates = [];
while ($currentDate->lessThanOrEqualTo($endDate) && count($dates) < 100) {
$dates[] = [
@@ -45,7 +84,7 @@ class extends Component {
'time' => $currentDate->format('H:i'),
];
if ($this->interval === 'weekly') {
if ($this->recurrenceType === RecurrenceType::Weekly) {
$currentDate->addWeek();
} else {
$currentDate->addMonth();
@@ -58,6 +97,138 @@ class extends Component {
}
}
private function generateCustomRecurrenceDates(\Carbon\Carbon $startDate, \Carbon\Carbon $endDate, string $timezone, bool $formatted = false): array
{
$dates = [];
// Start from the beginning of the month containing startDate
$currentDate = $startDate->copy()->startOfMonth();
// Preserve the time from startDate for the occurrences
$time = $startDate->format('H:i:s');
while ($currentDate->lessThanOrEqualTo($endDate) && count($dates) < 100) {
$occurrenceDate = $this->findNextOccurrence($currentDate, $timezone);
if ($occurrenceDate && $occurrenceDate->lessThanOrEqualTo($endDate)) {
// Set the time from startDate, preserving the date
$occurrenceWithTime = $occurrenceDate->copy()->setTimeFrom($startDate);
// Only add if this is after or on the start date
if ($occurrenceWithTime->gte($startDate)) {
if ($formatted) {
$dates[] = [
'date' => $occurrenceWithTime,
'formatted' => $occurrenceWithTime->translatedFormat('l, d.m.Y'),
'time' => $time,
];
} else {
$dates[] = $occurrenceWithTime;
}
}
// Move to the next month
$currentDate = $currentDate->copy()->addMonth();
} else {
break;
}
}
return $dates;
}
private function findNextOccurrence(\Carbon\Carbon $currentDate, string $timezone): ?\Carbon\Carbon
{
if (!$this->recurrenceDayOfWeek || !$this->recurrenceDayPosition) {
return $currentDate;
}
$dayOfWeek = $this->getDayOfWeekNumber($this->recurrenceDayOfWeek);
$dayPosition = $this->getDayPositionNumber($this->recurrenceDayPosition);
if ($dayOfWeek === null || $dayPosition === null) {
return $currentDate;
}
// Find the Nth dayOfWeek in the current month
$date = $currentDate->copy()->startOfMonth();
if ($dayPosition === -1) {
return $date->lastOfMonth($dayOfWeek)->setTime($currentDate->hour, $currentDate->minute, $currentDate->second);
}
$count = 0;
while ($date->month === $currentDate->month) {
if ($date->dayOfWeek === $dayOfWeek) {
$count++;
if ($count === $dayPosition) {
return $date->copy()->setTime($currentDate->hour, $currentDate->minute, $currentDate->second);
}
}
$date->addDay();
}
// If we didn't find enough occurrences in this month, return null
return null;
}
private function getDayOfWeekNumber(string $day): ?int
{
return match (strtolower($day)) {
'monday', 'montag' => \Carbon\Carbon::MONDAY,
'tuesday', 'dienstag' => \Carbon\Carbon::TUESDAY,
'wednesday', 'mittwoch' => \Carbon\Carbon::WEDNESDAY,
'thursday', 'donnerstag' => \Carbon\Carbon::THURSDAY,
'friday', 'freitag' => \Carbon\Carbon::FRIDAY,
'saturday', 'samstag' => \Carbon\Carbon::SATURDAY,
'sunday', 'sonntag' => \Carbon\Carbon::SUNDAY,
default => null,
};
}
private function getDayPositionNumber(string $position): ?int
{
return match (strtolower($position)) {
'first', 'erster' => 1,
'second', 'zweiter' => 2,
'third', 'dritter' => 3,
'fourth', 'vierter' => 4,
'last', 'letzter' => -1,
default => null,
};
}
public function getRecurrenceTypesProperty(): array
{
return [
RecurrenceType::Weekly,
RecurrenceType::Monthly,
];
}
public function getDaysOfWeekProperty(): array
{
return [
'monday' => __('Montag'),
'tuesday' => __('Dienstag'),
'wednesday' => __('Mittwoch'),
'thursday' => __('Donnerstag'),
'friday' => __('Freitag'),
'saturday' => __('Samstag'),
'sunday' => __('Sonntag'),
];
}
public function getDayPositionsProperty(): array
{
return [
'first' => __('Erster'),
'second' => __('Zweiter'),
'third' => __('Dritter'),
'fourth' => __('Vierter'),
'last' => __('Letzter'),
];
}
#[Validate('required|string|max:255')]
public ?string $location = null;
@@ -70,7 +241,8 @@ class extends Component {
public function mount(): void
{
$this->country = request()->route('country', config('app.domain_country'));
$timezone = auth()->user()->timezone ?? 'Europe/Berlin';
$this->userTimezone = auth()->user()->timezone ?? 'Europe/Berlin';
$timezone = $this->userTimezone;
if ($this->event) {
$localStart = $this->event->start->setTimezone($timezone);
@@ -79,12 +251,21 @@ class extends Component {
$this->location = $this->event->location;
$this->description = $this->event->description;
$this->link = $this->event->link;
if ($this->event->recurrence_type) {
$this->seriesMode = true;
$this->recurrenceType = $this->event->recurrence_type;
$this->recurrenceDayOfWeek = $this->event->recurrence_day_of_week;
$this->recurrenceDayPosition = $this->event->recurrence_day_position;
$this->endDate = $this->event->recurrence_end_date ? $this->event->recurrence_end_date->format('Y-m-d') : '';
}
} else {
// Set default start time to next Monday at 19:00 in user's timezone
$defaultStart = now($timezone)->next('Monday')->setTime(19, 0);
$this->startDate = $defaultStart->format('Y-m-d');
$this->startTime = $defaultStart->format('H:i');
$this->endDate = $defaultStart->copy()->addMonths(6)->format('Y-m-d');
$this->recurrenceType = RecurrenceType::Weekly;
}
}
@@ -100,12 +281,12 @@ class extends Component {
if ($this->seriesMode) {
$validationRules['endDate'] = 'required|date|after:startDate';
$validationRules['interval'] = 'required|in:weekly,monthly';
$validationRules['recurrenceType'] = 'required';
}
$this->validate($validationRules);
$timezone = auth()->user()->timezone ?? 'Europe/Berlin';
$timezone = $this->userTimezone;
if ($this->seriesMode && !$this->event) {
// Create series of events
@@ -153,11 +334,12 @@ class extends Component {
$startDate = \Carbon\Carbon::createFromFormat('Y-m-d H:i', $this->startDate . ' ' . $this->startTime, $timezone);
$endDate = \Carbon\Carbon::createFromFormat('Y-m-d', $this->endDate, $timezone);
$currentDate = $startDate->copy();
$eventsCreated = 0;
while ($currentDate->lessThanOrEqualTo($endDate)) {
$utcDateTime = $currentDate->copy()->setTimezone('UTC');
$dates = $this->generateEventDates($startDate, $endDate, $timezone);
foreach ($dates as $date) {
$utcDateTime = $date->copy()->setTimezone('UTC');
$this->meetup->meetupEvents()->create([
'start' => $utcDateTime,
@@ -170,16 +352,52 @@ class extends Component {
]);
$eventsCreated++;
}
// Move to next date based on interval
if ($this->interval === 'weekly') {
session()->flash('status', __(':count Events erfolgreich erstellt!', ['count' => $eventsCreated]));
}
private function generateEventDates(\Carbon\Carbon $startDate, \Carbon\Carbon $endDate, string $timezone): array
{
// Use custom recurrence when dayOfWeek and dayPosition are set (e.g., "last Friday of month")
if ($this->recurrenceDayOfWeek && $this->recurrenceDayPosition) {
return $this->generateCustomRecurrenceDates($startDate, $endDate, $timezone);
}
// For weekly recurrence with a specific day of week (no position),
// shift start date to the next occurrence of that weekday
if ($this->recurrenceType === RecurrenceType::Weekly && $this->recurrenceDayOfWeek) {
$dayOfWeekNumber = $this->getDayOfWeekNumber($this->recurrenceDayOfWeek);
if ($dayOfWeekNumber !== null) {
$adjustedStartDate = $startDate->copy();
while ($adjustedStartDate->dayOfWeek !== $dayOfWeekNumber) {
$adjustedStartDate->addDay();
}
$dates = [];
$currentDate = $adjustedStartDate->copy();
while ($currentDate->lessThanOrEqualTo($endDate)) {
$dates[] = $currentDate->copy();
$currentDate->addWeek();
}
return $dates;
}
}
// Default: generate dates based on recurrence type
$dates = [];
$currentDate = $startDate->copy();
while ($currentDate->lessThanOrEqualTo($endDate)) {
$dates[] = $currentDate->copy();
if ($this->recurrenceType === RecurrenceType::Weekly) {
$currentDate->addWeek();
} else {
$currentDate->addMonth();
}
}
session()->flash('status', __(':count Events erfolgreich erstellt!', ['count' => $eventsCreated]));
return $dates;
}
public function delete(): void
@@ -217,15 +435,15 @@ class extends Component {
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<flux:field>
<flux:label>{{ $seriesMode ? __('Startdatum') : __('Datum') }} <span class="text-red-500">*</span></flux:label>
<flux:date-picker min="today" wire:model="startDate" required locale="{{ session('lang_country', 'de-DE') }}"/>
<flux:date-picker :clearable="false" min="today" wire:model.live="startDate" required locale="{{ session('lang_country', 'de-DE') }}"/>
<flux:description>{{ $seriesMode ? __('Datum des ersten Termins') : __('An welchem Tag findet das Event statt?') }}</flux:description>
<flux:error name="startDate"/>
</flux:field>
<flux:field>
<flux:label>{{ __('Uhrzeit') }} <span class="text-red-500">*</span></flux:label>
<flux:time-picker wire:model="startTime" required locale="{{ session('lang_country', 'de-DE') }}"/>
<flux:description>{{ __('Um wie viel Uhr startet das Event?') }} ({{ auth()->user()->timezone ?? 'Europe/Berlin' }})</flux:description>
<flux:time-picker :clearable="false" wire:model="startTime" required locale="{{ session('lang_country', 'de-DE') }}"/>
<flux:description>{{ __('Um wie viel Uhr startet das Event?') }} ({{ $this->userTimezone }})</flux:description>
<flux:error name="startTime"/>
</flux:field>
</div>
@@ -234,21 +452,57 @@ class extends Component {
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<flux:field>
<flux:label>{{ __('Enddatum') }} <span class="text-red-500">*</span></flux:label>
<flux:date-picker min="today" wire:model.live="endDate" required locale="{{ session('lang_country', 'de-DE') }}"/>
<flux:date-picker :clearable="false" min="today" wire:model.live="endDate" required locale="{{ session('lang_country', 'de-DE') }}"/>
<flux:description>{{ __('Datum des letzten Termins') }}</flux:description>
<flux:error name="endDate"/>
</flux:field>
<flux:field>
<flux:label>{{ __('Intervall') }} <span class="text-red-500">*</span></flux:label>
<flux:select wire:model.live="interval" required>
<option value="monthly">{{ __('Monatlich') }}</option>
<option value="weekly">{{ __('Wöchentlich') }}</option>
<flux:label>{{ __('Wiederholungstyp') }} <span class="text-red-500">*</span></flux:label>
<flux:select wire:model.live="recurrenceType" required>
@foreach($this->recurrenceTypes as $type)
<flux:select.option value="{{ $type->value }}">{{ $type->getLabel() }}</flux:select.option>
@endforeach
</flux:select>
<flux:description>{{ __('Wie oft soll das Event wiederholt werden?') }}</flux:description>
<flux:error name="interval"/>
<flux:error name="recurrenceType"/>
</flux:field>
</div>
<div class="grid grid-cols-1 lg:grid-cols-2 gap-6">
<flux:field>
<flux:label>{{ __('Wochentag') }}</flux:label>
<flux:select wire:model.live="recurrenceDayOfWeek">
<flux:select.option value="">{{ __('Automatisch (wie Startdatum)') }}</flux:select.option>
@foreach($this->daysOfWeek as $key => $label)
<flux:select.option value="{{ $key }}">{{ $label }}</flux:select.option>
@endforeach
</flux:select>
<flux:description>{{ __('An welchem Wochentag soll das Event stattfinden?') }}</flux:description>
<flux:error name="recurrenceDayOfWeek"/>
</flux:field>
<flux:field>
<flux:label>{{ __('Position im Monat') }}</flux:label>
<flux:select wire:model.live="recurrenceDayPosition">
<flux:select.option value="">{{ __('Automatisch (gleiches Datum)') }}</flux:select.option>
@foreach($this->dayPositions as $key => $label)
<flux:select.option value="{{ $key }}">{{ $label }}</flux:select.option>
@endforeach
</flux:select>
<flux:description>{{ __('Welcher Wochentag im Monat? (z.B. "letzter Freitag")') }}</flux:description>
<flux:error name="recurrenceDayPosition"/>
</flux:field>
</div>
<flux:field>
<flux:text class="text-sm text-zinc-600 dark:text-zinc-400">
{{ __('Für regelmäßige Termine wie "immer am letzten Freitag des Monats":') }}<br>
{{ __('Wiederholungstyp: Monatlich') }}<br>
{{ __('Wochentag: Freitag') }}<br>
{{ __('Position im Monat: Letzter') }}
</flux:text>
</flux:field>
@endif
<flux:field>
@@ -287,7 +541,7 @@ class extends Component {
@foreach($this->previewDates as $index => $dateInfo)
<flux:card class="bg-zinc-50 dark:bg-zinc-800/50">
<div class="flex items-start gap-3">
<div class="flex-shrink-0 w-10 h-10 rounded-full bg-zinc-200 dark:bg-zinc-700 flex items-center justify-center">
<div class="shrink-0 w-10 h-10 rounded-full bg-zinc-200 dark:bg-zinc-700 flex items-center justify-center">
<flux:text class="font-semibold text-sm">{{ $index + 1 }}</flux:text>
</div>
<div class="flex-1 min-w-0">
@@ -346,7 +600,7 @@ class extends Component {
</form>
<!-- Confirmation Modal for Series -->
<flux:modal name="confirm-series" class="min-w-[22rem]">
<flux:modal name="confirm-series" class="min-w-88">
<div class="space-y-6">
<div>
<flux:heading size="lg">{{ __('Serientermine erstellen?') }}</flux:heading>