Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- Add info about benefits on list #518

Merged
merged 4 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading