From 54a7fcec5aa77e82d0717ab005e8bfc10e0a6fc3 Mon Sep 17 00:00:00 2001 From: Yoga Pangestu Date: Wed, 12 Nov 2025 09:16:26 +0700 Subject: [PATCH] feat(tier): menambahkan counting total hadiah - updated data tiers saat action reward - menyesuaikan kueri tiers nya --- app/Livewire/Studio/Loyalty/Tier.php | 7 +++++++ app/Livewire/Studio/Loyalty/Tier/Reward.php | 5 +++++ resources/views/livewire/studio/loyalty/tiers.blade.php | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/app/Livewire/Studio/Loyalty/Tier.php b/app/Livewire/Studio/Loyalty/Tier.php index 36ca0e2..8cd214e 100644 --- a/app/Livewire/Studio/Loyalty/Tier.php +++ b/app/Livewire/Studio/Loyalty/Tier.php @@ -31,6 +31,12 @@ class Tier extends Component public string $modalTitle = ''; public function mount() + { + $this->loadTiers(); + } + + #[On('data:tiersUpdated')] + public function loadTiers() { $this->tiers = TierModel::with(['memberships.user.customer.orders.items']) ->withCount('memberships') @@ -82,6 +88,7 @@ public function mount() 'min_points' => currency($tier->min_points), 'max_points' => currency($tier->max_points), 'total_members' => currency($tier->memberships_count), + 'total_rewards' => $tier->rewards->count(), 'top_member' => $topMemberStats, ]; }) diff --git a/app/Livewire/Studio/Loyalty/Tier/Reward.php b/app/Livewire/Studio/Loyalty/Tier/Reward.php index a8ced41..513914e 100644 --- a/app/Livewire/Studio/Loyalty/Tier/Reward.php +++ b/app/Livewire/Studio/Loyalty/Tier/Reward.php @@ -3,6 +3,7 @@ namespace App\Livewire\Studio\Loyalty\Tier; use App\Livewire\Forms\Studio\Loyalty\Tier\RewardForm; +use App\Livewire\Studio\Loyalty\Tier; use App\Models\TierReward; use App\Traits\WithAuthorization; use App\Traits\WithCloseModal; @@ -59,6 +60,8 @@ public function create() $this->form->store(); + $this->dispatch('data:tiersUpdated')->to(Tier::class); + $this->toast('Hadiah berhasil ditambahkan.'); Flux::modals()->close(); @@ -81,6 +84,8 @@ public function delete(TierReward $reward) $this->toast('Hadiah berhasil dihapus.'); + $this->dispatch('data:tiersUpdated')->to(Tier::class); + Flux::modal('delete')->close(); $this->rewards = array_values(array_filter($this->rewards, fn ($item) => $item['hash'] !== $reward->hash)); diff --git a/resources/views/livewire/studio/loyalty/tiers.blade.php b/resources/views/livewire/studio/loyalty/tiers.blade.php index ee9cec7..f47803e 100644 --- a/resources/views/livewire/studio/loyalty/tiers.blade.php +++ b/resources/views/livewire/studio/loyalty/tiers.blade.php @@ -42,6 +42,11 @@ class="hover:shadow-lg transition-shadow duration-200 bg-white dark:bg-gray-900 {{ $tier['total_members'] }} +
+ Total Hadiah: + {{ $tier['total_rewards'] }} +
+ @if ($tier['top_member'])
Member Dengan Poin