Skip to content

Commit 134faae

Browse files
author
Itamar Junior
committed
feat: add modal to display due items when clicking calendar dates
1 parent 40a6839 commit 134faae

File tree

2 files changed

+53
-2
lines changed

2 files changed

+53
-2
lines changed

app/Livewire/Company/BudgetCalendar.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ class BudgetCalendar extends Component
1717
public $currentDate;
1818
public $dueDatesByDay = [];
1919
public $viewMode = 'month';
20+
public $selectedDate = null;
21+
public $selectedDueItems = [];
2022

2123

2224
public function mount()
@@ -32,6 +34,12 @@ public function mount()
3234
}
3335
}
3436

37+
public function showDueItems($date)
38+
{
39+
$this->selectedDate = $date;
40+
$this->selectedDueItems = $this->dueDatesByDay[$date] ?? [];
41+
}
42+
3543
public function updatedViewMode($value)
3644
{
3745
session(['calendarViewMode' => $value]);

resources/views/livewire/company/budget-calendar.blade.php

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,11 +137,11 @@ class="isolate mt-2 grid grid-cols-7 gap-px rounded-lg bg-gray-200 text-sm shado
137137
$isLastCell = $cellIndex === $firstDayOfWeek - 1 + $daysInMonth;
138138
@endphp
139139

140-
<button type="button"
140+
<button type="button" wire:click="showDueItems('{{ $formattedDate }}')"
141141
class="bg-white py-1.5 hover:bg-gray-100 focus:z-10 {{ $isFirstCell ? 'rounded-tl-lg' : '' }} {{ $isLastCell ? 'rounded-br-lg' : '' }}">
142142
<time datetime="{{ $formattedDate }}"
143143
title="{{ $hasDue ? implode(', ', collect($dueDatesByDay[$formattedDate])->pluck('category.name')->toArray()) : '' }}"
144-
class="mx-auto flex size-7 items-center justify-center rounded-full {{ $hasDue ? 'bg-indigo-600 font-semibold text-white' : '' }}">
144+
class="mx-auto flex size-7 items-center justify-center rounded-full {{ $hasDue ? 'bg-indigo-600 font-semibold text-white cursor-pointer' : '' }}">
145145
{{ $day }}
146146
</time>
147147
</button>
@@ -150,6 +150,49 @@ class="mx-auto flex size-7 items-center justify-center rounded-full {{ $hasDue ?
150150
</section>
151151
@endforeach
152152

153+
@if ($selectedDate && count($selectedDueItems))
154+
<div class="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50"
155+
x-transition:enter="transition ease-out duration-300" x-transition:enter-start="opacity-0"
156+
x-transition:enter-end="opacity-100" x-transition:leave="transition ease-in duration-200"
157+
x-transition:leave-start="opacity-100" x-transition:leave-end="opacity-0">
158+
<div class="bg-white rounded-lg shadow-lg w-full max-w-2xl p-6 relative">
159+
<button wire:click="$set('selectedDate', null)"
160+
wire:keydown.escape.window="$set('selectedDate', null)"
161+
class="absolute top-2 right-2 text-gray-400 hover:text-gray-600">
162+
<svg xmlns="http://www.w3.org/2000/svg" class="h-5 w-5" fill="none"
163+
viewBox="0 0 24 24" stroke="currentColor">
164+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
165+
d="M6 18L18 6M6 6l12 12" />
166+
</svg>
167+
</button>
168+
169+
<h2 class="text-lg font-semibold mb-4">Due on
170+
{{ \Carbon\Carbon::parse($selectedDate)->format('jS F, Y') }}</h2>
171+
172+
<table class="min-w-full text-sm text-left border">
173+
<thead class="bg-gray-100">
174+
<tr>
175+
<th class="px-4 py-2 border-b">Category</th>
176+
<th class="px-4 py-2 border-b">Provider</th>
177+
<th class="px-4 py-2 border-b">Amount</th>
178+
</tr>
179+
</thead>
180+
<tbody>
181+
@foreach ($selectedDueItems as $item)
182+
<tr>
183+
<td class="px-4 py-2 border-b">{{ $item->category->name ?? '-' }}</td>
184+
<td class="px-4 py-2 border-b">{{ $item->provider->name ?? '-' }}</td>
185+
<td class="px-4 py-2 border-b">
186+
{{ Number::currency($item->budget, 'EUR') }}</td>
187+
</tr>
188+
@endforeach
189+
</tbody>
190+
</table>
191+
</div>
192+
</div>
193+
@endif
194+
195+
153196
</div>
154197
</div>
155198
</div>

0 commit comments

Comments
 (0)