This commit is contained in:
38
app/Livewire/ViewBot.php
Normal file
38
app/Livewire/ViewBot.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Livewire;
|
||||
|
||||
use App\Jobs\RunBot;
|
||||
use App\Models\Bot;
|
||||
use Jantinnerezo\LivewireAlert\Facades\LivewireAlert;
|
||||
use Livewire\Component;
|
||||
|
||||
class ViewBot extends Component
|
||||
{
|
||||
public Bot $bot;
|
||||
|
||||
public function runBot()
|
||||
{
|
||||
LivewireAlert::title('Are you sure you want to run ' . $this->bot->name . '?')
|
||||
->asConfirm()
|
||||
->onConfirm('confirmRunBot')
|
||||
->show();
|
||||
}
|
||||
|
||||
public function confirmRunBot(): void
|
||||
{
|
||||
$log = $this->bot->logs()->create([
|
||||
'status' => 'pending',
|
||||
]);
|
||||
|
||||
// Dispatch the job to run the bot
|
||||
dispatch(new RunBot($this->bot, $log));
|
||||
|
||||
flash()->success("Bot '{$this->bot->name}' is being executed.");
|
||||
}
|
||||
|
||||
public function render()
|
||||
{
|
||||
return view('livewire.view-bot');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user