-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathDashboard.php
More file actions
131 lines (108 loc) · 3.09 KB
/
Dashboard.php
File metadata and controls
131 lines (108 loc) · 3.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
<?php
namespace App\Livewire\Customer;
use App\Enums\Subscription;
use App\Models\Team;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Layout;
use Livewire\Attributes\Title;
use Livewire\Component;
#[Layout('components.layouts.dashboard')]
#[Title('Dashboard')]
class Dashboard extends Component
{
#[Computed]
public function licenseCount(): int
{
return auth()->user()->licenses()->count();
}
#[Computed]
public function isEapCustomer(): bool
{
return auth()->user()->isEapCustomer();
}
#[Computed]
public function activeSubscription()
{
return auth()->user()->subscription();
}
#[Computed]
public function isCompedSubscription(): bool
{
return auth()->user()->hasCompedSubscription();
}
#[Computed]
public function subscriptionName(): ?string
{
$subscription = $this->activeSubscription;
if (! $subscription) {
return null;
}
if ($subscription->stripe_price) {
try {
return Subscription::fromStripePriceId($subscription->stripe_price)->name();
} catch (\RuntimeException) {
return ucfirst($subscription->type);
}
}
return ucfirst($subscription->type);
}
#[Computed]
public function hasUltraSubscription(): bool
{
return auth()->user()->hasActiveUltraSubscription();
}
#[Computed]
public function ownedTeam(): ?Team
{
return auth()->user()->ownedTeam;
}
#[Computed]
public function teamMemberCount(): int
{
return $this->ownedTeam?->activeUserCount() ?? 0;
}
#[Computed]
public function pluginLicenseCount(): int
{
return auth()->user()->pluginLicenses()->count();
}
#[Computed]
public function renewalLicenseKey(): ?string
{
if ($this->activeSubscription) {
return null;
}
$highestTierLicense = auth()->user()->licenses()
->whereIn('policy_name', ['max', 'pro', 'mini'])
->orderByRaw("CASE policy_name WHEN 'max' THEN 1 WHEN 'pro' THEN 2 WHEN 'mini' THEN 3 END")
->first();
return $highestTierLicense?->key;
}
#[Computed]
public function connectedAccountsCount(): int
{
$user = auth()->user();
return ($user->hasGitHubToken() ? 1 : 0) + ($user->hasDiscordConnected() ? 1 : 0);
}
#[Computed]
public function connectedAccountsDescription(): string
{
$user = auth()->user();
$hasGitHub = $user->hasGitHubToken();
$hasDiscord = $user->hasDiscordConnected();
return match (true) {
$hasGitHub && $hasDiscord => 'GitHub & Discord',
$hasGitHub => 'GitHub connected',
$hasDiscord => 'Discord connected',
default => 'No accounts connected',
};
}
#[Computed]
public function totalPurchases(): int
{
$user = auth()->user();
return $this->licenseCount
+ $this->pluginLicenseCount
+ $user->productLicenses()->count();
}
}