Skip to content

Commit a3088ea

Browse files
authored
Move user actions to action group (#142)
* move user actions to action group * pint
1 parent 26e9003 commit a3088ea

File tree

2 files changed

+86
-63
lines changed

2 files changed

+86
-63
lines changed

app/Filament/Resources/UserResource.php

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,23 @@ public static function table(Table $table): Table
8686
//
8787
])
8888
->actions([
89-
Tables\Actions\EditAction::make(),
90-
Tables\Actions\Action::make('view_on_stripe')
91-
->label('View on Stripe')
92-
->color('gray')
93-
->icon('heroicon-o-arrow-top-right-on-square')
94-
->url(fn (User $record) => 'https://dashboard.stripe.com/customers/'.$record->stripe_id)
95-
->openUrlInNewTab()
96-
->visible(fn (User $record) => filled($record->stripe_id)),
97-
Tables\Actions\Action::make('view_on_anystack')
98-
->label('View on Anystack')
99-
->color('gray')
100-
->icon('heroicon-o-arrow-top-right-on-square')
101-
->url(fn (User $record) => 'https://app.anystack.sh/contacts/'.$record->anystack_contact_id)
102-
->openUrlInNewTab()
103-
->visible(fn (User $record) => filled($record->anystack_contact_id)),
89+
Tables\Actions\ActionGroup::make([
90+
Tables\Actions\EditAction::make(),
91+
Tables\Actions\Action::make('view_on_stripe')
92+
->label('View on Stripe')
93+
->color('gray')
94+
->icon('heroicon-o-arrow-top-right-on-square')
95+
->url(fn (User $record) => 'https://dashboard.stripe.com/customers/'.$record->stripe_id)
96+
->openUrlInNewTab()
97+
->visible(fn (User $record) => filled($record->stripe_id)),
98+
Tables\Actions\Action::make('view_on_anystack')
99+
->label('View on Anystack')
100+
->color('gray')
101+
->icon('heroicon-o-arrow-top-right-on-square')
102+
->url(fn (User $record) => 'https://app.anystack.sh/contacts/'.$record->anystack_contact_id)
103+
->openUrlInNewTab()
104+
->visible(fn (User $record) => filled($record->anystack_contact_id)),
105+
])->label('Actions')->icon('heroicon-m-ellipsis-vertical'),
104106
])
105107
->bulkActions([
106108
Tables\Actions\BulkActionGroup::make([

app/Filament/Resources/UserResource/Pages/EditUser.php

Lines changed: 69 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -15,60 +15,81 @@ class EditUser extends EditRecord
1515
protected function getHeaderActions(): array
1616
{
1717
return [
18-
Actions\Action::make('createStripeCustomer')
19-
->label('Create Stripe Customer')
20-
->color('gray')
21-
->icon('heroicon-o-credit-card')
22-
->action(function (User $record) {
23-
if ($record->hasStripeId()) {
24-
Notification::make()
25-
->danger()
26-
->title('User is already a Stripe customer.')
27-
->send();
18+
Actions\ActionGroup::make([
19+
Actions\Action::make('createStripeCustomer')
20+
->label('Create Stripe Customer')
21+
->color('gray')
22+
->icon('heroicon-o-credit-card')
23+
->action(function (User $record) {
24+
if ($record->hasStripeId()) {
25+
Notification::make()
26+
->danger()
27+
->title('User is already a Stripe customer.')
28+
->send();
2829

29-
return;
30-
}
30+
return;
31+
}
3132

32-
$record->createOrGetStripeCustomer();
33-
})
34-
->visible(fn (User $record) => empty($record->stripe_id)),
33+
$record->createOrGetStripeCustomer();
34+
})
35+
->visible(fn (User $record) => empty($record->stripe_id)),
3536

36-
Actions\Action::make('createAnystackLicense')
37-
->label('Create Anystack License')
38-
->color('gray')
39-
->icon('heroicon-o-key')
40-
->form([
41-
\Filament\Forms\Components\Select::make('subscription')
42-
->label('Subscription Plan')
43-
->options(collect(\App\Enums\Subscription::cases())->mapWithKeys(function ($case) {
44-
return [$case->value => $case->name()];
45-
}))
46-
->required(),
47-
])
48-
->action(function (array $data, User $record) {
49-
$subscription = \App\Enums\Subscription::from($data['subscription']);
37+
Actions\Action::make('createAnystackLicense')
38+
->label('Create Anystack License')
39+
->color('gray')
40+
->icon('heroicon-o-key')
41+
->form([
42+
\Filament\Forms\Components\Select::make('subscription')
43+
->label('Subscription Plan')
44+
->options(collect(\App\Enums\Subscription::cases())->mapWithKeys(function ($case) {
45+
return [$case->value => $case->name()];
46+
}))
47+
->required(),
48+
])
49+
->action(function (array $data, User $record) {
50+
$subscription = \App\Enums\Subscription::from($data['subscription']);
5051

51-
\App\Jobs\CreateAnystackLicenseJob::dispatch(
52-
$record,
53-
$subscription,
54-
null,
55-
$record->first_name,
56-
$record->last_name,
57-
);
58-
}),
52+
\App\Jobs\CreateAnystackLicenseJob::dispatch(
53+
$record,
54+
$subscription,
55+
null,
56+
$record->first_name,
57+
$record->last_name,
58+
);
59+
}),
5960

60-
Actions\Action::make('sendPasswordReset')
61-
->label('Send Password Reset')
62-
->color('gray')
63-
->icon('heroicon-o-envelope')
64-
->requiresConfirmation()
65-
->action(function (User $record) {
66-
\Illuminate\Support\Facades\Password::sendResetLink(
67-
['email' => $record->email]
68-
);
69-
}),
61+
Actions\Action::make('sendPasswordReset')
62+
->label('Send Password Reset')
63+
->color('gray')
64+
->icon('heroicon-o-envelope')
65+
->requiresConfirmation()
66+
->action(function (User $record) {
67+
\Illuminate\Support\Facades\Password::sendResetLink(
68+
['email' => $record->email]
69+
);
70+
}),
7071

71-
Actions\DeleteAction::make(),
72+
Actions\Action::make('view_on_stripe')
73+
->label('View on Stripe')
74+
->color('gray')
75+
->icon('heroicon-o-arrow-top-right-on-square')
76+
->url(fn (User $record) => 'https://dashboard.stripe.com/customers/'.$record->stripe_id)
77+
->openUrlInNewTab()
78+
->visible(fn (User $record) => filled($record->stripe_id)),
79+
80+
Actions\Action::make('view_on_anystack')
81+
->label('View on Anystack')
82+
->color('gray')
83+
->icon('heroicon-o-arrow-top-right-on-square')
84+
->url(fn (User $record) => 'https://app.anystack.sh/contacts/'.$record->anystack_contact_id)
85+
->openUrlInNewTab()
86+
->visible(fn (User $record) => filled($record->anystack_contact_id)),
87+
88+
Actions\DeleteAction::make(),
89+
90+
])
91+
->label('Actions')
92+
->icon('heroicon-m-ellipsis-vertical'),
7293
];
7394
}
7495
}

0 commit comments

Comments
 (0)