Skip to content

Commit

Permalink
- Add info about benefits on list (#518)
Browse files Browse the repository at this point in the history
* - add info about owning benefit on benefit list

* - style icon

* - fix calendar

* - linter
  • Loading branch information
EwelinaSkrzypacz authored Jan 17, 2025
1 parent f77422e commit ebef1d6
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
1 change: 1 addition & 0 deletions app/Domain/UserBenefitsRetriever.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public function getAssignedBenefits(User $user): array
"name" => $benefit["name"],
"employee" => $assignedBenefit["employee"],
"employer" => $assignedBenefit["employer"],
"isUsed" => true,
];
}

Expand Down
12 changes: 11 additions & 1 deletion app/Http/Controllers/BenefitController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Inertia\Response;
use Toby\Domain\UserBenefitsRetriever;
use Toby\Http\Requests\BenefitRequest;
use Toby\Http\Resources\BenefitResource;
use Toby\Models\Benefit;
Expand All @@ -24,8 +25,17 @@ public function index(Request $request): Response
->paginate()
->withQueryString();

$userBenefitsRetriever = new UserBenefitsRetriever();
$userBenefits = $userBenefitsRetriever->getAssignedBenefits($request->user());
$userBenefitIds = collect($userBenefits)->pluck("id")->toArray();

return inertia("Benefits/Benefits", [
"benefits" => BenefitResource::collection($benefits),
"benefits" => BenefitResource::collection($benefits->through(fn($benefit) => [
"id" => $benefit->id,
"name" => $benefit->name,
"companion" => $benefit->companion,
"isUsed" => in_array($benefit->id, $userBenefitIds, true),
])),
]);
}

Expand Down
7 changes: 4 additions & 3 deletions app/Http/Resources/BenefitResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,10 @@ class BenefitResource extends JsonResource
public function toArray($request): array
{
return [
"id" => $this->id,
"name" => $this->name,
"companion" => $this->companion,
"id" => $this->resource["id"] ?? $this->id,
"name" => $this->resource["name"] ?? $this->name,
"companion" => $this->resource["companion"] ?? $this->companion,
"isUsed" => $this->resource["isUsed"] ?? false,
];
}
}
11 changes: 9 additions & 2 deletions resources/js/Pages/Benefits/Benefits.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<script setup>
import { EllipsisVerticalIcon, TrashIcon } from '@heroicons/vue/24/solid'
import { EllipsisVerticalIcon, TrashIcon, ShieldCheckIcon } from '@heroicons/vue/24/solid'
import { Menu, MenuButton, MenuItem, MenuItems } from '@headlessui/vue'
import { ref } from 'vue'
import { Dialog, DialogOverlay, DialogTitle, TransitionChild, TransitionRoot } from '@headlessui/vue'
Expand Down Expand Up @@ -80,7 +80,14 @@ function submitCreateBenefit() {
class="hover:bg-blumilk-25"
>
<td class="px-4 py-2 text-sm text-gray-500 whitespace-nowrap">
{{ benefit.name }}
<div class="flex items-center gap-1 font-medium">
{{ benefit.name }}
<span v-if="benefit.isUsed"
v-tooltip.right="'Posiadany benefit'"
>
<ShieldCheckIcon class="size-5 text-gray-500" />
</span>
</div>
</td>
<td class="px-4 py-2 text-sm text-gray-500 whitespace-nowrap">
<span
Expand Down
2 changes: 1 addition & 1 deletion resources/js/Pages/Calendar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ const currentDate = DateTime.now()
const selectedMonth = ref(DateTime.fromISO(props.selectedDate))
watch(selectedMonth, (value, oldValue) => {
if (!value || value.toFormat('LL-YYY') === oldValue?.toFormat('LL-YYY')) {
if (!value || value.toFormat('LL-yyyy') === oldValue?.toFormat('LL-yyyy')) {
return
}
Expand Down

0 comments on commit ebef1d6

Please sign in to comment.