-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathUserResource.php
More file actions
193 lines (185 loc) · 9.14 KB
/
UserResource.php
File metadata and controls
193 lines (185 loc) · 9.14 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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<?php
namespace App\Filament\Resources;
use App\Enums\StripeConnectStatus;
use App\Filament\Resources\UserResource\Pages;
use App\Filament\Resources\UserResource\RelationManagers;
use App\Models\User;
use Filament\Actions;
use Filament\Forms;
use Filament\Resources\Resource;
use Filament\Schemas;
use Filament\Schemas\Schema;
use Filament\Tables;
use Filament\Tables\Table;
use Illuminate\Support\HtmlString;
use STS\FilamentImpersonate\Actions\Impersonate;
class UserResource extends Resource
{
protected static ?string $model = User::class;
protected static \BackedEnum|string|null $navigationIcon = 'heroicon-o-user';
public static function form(Schema $schema): Schema
{
return $schema
->inlineLabel()
->columns(1)
->schema([
Schemas\Components\Section::make('User Information')
->inlineLabel()
->columns(1)
->schema([
Forms\Components\TextInput::make('name')
->maxLength(255),
Forms\Components\TextInput::make('email')
->email()
->required()
->maxLength(255),
Forms\Components\DateTimePicker::make('email_verified_at'),
Forms\Components\TextInput::make('password')
->password()
->dehydrated(fn ($state) => filled($state))
->required(fn (string $context): bool => $context === 'create')
->maxLength(255),
]),
Schemas\Components\Section::make('Billing Information')
->inlineLabel()
->columns(1)
->schema([
Forms\Components\TextInput::make('stripe_id')
->maxLength(255)
->disabled(),
Forms\Components\TextInput::make('pm_type')
->maxLength(255)
->disabled(),
Forms\Components\TextInput::make('pm_last_four')
->maxLength(4)
->disabled(),
Forms\Components\DateTimePicker::make('trial_ends_at')
->disabled(),
Forms\Components\TextInput::make('anystack_contact_id')
->maxLength(255)
->disabled(),
]),
Schemas\Components\Section::make('Developer Account')
->inlineLabel()
->columns(1)
->visible(fn (?User $record) => $record?->developerAccount !== null)
->schema([
Forms\Components\Select::make('developerAccount.stripe_connect_status')
->label('Stripe Connect Status')
->options(StripeConnectStatus::class)
->disabled(),
Forms\Components\Placeholder::make('developerAccount.stripe_connect_account_id')
->label('Stripe Connect Account')
->content(fn (User $record) => new HtmlString(
'<a href="https://dashboard.stripe.com/connect/accounts/'
.e($record->developerAccount->stripe_connect_account_id)
.'" target="_blank" class="text-primary-600 hover:underline">'
.e($record->developerAccount->stripe_connect_account_id)
.' ↗</a>'
)),
Forms\Components\Placeholder::make('developerAccount.country')
->label('Country')
->content(fn (User $record) => $record->developerAccount->country ?? '—'),
Forms\Components\Placeholder::make('developerAccount.payout_currency')
->label('Payout Currency')
->content(fn (User $record) => strtoupper($record->developerAccount->payout_currency ?? '—')),
Forms\Components\Placeholder::make('developerAccount.payouts_enabled')
->label('Payouts Enabled')
->content(fn (User $record) => $record->developerAccount->payouts_enabled ? 'Yes' : 'No'),
Forms\Components\Placeholder::make('developerAccount.charges_enabled')
->label('Charges Enabled')
->content(fn (User $record) => $record->developerAccount->charges_enabled ? 'Yes' : 'No'),
Forms\Components\Placeholder::make('developerAccount.onboarding_completed_at')
->label('Onboarding Completed')
->content(fn (User $record) => $record->developerAccount->onboarding_completed_at?->format('M j, Y g:i A') ?? '—'),
Forms\Components\Placeholder::make('developerAccount.accepted_plugin_terms_at')
->label('Plugin Terms Accepted')
->content(fn (User $record) => $record->developerAccount->accepted_plugin_terms_at?->format('M j, Y g:i A') ?? '—'),
Forms\Components\Placeholder::make('developerAccount.plugin_terms_version')
->label('Terms Version')
->content(fn (User $record) => $record->developerAccount->plugin_terms_version ?? '—'),
]),
]);
}
public static function table(Table $table): Table
{
return $table
->defaultSort('id', 'desc')
->columns([
Tables\Columns\TextColumn::make('id')
->sortable()
->searchable(),
Tables\Columns\TextColumn::make('email')
->searchable()
->copyable(),
Tables\Columns\TextColumn::make('name')
->searchable()
->copyable(),
Tables\Columns\TextColumn::make('stripe_id')
->hidden()
->searchable(),
Tables\Columns\TextColumn::make('anystack_contact_id')
->hidden()
->searchable(),
Tables\Columns\IconColumn::make('developerAccount.id')
->label('Developer')
->boolean()
->getStateUsing(fn (User $record) => $record->developerAccount !== null),
Tables\Columns\TextColumn::make('created_at')
->dateTime()
->sortable(),
Tables\Columns\TextColumn::make('updated_at')
->dateTime()
->sortable(),
])
->filters([
//
])
->actions([
Impersonate::make(),
Actions\ActionGroup::make([
Actions\EditAction::make(),
Actions\Action::make('view_on_stripe')
->label('View on Stripe')
->color('gray')
->icon('heroicon-o-arrow-top-right-on-square')
->url(fn (User $record) => 'https://dashboard.stripe.com/customers/'.$record->stripe_id)
->openUrlInNewTab()
->visible(fn (User $record) => filled($record->stripe_id)),
Actions\Action::make('view_on_anystack')
->label('View on Anystack')
->color('gray')
->icon('heroicon-o-arrow-top-right-on-square')
->url(fn (User $record) => 'https://app.anystack.sh/contacts/'.$record->anystack_contact_id)
->openUrlInNewTab()
->visible(fn (User $record) => filled($record->anystack_contact_id)),
])->label('Actions')->icon('heroicon-m-ellipsis-vertical'),
])
->bulkActions([
Actions\BulkActionGroup::make([
Actions\DeleteBulkAction::make(),
]),
])
->recordUrl(
fn ($record) => static::getUrl('edit', ['record' => $record])
);
}
public static function getRelations(): array
{
return [
RelationManagers\DeveloperPluginsRelationManager::class,
RelationManagers\PluginLicensesRelationManager::class,
RelationManagers\ProductLicensesRelationManager::class,
RelationManagers\LicensesRelationManager::class,
RelationManagers\SubscriptionsRelationManager::class,
];
}
public static function getPages(): array
{
return [
'index' => Pages\ListUsers::route('/'),
'create' => Pages\CreateUser::route('/create'),
'edit' => Pages\EditUser::route('/{record}/edit'),
];
}
}