3
3
namespace App \Filament \Resources ;
4
4
5
5
use App \Filament \Resources \LicenseResource \Pages ;
6
+ use App \Filament \Resources \LicenseResource \RelationManagers ;
6
7
use App \Models \License ;
7
8
use Filament \Forms ;
8
9
use Filament \Forms \Form ;
9
- use Filament \Infolists \ Components ;
10
+ use Filament \Infolists ;
10
11
use Filament \Infolists \Infolist ;
11
12
use Filament \Resources \Resource ;
12
13
use Filament \Tables ;
@@ -24,24 +25,21 @@ public static function form(Form $form): Form
24
25
->schema ([
25
26
Forms \Components \Section::make ('License Information ' )
26
27
->schema ([
27
- Forms \Components \TextInput::make ('id ' )
28
- ->disabled (),
28
+ Forms \Components \TextInput::make ('id ' ),
29
29
Forms \Components \TextInput::make ('anystack_id ' )
30
- ->maxLength (36 )
31
- ->disabled (),
30
+ ->maxLength (36 ),
32
31
Forms \Components \Select::make ('user_id ' )
33
- ->relationship ('user ' , 'email ' )
34
- ->disabled (),
32
+ ->relationship ('user ' , 'email ' ),
35
33
Forms \Components \TextInput::make ('policy_name ' )
36
- ->label ('Plan ' )
37
- -> disabled ( ),
38
- Forms \Components \TextInput ::make ('key ' )
39
- -> disabled ( ),
40
- Forms \Components \DateTimePicker ::make ('expires_at ' )
41
- ->disabled ( ),
42
- Forms \ Components \DateTimePicker:: make ( ' created_at ' )
43
- -> disabled (),
44
- ])-> columns ( 2 ),
34
+ ->label ('Plan ' ),
35
+ Forms \ Components \TextInput:: make ( ' key ' ),
36
+ Forms \Components \DateTimePicker ::make ('expires_at ' ),
37
+ Forms \ Components \DateTimePicker:: make ( ' created_at ' ),
38
+ Forms \Components \Toggle ::make ('is_suspended ' )
39
+ ->label ( ' Suspended ' ),
40
+ ] )
41
+ -> columns ( 2 )
42
+ -> disabled ( ),
45
43
]);
46
44
}
47
45
@@ -54,10 +52,11 @@ public static function table(Table $table): Table
54
52
->searchable (),
55
53
Tables \Columns \TextColumn::make ('user.email ' )
56
54
->searchable ()
57
- ->sortable ()
58
- ->copyable ()
59
- ->url (fn (\App \Models \License $ record ): string => route ('filament.admin.resources.users.edit ' , ['record ' => $ record ->user_id ]))
60
- ->openUrlInNewTab (),
55
+ ->sortable (),
56
+ Tables \Columns \TextColumn::make ('subscription_item_id ' )
57
+ ->label ('Subscription Item ' )
58
+ ->searchable ()
59
+ ->sortable (),
61
60
Tables \Columns \TextColumn::make ('key ' )
62
61
->searchable ()
63
62
->copyable (),
@@ -70,138 +69,77 @@ public static function table(Table $table): Table
70
69
Tables \Columns \TextColumn::make ('created_at ' )
71
70
->dateTime ()
72
71
->sortable (),
72
+ Tables \Columns \IconColumn::make ('is_suspended ' )
73
+ ->boolean ()
74
+ ->label ('Suspended ' )
75
+ ->sortable (),
73
76
])
74
77
->filters ([
75
78
//
76
79
])
77
80
->actions ([
78
- Tables \Actions \ViewAction::make ()
79
- ->slideOver ()
80
- ->modalHeading ('License Details ' )
81
- ->modalWidth ('7xl ' )
82
- ->extraModalFooterActions ([
83
- Tables \Actions \Action::make ('viewUser ' )
84
- ->label ('View User ' )
85
- ->icon ('heroicon-o-user ' )
86
- ->color ('primary ' )
87
- ->url (fn (License $ record ) => route ('filament.admin.resources.users.edit ' , ['record ' => $ record ->user_id ]))
88
- ->openUrlInNewTab ()
89
- ->visible (fn (License $ record ) => $ record ->user_id !== null ),
90
- ]),
81
+ Tables \Actions \ActionGroup::make ([
82
+ Tables \Actions \EditAction::make (),
83
+ Tables \Actions \Action::make ('viewUser ' )
84
+ ->label ('View User ' )
85
+ ->icon ('heroicon-o-user ' )
86
+ ->color ('primary ' )
87
+ ->url (fn (License $ record ) => route ('filament.admin.resources.users.edit ' , ['record ' => $ record ->user_id ]))
88
+ ->openUrlInNewTab ()
89
+ ->visible (fn (License $ record ) => $ record ->user_id !== null ),
90
+ ])
91
+ ->label ('Actions ' )
92
+ ->icon ('heroicon-m-ellipsis-vertical ' ),
91
93
])
92
94
->defaultPaginationPageOption (25 )
93
95
->bulkActions ([]);
94
96
}
95
97
96
- public static function getRelations (): array
97
- {
98
- return [
99
- //
100
- ];
101
- }
102
-
103
98
public static function infolist (Infolist $ infolist ): Infolist
104
99
{
105
100
return $ infolist
106
101
->schema ([
107
- Components \Section::make ('License Information ' )
102
+ Infolists \ Components \Section::make ('License Information ' )
108
103
->schema ([
109
- Components \TextEntry::make ('id ' ),
110
- Components \TextEntry::make ('key ' )
104
+ Infolists \Components \TextEntry::make ('id ' )
111
105
->copyable (),
112
- Components \TextEntry::make ('policy_name ' )
113
- ->label ('Plan ' ),
114
- Components \TextEntry::make ('expires_at ' )
115
- ->dateTime (),
116
- Components \TextEntry::make ('created_at ' )
117
- ->dateTime (),
118
- Components \TextEntry::make ('anystack_id ' )
106
+ Infolists \Components \TextEntry::make ('anystack_id ' )
119
107
->copyable (),
120
- ])->columns (2 ),
121
-
122
- Components \Section::make ('User Information ' )
123
- ->schema ([
124
- Components \TextEntry::make ('user.id ' )
125
- ->label ('User ID ' )
126
- ->url (fn ($ record ) => route ('filament.admin.resources.users.edit ' , ['record ' => $ record ->user_id ]))
127
- ->openUrlInNewTab (),
128
- Components \TextEntry::make ('user.email ' )
129
- ->label ('Email ' )
130
- ->copyable ()
131
- ->url (fn ($ record ) => route ('filament.admin.resources.users.edit ' , ['record ' => $ record ->user_id ]))
132
- ->openUrlInNewTab (),
133
- Components \TextEntry::make ('user.name ' )
134
- ->label ('Name ' ),
135
- Components \TextEntry::make ('user.first_name ' )
136
- ->label ('First Name ' ),
137
- Components \TextEntry::make ('user.last_name ' )
138
- ->label ('Last Name ' ),
139
- Components \TextEntry::make ('user.stripe_id ' )
140
- ->label ('Stripe ID ' )
141
- ->copyable ()
142
- ->visible (fn ($ record ) => filled ($ record ->user ->stripe_id ))
143
- ->url (fn ($ record ) => filled ($ record ->user ->stripe_id )
144
- ? "https://dashboard.stripe.com/customers/ {$ record ->user ->stripe_id }"
145
- : null )
146
- ->openUrlInNewTab (),
147
- Components \TextEntry::make ('user.anystack_contact_id ' )
148
- ->label ('Anystack Contact ID ' )
149
- ->copyable ()
150
- ->visible (fn ($ record ) => filled ($ record ->user ->anystack_contact_id ))
151
- ->url (fn ($ record ) => filled ($ record ->user ->anystack_contact_id )
152
- ? "https://app.anystack.sh/contacts/ {$ record ->user ->anystack_contact_id }"
153
- : null )
154
- ->openUrlInNewTab (),
155
- ])->columns (2 ),
156
-
157
- Components \Section::make ('Subscription Information ' )
158
- ->schema ([
159
- Components \TextEntry::make ('subscriptionItem.id ' )
160
- ->label ('Subscription Item ID ' )
161
- ->visible (fn ($ record ) => $ record ->subscription_item_id !== null ),
162
- Components \TextEntry::make ('subscriptionItem.stripe_id ' )
163
- ->label ('Stripe Subscription Item ID ' )
164
- ->copyable ()
165
- ->visible (fn ($ record ) => $ record ->subscription_item_id !== null ),
166
- Components \TextEntry::make ('subscriptionItem.subscription.stripe_id ' )
167
- ->label ('Stripe Subscription ID ' )
168
- ->copyable ()
169
- ->visible (fn ($ record ) => $ record ->subscription_item_id !== null )
170
- ->url (fn ($ record ) => $ record ->subscription_item_id !== null && filled ($ record ->subscriptionItem ?->subscription?->stripe_id)
171
- ? "https://dashboard.stripe.com/subscriptions/ {$ record ->subscriptionItem ->subscription ->stripe_id }"
172
- : null )
173
- ->openUrlInNewTab (),
174
- Components \TextEntry::make ('subscriptionItem.stripe_price ' )
175
- ->label ('Stripe Price ID ' )
176
- ->copyable ()
177
- ->visible (fn ($ record ) => $ record ->subscription_item_id !== null ),
178
- Components \TextEntry::make ('subscriptionItem.stripe_product ' )
179
- ->label ('Stripe Product ID ' )
180
- ->copyable ()
181
- ->visible (fn ($ record ) => $ record ->subscription_item_id !== null ),
182
- Components \TextEntry::make ('subscriptionItem.subscription.stripe_status ' )
183
- ->label ('Subscription Status ' )
184
- ->badge ()
185
- ->color (fn ($ state ): string => match ($ state ) {
186
- 'active ' => 'success ' ,
187
- 'canceled ' => 'danger ' ,
188
- 'incomplete ' => 'warning ' ,
189
- 'incomplete_expired ' => 'danger ' ,
190
- 'past_due ' => 'warning ' ,
191
- 'trialing ' => 'info ' ,
192
- 'unpaid ' => 'danger ' ,
193
- default => 'gray ' ,
194
- })
195
- ->visible (fn ($ record ) => $ record ->subscription_item_id !== null ),
196
- ])->columns (2 )
197
- ->visible (fn ($ record ) => $ record ->subscription_item_id !== null ),
108
+ Infolists \Components \TextEntry::make ('user.email ' )
109
+ ->label ('User ' )
110
+ ->copyable (),
111
+ Infolists \Components \TextEntry::make ('policy_name ' )
112
+ ->label ('Plan ' )
113
+ ->copyable (),
114
+ Infolists \Components \TextEntry::make ('key ' )
115
+ ->copyable (),
116
+ Infolists \Components \TextEntry::make ('expires_at ' )
117
+ ->dateTime ()
118
+ ->copyable (),
119
+ Infolists \Components \TextEntry::make ('created_at ' )
120
+ ->dateTime ()
121
+ ->copyable (),
122
+ Infolists \Components \IconEntry::make ('is_suspended ' )
123
+ ->label ('Suspended ' )
124
+ ->boolean (),
125
+ ])
126
+ ->columns (2 ),
198
127
]);
199
128
}
200
129
130
+ public static function getRelations (): array
131
+ {
132
+ return [
133
+ RelationManagers \UserRelationManager::class,
134
+ RelationManagers \SubscriptionItemRelationManager::class,
135
+ ];
136
+ }
137
+
201
138
public static function getPages (): array
202
139
{
203
140
return [
204
141
'index ' => Pages \ListLicenses::route ('/ ' ),
142
+ 'view ' => Pages \ViewLicense::route ('/{record} ' ),
205
143
];
206
144
}
207
145
}
0 commit comments