diff --git a/app/Http/Livewire/SlackSettingsForm.php b/app/Http/Livewire/SlackSettingsForm.php index d2760cb890..6ba3b5b1a9 100644 --- a/app/Http/Livewire/SlackSettingsForm.php +++ b/app/Http/Livewire/SlackSettingsForm.php @@ -11,7 +11,7 @@ class SlackSettingsForm extends Component public $webhook_endpoint; public $webhook_channel; public $webhook_botname; - public $isDisabled ='disabled' ; + public $isDisabled ='' ; public $webhook_name; public $webhook_link; public $webhook_placeholder; @@ -27,7 +27,6 @@ class SlackSettingsForm extends Component 'webhook_botname' => 'string|nullable', ]; - public function mount(){ $this->webhook_text= [ "slack" => array( @@ -45,6 +44,7 @@ class SlackSettingsForm extends Component ]; $this->setting = Setting::getSettings(); + $this->save_button = trans('general.save'); $this->webhook_selected = $this->setting->webhook_selected; $this->webhook_placeholder = $this->webhook_text[$this->setting->webhook_selected]["placeholder"]; $this->webhook_name = $this->webhook_text[$this->setting->webhook_selected]["name"]; @@ -54,6 +54,12 @@ class SlackSettingsForm extends Component $this->webhook_botname = $this->setting->webhook_botname; $this->webhook_options = $this->setting->webhook_selected; + if($this->setting->webhook_selected == 'general'){ + $this->isDisabled=''; + } + if($this->setting->webhook_endpoint != null && $this->setting->webhook_channel != null){ + $this->isDisabled= ''; + } } public function updated($field){ @@ -66,17 +72,28 @@ class SlackSettingsForm extends Component $this->webhook_icon = $this->webhook_text[$this->webhook_selected]["icon"]; ; $this->webhook_placeholder = $this->webhook_text[$this->webhook_selected]["placeholder"]; $this->webhook_link = $this->webhook_text[$this->webhook_selected]["link"]; - + if($this->webhook_selected != 'slack'){ + $this->isDisabled= ''; + $this->save_button = trans('general.save'); + } } + private function isButtonDisabled(){ + if($this->webhook_selected == 'slack') { + if (empty($this->webhook_endpoint)) { + $this->isDisabled = 'disabled'; + $this->save_button = trans('admin/settings/general.webhook_presave'); + } + if (empty($this->webhook_channel)) { + $this->isDisabled = 'disabled'; + $this->save_button = trans('admin/settings/general.webhook_presave'); + } + } + + } public function render() { - if(empty($this->webhook_channel || $this->webhook_endpoint)){ - $this->isDisabled= 'disabled'; - } - if(empty($this->webhook_endpoint && $this->webhook_channel)){ - $this->isDisabled= ''; - } + $this->isButtonDisabled(); return view('livewire.slack-settings-form'); } @@ -100,6 +117,7 @@ class SlackSettingsForm extends Component try { $webhook->post($this->webhook_endpoint, ['body' => $payload]); $this->isDisabled=''; + $this->save_button = trans('general.save'); return session()->flash('success' , 'Your '.$this->webhook_name.' Integration works!'); } catch (\Exception $e) { @@ -110,9 +128,21 @@ class SlackSettingsForm extends Component //} return session()->flash('message' , trans('admin/settings/message.webhook.error_misc')); - - } + + public function clearSettings(){ + $this->webhook_endpoint = ''; + $this->webhook_channel = ''; + $this->webhook_botname = ''; + $this->setting->webhook_endpoint = ''; + $this->setting->webhook_channel = ''; + $this->setting->webhook_botname = ''; + + $this->setting->save(); + + session()->flash('save',trans('admin/settings/message.update.success')); + } + public function submit() { if($this->webhook_selected != 'general') { @@ -124,11 +154,9 @@ class SlackSettingsForm extends Component $this->setting->webhook_channel = $this->webhook_channel; $this->setting->webhook_botname = $this->webhook_botname; - $this->setting->save(); session()->flash('save',trans('admin/settings/message.update.success')); - } } diff --git a/resources/lang/en/admin/settings/general.php b/resources/lang/en/admin/settings/general.php index 3316ed09ff..4c8bdcb629 100644 --- a/resources/lang/en/admin/settings/general.php +++ b/resources/lang/en/admin/settings/general.php @@ -202,6 +202,7 @@ return [ 'slack' => 'Slack', 'general_webhook' => 'General Webhook', 'webhook' => ':app', + 'webhook_presave' => 'Test to Save', 'webhook_title' => 'Update Webhook Settings', 'webhook_help' => 'Integration settings', 'webhook_botname' => ':app Botname', diff --git a/resources/views/livewire/slack-settings-form.blade.php b/resources/views/livewire/slack-settings-form.blade.php index ce6ba52c0e..e7a22978ff 100644 --- a/resources/views/livewire/slack-settings-form.blade.php +++ b/resources/views/livewire/slack-settings-form.blade.php @@ -13,9 +13,6 @@ @section('content')
-
- {{csrf_field()}} -
@@ -34,7 +31,7 @@
-
+
@if (session()->has('save'))
{{session('save')}} @@ -58,66 +55,72 @@ @endif -
+
-
+
+


+ + {{csrf_field()}} - -
- -
- {{ Form::label('webhook_endpoint', trans('admin/settings/general.webhook_endpoint',['app' => ucwords($webhook_selected) ])) }} + +
+
+ {{ Form::label('webhook_endpoint', trans('admin/settings/general.webhook_endpoint',['app' => $webhook_name ])) }} +
+
+ @if (config('app.lock_passwords')===true) +

{{ trans('general.feature_disabled') }}

+ + @else + + @endif + {!! $errors->first('webhook_endpoint', '') !!} +
-
- @if (config('app.lock_passwords')===true) -

- - {{ trans('general.feature_disabled') }} -

- - @else - - @endif - {!! $errors->first('webhook_endpoint', ':message') !!} -
-
+ +
+
+ {{ Form::label('webhook_channel', trans('admin/settings/general.webhook_channel',['app' => $webhook_name ])) }} +
+
+ @if (config('app.lock_passwords')===true) + +

{{ trans('general.feature_disabled') }}

- -
-
- {{ Form::label('webhook_channel', trans('admin/settings/general.webhook_channel',['app' => ucwords($webhook_selected) ])) }} + @else + + @endif + {!! $errors->first('webhook_channel', '') !!} +
-
- - @if (config('app.lock_passwords')===true) - -

- {{ trans('general.feature_disabled') }}

- @else - - @endif - {!! $errors->first('webhook_channel', ':message') !!} -
- -
-
-
- {{ Form::label('webhook_botname', trans('admin/settings/general.webhook_botname',['app' => ucwords($webhook_selected) ])) }} +
+
+ {{ Form::label('webhook_botname', trans('admin/settings/general.webhook_botname',['app' => $webhook_name ])) }}
@if (config('app.lock_passwords')===true) @@ -127,7 +130,8 @@ {{ trans('general.feature_disabled') }}

@else - + @endif {!! $errors->first('webhook_botname', '') !!}
@@ -136,9 +140,8 @@ @if($webhook_selected == 'slack') @if($webhook_endpoint != null && $webhook_channel != null) -
- @endif @@ -157,17 +159,20 @@ + +
-
- +
+
-