diff --git a/app/Concerns/Confirmation.php b/app/Concerns/Confirmation.php new file mode 100644 index 0000000..6e37799 --- /dev/null +++ b/app/Concerns/Confirmation.php @@ -0,0 +1,65 @@ +dispatch( + 'open-confirmation', + componentId: $this->getId(), + action: $method, + params: $params, + title: $title, + subtitle: $subtitle, + description: $description, + descriptionClass: $descriptionClass, + acceptBtnClass: $acceptBtnClass, + icon: $icon + ); + } + + /** + * Listen globally for the acceptance, but only process if the ID matches. + */ + #[On('confirmation-accepted')] + public function onConfirmationAccepted(string $action, mixed $params, string $componentId): void + { + // Ignore the event if it wasn't requested by this specific component instance + if ($this->getId() !== $componentId) { + return; + } + + // Verify the method actually exists on the component + if (method_exists($this, $action)) { + + // Execute the requested method, passing any provided parameters + $this->{$action}($params); + } + } +} diff --git a/captainhook.json b/captainhook.json index 91c361d..2bda658 100644 --- a/captainhook.json +++ b/captainhook.json @@ -5,7 +5,7 @@ { "action": "\\CaptainHook\\App\\Hook\\Message\\Action\\Beams", "options": { - "subjectLength": 50, + "subjectLength": 100, "bodyLineLength": 300 } } diff --git a/resources/views/components/⚡confirmation-modal.blade.php b/resources/views/components/⚡confirmation-modal.blade.php new file mode 100644 index 0000000..53f9989 --- /dev/null +++ b/resources/views/components/⚡confirmation-modal.blade.php @@ -0,0 +1,97 @@ +action = $action; + $this->componentId = $componentId; + $this->title = $title; + $this->subtitle = $subtitle; + $this->description = $description; + $this->params = $params; + + $this->descriptionClass = $descriptionClass; + $this->acceptBtnClass = $acceptBtnClass; + $this->icon = $icon; + + $this->open = true; + } + + public function confirm(): void + { + $this->open = false; + + $this->dispatch('confirmation-accepted', + action: $this->action, + params: $this->params, + componentId: $this->componentId + ); + } + + public function getMergedAlertClass(): string + { + return TailwindMerge::factory()->make()->merge( + 'alert-warning alert-soft text-red-600', + $this->descriptionClass + ); + } + + public function getMergedButtonClass(): string + { + return TailwindMerge::factory()->make()->merge( + 'btn-warning', + $this->acceptBtnClass + ); + } +} +?> +
+ + @isset($description) + + {{ $description }} + + @endisset + + + + + + +
diff --git a/resources/views/layouts/app/sidebar.blade.php b/resources/views/layouts/app/sidebar.blade.php index 0fc30e8..2940e54 100644 --- a/resources/views/layouts/app/sidebar.blade.php +++ b/resources/views/layouts/app/sidebar.blade.php @@ -15,6 +15,7 @@ + @livewireScripts