diff --git a/resources/views/livewire/courses/create-edit-events.blade.php b/resources/views/livewire/courses/create-edit-events.blade.php index fd2c897..959f66b 100644 --- a/resources/views/livewire/courses/create-edit-events.blade.php +++ b/resources/views/livewire/courses/create-edit-events.blade.php @@ -19,11 +19,10 @@ class extends Component { public $country = 'de'; - #[Validate('required|date')] - public string $from = ''; - - #[Validate('required|date|after:from')] - public string $to = ''; + public string $fromDate = ''; + public string $fromTime = ''; + public string $toDate = ''; + public string $toTime = ''; #[Validate('required|exists:venues,id')] public ?int $venue_id = null; @@ -39,31 +38,69 @@ class extends Component { public function mount(): void { $this->country = request()->route('country'); + $timezone = auth()->user()->timezone ?? 'Europe/Berlin'; + if ($this->event) { - $this->from = $this->event->from->format('Y-m-d\TH:i'); - $this->to = $this->event->to->format('Y-m-d\TH:i'); + $localFrom = $this->event->from->setTimezone($timezone); + $localTo = $this->event->to->setTimezone($timezone); + + $this->fromDate = $localFrom->format('Y-m-d'); + $this->fromTime = $localFrom->format('H:i'); + $this->toDate = $localTo->format('Y-m-d'); + $this->toTime = $localTo->format('H:i'); $this->venue_id = $this->event->venue_id; $this->link = $this->event->link; } else { - // Set default start time to next Monday at 09:00 - $nextMonday = now()->next('Monday')->setTime(9, 0); - $this->from = $nextMonday->format('Y-m-d\TH:i'); - $this->to = $nextMonday->copy()->addHours(3)->format('Y-m-d\TH:i'); + // Set default start time to next Monday at 09:00 in user's timezone + $nextMonday = now($timezone)->next('Monday')->setTime(9, 0); + $this->fromDate = $nextMonday->format('Y-m-d'); + $this->fromTime = $nextMonday->format('H:i'); + $this->toDate = $nextMonday->format('Y-m-d'); + $this->toTime = $nextMonday->copy()->addHours(3)->format('H:i'); } } public function save(): void { - $validated = $this->validate(); + $this->validate([ + 'fromDate' => 'required|date', + 'fromTime' => 'required', + 'toDate' => 'required|date|after_or_equal:fromDate', + 'toTime' => 'required', + 'venue_id' => 'required|exists:venues,id', + 'link' => 'required|url|max:255', + ]); + + $timezone = auth()->user()->timezone ?? 'Europe/Berlin'; + + // Combine date and time in user's timezone, then convert to UTC + $localFrom = \Carbon\Carbon::createFromFormat('Y-m-d H:i', $this->fromDate . ' ' . $this->fromTime, $timezone); + $utcFrom = $localFrom->setTimezone('UTC'); + + $localTo = \Carbon\Carbon::createFromFormat('Y-m-d H:i', $this->toDate . ' ' . $this->toTime, $timezone); + $utcTo = $localTo->setTimezone('UTC'); + + // Additional validation: to must be after from + if ($utcTo->lte($utcFrom)) { + $this->addError('toTime', __('Die Endzeit muss nach der Startzeit liegen.')); + return; + } + + $data = [ + 'from' => $utcFrom, + 'to' => $utcTo, + 'venue_id' => $this->venue_id, + 'link' => $this->link, + ]; if ($this->event) { // Update existing event - $this->event->update($validated); + $this->event->update($data); session()->flash('status', __('Event erfolgreich aktualisiert!')); } else { // Create new event $this->course->courseEvents()->create([ - ...$validated, + ...$data, 'created_by' => auth()->id(), ]); session()->flash('status', __('Event erfolgreich erstellt!')); @@ -108,8 +145,18 @@ class extends Component { public function with(): array { return [ - 'venues' => Venue::query()->orderBy('name')->get(), - 'cities' => City::query()->orderBy('name')->get(), + 'venues' => Venue::query() + ->with([ + 'city', + ]) + ->orderBy('name') + ->get(), + 'cities' => City::query() + ->with([ + 'country', + ]) + ->orderBy('name') + ->get(), ]; } }; ?> @@ -126,18 +173,34 @@ class extends Component { {{ __('Event Details') }}
+ + {{ __('Startdatum') }} * + + {{ __('An welchem Tag beginnt das Event?') }} + + + {{ __('Startzeit') }} * - - {{ __('Wann beginnt das Event?') }} - + + {{ __('Um wie viel Uhr beginnt das Event?') }} ({{ auth()->user()->timezone ?? 'Europe/Berlin' }}) + + +
+ +
+ + {{ __('Enddatum') }} * + + {{ __('An welchem Tag endet das Event?') }} + {{ __('Endzeit') }} * - - {{ __('Wann endet das Event?') }} - + + {{ __('Um wie viel Uhr endet das Event?') }} ({{ auth()->user()->timezone ?? 'Europe/Berlin' }}) +
diff --git a/resources/views/livewire/meetups/create-edit-events.blade.php b/resources/views/livewire/meetups/create-edit-events.blade.php index c1d5153..5c6ff78 100644 --- a/resources/views/livewire/meetups/create-edit-events.blade.php +++ b/resources/views/livewire/meetups/create-edit-events.blade.php @@ -17,8 +17,8 @@ class extends Component { public $country = 'de'; - #[Validate('required|date')] - public string $start = ''; + public string $startDate = ''; + public string $startTime = ''; #[Validate('required|string|max:255')] public ?string $location = null; @@ -32,29 +32,54 @@ class extends Component { public function mount(): void { $this->country = request()->route('country'); + $timezone = auth()->user()->timezone ?? 'Europe/Berlin'; + if ($this->event) { - $this->start = $this->event->start->format('Y-m-d\TH:i'); + $localStart = $this->event->start->setTimezone($timezone); + $this->startDate = $localStart->format('Y-m-d'); + $this->startTime = $localStart->format('H:i'); $this->location = $this->event->location; $this->description = $this->event->description; $this->link = $this->event->link; } else { - // Set default start time to next Monday at 19:00 - $this->start = now()->next('Monday')->setTime(19, 0)->format('Y-m-d\TH:i'); + // 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'); } } public function save(): void { - $validated = $this->validate(); + $this->validate([ + 'startDate' => 'required|date', + 'startTime' => 'required', + 'location' => 'required|string|max:255', + 'description' => 'required|string', + 'link' => 'required|url|max:255', + ]); + + $timezone = auth()->user()->timezone ?? 'Europe/Berlin'; + + // Combine date and time in user's timezone, then convert to UTC + $localDateTime = \Carbon\Carbon::createFromFormat('Y-m-d H:i', $this->startDate . ' ' . $this->startTime, $timezone); + $utcDateTime = $localDateTime->setTimezone('UTC'); + + $data = [ + 'start' => $utcDateTime, + 'location' => $this->location, + 'description' => $this->description, + 'link' => $this->link, + ]; if ($this->event) { // Update existing event - $this->event->update($validated); + $this->event->update($data); session()->flash('status', __('Event erfolgreich aktualisiert!')); } else { // Create new event $this->meetup->meetupEvents()->create([ - ...$validated, + ...$data, 'created_by' => auth()->id(), 'attendees' => [], 'might_attendees' => [], @@ -90,20 +115,27 @@ class extends Component {
- {{ __('Startzeit') }} * - - {{ __('Wann findet das Event statt?') }} - + {{ __('Datum') }} * + + {{ __('An welchem Tag findet das Event statt?') }} + - {{ __('Ort') }} - - {{ __('Wo findet das Event statt?') }} - + {{ __('Uhrzeit') }} * + + {{ __('Um wie viel Uhr startet das Event?') }} ({{ auth()->user()->timezone ?? 'Europe/Berlin' }}) +
+ + {{ __('Ort') }} + + {{ __('Wo findet das Event statt?') }} + + + {{ __('Beschreibung') }} diff --git a/resources/views/livewire/meetups/create.blade.php b/resources/views/livewire/meetups/create.blade.php index e82ce0a..af3d42e 100644 --- a/resources/views/livewire/meetups/create.blade.php +++ b/resources/views/livewire/meetups/create.blade.php @@ -100,8 +100,15 @@ class extends Component { public function with(): array { return [ - 'cities' => City::query()->orderBy('name')->get(), - 'countries' => Country::query()->orderBy('countries.name')->get(), + 'cities' => City::query() + ->with([ + 'country', + ]) + ->orderBy('name') + ->get(), + 'countries' => Country::query() + ->orderBy('countries.name') + ->get(), ]; } }; ?> @@ -120,20 +127,20 @@ class extends Component {
@if($logo) Logo + class="size-full object-cover rounded"/> @else @endif -
+