F
Filament9mo ago
qilir

Open a Modal from inside of an Action

Forms\Components\Actions::make([
Forms\Components\Actions\Action::make('generateToken')
->label('Generate Token')
->button()
->hidden(fn(string $operation) => $operation === "create")
->requiresConfirmation(fn(Client $client) => $client->tokens()->exists())
->modalHeading('Generate new Token')
->modalDescription('Are you sure you want to generate a new Token? Existing ones will be deleted.')
->action(function (Client $client) {
$tokenName = $client->client_name;
$client->tokens()->delete();
$token = $client->createToken($tokenName, ['server:update'])->plainTextToken;

//show a modal that displays the plainTextToken
dump($token);

}),
]),
Forms\Components\Actions::make([
Forms\Components\Actions\Action::make('generateToken')
->label('Generate Token')
->button()
->hidden(fn(string $operation) => $operation === "create")
->requiresConfirmation(fn(Client $client) => $client->tokens()->exists())
->modalHeading('Generate new Token')
->modalDescription('Are you sure you want to generate a new Token? Existing ones will be deleted.')
->action(function (Client $client) {
$tokenName = $client->client_name;
$client->tokens()->delete();
$token = $client->createToken($tokenName, ['server:update'])->plainTextToken;

//show a modal that displays the plainTextToken
dump($token);

}),
]),
Hi, im currently building a small internal tool and thought it would be the perfect opportunity to give Filament a try, since I thought I didn't need any custom components :D Its my first time using either Filament or Livewire, so it might just be that this is a really stupid question. So I added an Action to my Edit-Form that generates a Sanctum API-Token, for us to be able to use the token, I want to display the plainTextToken once after generation, preferrably in a modal. Is there any way to open a modal that just shows the token from inside this action?
Solution:
Notification::make('api_key_notice')->title('Your API Key is')->body($apiKey)->send();
Notification::make('api_key_notice')->title('Your API Key is')->body($apiKey)->send();
...
Jump to solution
3 Replies
toeknee
toeknee9mo ago
For this, you would probably be better using the notification plugin with a long expiry
Solution
toeknee
toeknee9mo ago
Notification::make('api_key_notice')->title('Your API Key is')->body($apiKey)->send();
Notification::make('api_key_notice')->title('Your API Key is')->body($apiKey)->send();
qilir
qilirOP9mo ago
I guess that works, thank you! :)
Want results from more Discord servers?
Add your server