Skip to content

Commit 39a7332

Browse files
committed
refactored: webhooks view
1 parent 2182587 commit 39a7332

File tree

2 files changed

+38
-30
lines changed

2 files changed

+38
-30
lines changed

app/Livewire/Project/Shared/Webhooks.php

Lines changed: 33 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,59 @@
44

55
use Livewire\Component;
66

7+
// Refactored ✅
78
class Webhooks extends Component
89
{
910
public $resource;
1011

11-
public ?string $deploywebhook = null;
12+
public string $deploywebhook;
1213

13-
public ?string $githubManualWebhook = null;
14+
public string $githubManualWebhook;
1415

15-
public ?string $gitlabManualWebhook = null;
16+
public string $gitlabManualWebhook;
1617

17-
public ?string $bitbucketManualWebhook = null;
18+
public string $bitbucketManualWebhook;
1819

19-
public ?string $giteaManualWebhook = null;
20+
public string $giteaManualWebhook;
2021

21-
protected $rules = [
22-
'resource.manual_webhook_secret_github' => 'nullable|string',
23-
'resource.manual_webhook_secret_gitlab' => 'nullable|string',
24-
'resource.manual_webhook_secret_bitbucket' => 'nullable|string',
25-
'resource.manual_webhook_secret_gitea' => 'nullable|string',
26-
];
22+
public ?string $githubManualWebhookSecret = null;
2723

28-
public function saveSecret()
29-
{
30-
try {
31-
$this->validate();
32-
$this->resource->save();
33-
$this->dispatch('success', 'Secret Saved.');
34-
} catch (\Exception $e) {
35-
return handleError($e, $this);
36-
}
37-
}
24+
public ?string $gitlabManualWebhookSecret = null;
25+
26+
public ?string $bitbucketManualWebhookSecret = null;
27+
28+
public ?string $giteaManualWebhookSecret = null;
3829

3930
public function mount()
4031
{
4132
$this->deploywebhook = generateDeployWebhook($this->resource);
33+
34+
$this->githubManualWebhookSecret = data_get($this->resource, 'manual_webhook_secret_github');
4235
$this->githubManualWebhook = generateGitManualWebhook($this->resource, 'github');
36+
37+
$this->gitlabManualWebhookSecret = data_get($this->resource, 'manual_webhook_secret_gitlab');
4338
$this->gitlabManualWebhook = generateGitManualWebhook($this->resource, 'gitlab');
39+
40+
$this->bitbucketManualWebhookSecret = data_get($this->resource, 'manual_webhook_secret_bitbucket');
4441
$this->bitbucketManualWebhook = generateGitManualWebhook($this->resource, 'bitbucket');
42+
43+
$this->giteaManualWebhookSecret = data_get($this->resource, 'manual_webhook_secret_gitea');
4544
$this->giteaManualWebhook = generateGitManualWebhook($this->resource, 'gitea');
4645
}
4746

48-
public function render()
47+
public function submit()
4948
{
50-
return view('livewire.project.shared.webhooks');
49+
try {
50+
$this->authorize('update', $this->resource);
51+
$this->resource->update([
52+
'manual_webhook_secret_github' => $this->githubManualWebhookSecret,
53+
'manual_webhook_secret_gitlab' => $this->gitlabManualWebhookSecret,
54+
'manual_webhook_secret_bitbucket' => $this->bitbucketManualWebhookSecret,
55+
'manual_webhook_secret_gitea' => $this->giteaManualWebhookSecret,
56+
]);
57+
$this->dispatch('success', 'Secret Saved.');
58+
} catch (\Exception $e) {
59+
return handleError($e, $this);
60+
}
5161
}
5262
}

resources/views/livewire/project/shared/webhooks.blade.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
<div>
1414
<h3>Manual Git Webhooks</h3>
1515
@if ($githubManualWebhook && $gitlabManualWebhook)
16-
<form wire:submit='saveSecret' class="flex flex-col gap-2">
16+
<form wire:submit='submit' class="flex flex-col gap-2">
1717
<div class="flex items-end gap-2">
1818
<x-forms.input helper="Content Type in GitHub configuration could be json or form-urlencoded."
1919
readonly label="GitHub" id="githubManualWebhook"></x-forms.input>
2020
<x-forms.input type="password"
2121
helper="Need to set a secret to be able to use this webhook. It should match with the secret in GitHub."
22-
label="GitHub Webhook Secret" id="resource.manual_webhook_secret_github"></x-forms.input>
22+
label="GitHub Webhook Secret" id="githubManualWebhookSecret"></x-forms.input>
2323

2424
</div>
2525
<a target="_blank" class="flex hover:no-underline" href="{{ $resource?->gitWebhook }}">
@@ -31,21 +31,19 @@
3131
<x-forms.input readonly label="GitLab" id="gitlabManualWebhook"></x-forms.input>
3232
<x-forms.input type="password"
3333
helper="Need to set a secret to be able to use this webhook. It should match with the secret in GitLab."
34-
label="GitLab Webhook Secret" id="resource.manual_webhook_secret_gitlab"></x-forms.input>
34+
label="GitLab Webhook Secret" id="gitlabManualWebhookSecret"></x-forms.input>
3535
</div>
3636
<div class="flex gap-2">
3737
<x-forms.input readonly label="Bitbucket" id="bitbucketManualWebhook"></x-forms.input>
3838
<x-forms.input type="password"
3939
helper="Need to set a secret to be able to use this webhook. It should match with the secret in Bitbucket."
40-
label="Bitbucket Webhook Secret"
41-
id="resource.manual_webhook_secret_bitbucket"></x-forms.input>
40+
label="Bitbucket Webhook Secret" id="bitbucketManualWebhookSecret"></x-forms.input>
4241
</div>
4342
<div class="flex gap-2">
4443
<x-forms.input readonly label="Gitea" id="giteaManualWebhook"></x-forms.input>
4544
<x-forms.input type="password"
4645
helper="Need to set a secret to be able to use this webhook. It should match with the secret in Gitea."
47-
label="Gitea Webhook Secret"
48-
id="resource.manual_webhook_secret_gitea"></x-forms.input>
46+
label="Gitea Webhook Secret" id="giteaManualWebhookSecret"></x-forms.input>
4947
</div>
5048
<x-forms.button type="submit">Save</x-forms.button>
5149
</form>

0 commit comments

Comments
 (0)