-
-
Notifications
You must be signed in to change notification settings - Fork 108
Expand file tree
/
Copy pathUserResource.php
More file actions
140 lines (132 loc) · 5.51 KB
/
UserResource.php
File metadata and controls
140 lines (132 loc) · 5.51 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
<?php
namespace App\Filament\Resources;
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 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
->schema([
Schemas\Components\Section::make('User Information')
->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),
])->columns(2),
Schemas\Components\Section::make('Billing Information')
->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(),
])->columns(2),
]);
}
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\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\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'),
];
}
}