diff --git a/app/Http/Controllers/Api/SettingsController.php b/app/Http/Controllers/Api/SettingsController.php index 26d380353f..d0f7fea602 100644 --- a/app/Http/Controllers/Api/SettingsController.php +++ b/app/Http/Controllers/Api/SettingsController.php @@ -143,37 +143,6 @@ class SettingsController extends Controller } - public function slacktest($slack_endpoint,$slack_channel,$slack_botname) - { - // If validation passes, continue to the curl request - $slack = new Client([ - 'base_url' => e($slack_endpoint), - 'defaults' => [ - 'exceptions' => false, - ], - ]); - - $payload = json_encode( - [ - 'channel' => e($slack_channel), - 'text' => trans('general.slack_test_msg'), - 'username' => e($slack_botname), - 'icon_emoji' => ':heart:', - ]); - - try { - $slack->post($slack_endpoint, ['body' => $payload]); - return response()->json(['message' => 'Success'], 200); - - } catch (\Exception $e) { - return response()->json(['message' => 'Please check the channel name and webhook endpoint URL ('.e($slack_endpoint).'). Slack responded with: '.$e->getMessage()], 400); - } - - //} - return response()->json(['message' => 'Something went wrong :( '], 400); - } - - /** * Test the email configuration * diff --git a/app/Http/Livewire/SlackSettingsForm.php b/app/Http/Livewire/SlackSettingsForm.php index fbc54a0517..9e83087112 100644 --- a/app/Http/Livewire/SlackSettingsForm.php +++ b/app/Http/Livewire/SlackSettingsForm.php @@ -2,9 +2,9 @@ namespace App\Http\Livewire; +use GuzzleHttp\Client; use Livewire\Component; use App\Models\Setting; -use App\Http\Controllers\Api\SettingsController; class SlackSettingsForm extends Component { @@ -28,8 +28,35 @@ class SlackSettingsForm extends Component return view('livewire.slack-settings-form'); } - public function testSlack($slack_endpoint, $slack_channel, $slack_botname){ - SettingsController::testSlack($slack_endpoint,$slack_channel,$slack_botname); + public function testSlack(){ + + // If validation passes, continue to the curl request + $slack = new Client([ + 'base_url' => e($this->slack_endpoint), + 'defaults' => [ + 'exceptions' => false, + ], + ]); + + $payload = json_encode( + [ + 'channel' => e($this->slack_channel), + 'text' => trans('general.slack_test_msg'), + 'username' => e($this->slack_botname), + 'icon_emoji' => ':heart:', + ]); + + try { + $slack->post($this->slack_endpoint, ['body' => $payload]); + return session()->flash('success' , 'Your Slack Integration works!'); + + } catch (\Exception $e) { + return session()->flash('error' , 'Please check the channel name and webhook endpoint URL ('.e($this->slack_endpoint).'). Slack responded with: '.$e->getMessage()); + } + + //} + return session()->flash('message' , 'Something went wrong :( '); + } @@ -47,7 +74,7 @@ class SlackSettingsForm extends Component $this->setting->save(); - session()->flash('message',trans('admin/settings/message.update.success')); + session()->flash('save',trans('admin/settings/message.update.success')); } diff --git a/app/Http/Requests/SlackSettingsRequest.php b/app/Http/Requests/SlackSettingsRequest.php deleted file mode 100644 index e8f7d2f0ea..0000000000 --- a/app/Http/Requests/SlackSettingsRequest.php +++ /dev/null @@ -1,32 +0,0 @@ - 'url|required_with:slack_channel|starts_with:"https://hooks.slack.com"|nullable', - 'slack_channel' => 'required_with:slack_endpoint|starts_with:#|nullable', - 'slack_botname' => 'string|nullable', - ]; - } - - -} diff --git a/resources/views/livewire/slack-settings-form.blade.php b/resources/views/livewire/slack-settings-form.blade.php index 6562f41b33..0335b6d0cc 100644 --- a/resources/views/livewire/slack-settings-form.blade.php +++ b/resources/views/livewire/slack-settings-form.blade.php @@ -1,11 +1,26 @@
{{ trans('general.feature_disabled') }}
@else -