Hey! ... could you fix this? i have the same problem :(
Jul 11, 2023
3
Level 13
Refresh FullCalendar after delete via Livewire
I have a Livewire Component where I implemented FullCalendar
<?php
class View extends Component
{
public function render()
{
return view('livewire.reservations.view')
->with('events', $this->getCalendarReservation())
->layoutData(['header' => 'Meine Reservierungen']);
}
private function getCalendarReservation(): array
{
$events = [];
$reservations = Reservation::with('desk')
->where('start_date', '>=', now()->startOfDay())
->where('user_id', Auth::user()->id)
->where('series', false)
->orderBy('start_date')
->get();
foreach ($reservations as $reservation) {
$events[] = [
'title' => $reservation->desk->name . ' (' . $reservation->desk->location . ')',
'start' => $reservation->start_date,
'id' => $reservation->uuid,
'allDay' => true
];
}
return $events;
}
}
and the view
<div>
<div id="calendar"></div>
<script>
document.addEventListener('livewire:load', function() {
var calendarEl = document.getElementById('calendar');
var calendar = new FullCalendar.Calendar(calendarEl, {
buttonText: {
today: 'Heute'
},
weekends: false,
eventColor: '#D30E28',
locale: 'de',
initialView: 'dayGridMonth',
height: 650,
eventDisplay: 'block',
events: @json($events),
eventClick: function(info) {
Livewire.emit('openModal', 'modal.view-reservation', {id: info.event.id})
}
});
Livewire.on('ReservationDeleted', () => {
calendar.refetchEvents();
});
calendar.render();
});
</script>
</div>
After the user confirms that he wants to delete his reservation, the reservation gets deleted and the event ReservationDeleted gets fired. But the calendar doesn't refresh and the deleted reservation is still shown. After refreshing the full page the reservation dissapears in the calendar. Why does the calendar not refresh?
Please or to participate in this conversation.