--- title: NotificationEditor Component --- # NotificationEditor Component The NotificationEditor component provides an interface for configuring form email notifications. ## Basic Usage ```blade ``` ## Properties | Property | Type | Default | Description | |----------|------|---------|-------------| | `form` | Form | required | Form to configure | ## Features - Create admin and autoresponder notifications - Configure recipients (static or from field) - Set from address and reply-to - Configure CC and BCC - Edit subject and message with placeholders - Set conditional send rules - Test notifications ## Component Structure ```blade
{{-- Notifications List --}}
@foreach ($form->notifications as $notification)
{{ $notification->type }} {{ $notification->name }} {{ $notification->is_active ? 'Active' : 'Inactive' }}
@endforeach
{{-- Add Notification --}}
{{-- Edit Modal --}} @if ($editingNotification)
{{-- Basic Settings --}}

Basic Settings

{{-- Recipients --}}

Recipients

@if ($notification['recipient_type'] === 'static') @else @endif
{{-- From Address --}}

From Address

{{-- Reply-To --}}

Reply-To

@if ($notification['reply_to_type'] === 'static') @else @endif
{{-- Content --}}

Email Content

Available Placeholders: {form_name}, {submission_number}, @foreach ($form->fields as $field) {{ '{' . $field->name . '}' }}, @endforeach
{{-- Conditions --}}

Conditions (Optional)

@include('forms::partials.condition-builder', ['conditions' => $notification['conditions']])
{{-- Actions --}}
@endif
``` ## Methods ### addNotification Add a new notification: ```php public function addNotification(string $type): void { $this->editingNotification = true; $this->notification = [ 'type' => $type, 'name' => $type === 'admin' ? 'Admin Notification' : 'Confirmation Email', 'is_active' => true, 'recipient_type' => $type === 'admin' ? 'static' : 'field', 'recipients' => '', 'recipient_field' => '', 'cc' => '', 'bcc' => '', 'from_email' => config('artisanpack.forms.notifications.from_email'), 'from_name' => config('artisanpack.forms.notifications.from_name'), 'reply_to_type' => 'field', 'reply_to_email' => '', 'reply_to_field' => 'email', 'subject' => $type === 'admin' ? 'New submission: {form_name}' : 'Thank you for your submission', 'message' => '', 'include_submission_data' => $type === 'admin', 'conditions' => null, ]; } ``` ### save Save the notification: ```php public function save(): void { $this->validate([ 'notification.name' => 'required|string|max:255', 'notification.subject' => 'required|string|max:255', 'notification.recipients' => 'required_if:notification.recipient_type,static', 'notification.recipient_field' => 'required_if:notification.recipient_type,field', ]); if (isset($this->notification['id'])) { $notificationModel = FormNotification::find($this->notification['id']); $notificationModel->update($this->notification); } else { $this->notification['form_id'] = $this->form->id; FormNotification::create($this->notification); } $this->form->refresh(); $this->editingNotification = false; session()->flash('success', 'Notification saved.'); } ``` ### sendTest Send a test email: ```php public function sendTest(): void { $this->validate([ 'testEmail' => 'required|email', ]); $this->notificationService->sendTest( new FormNotification($this->notification), $this->testEmail ); session()->flash('success', 'Test email sent.'); } ``` ### delete Delete a notification: ```php public function delete(int $id): void { $notification = FormNotification::findOrFail($id); $notification->delete(); $this->form->refresh(); session()->flash('success', 'Notification deleted.'); } ``` ## Events Emitted | Event | Payload | Description | |-------|---------|-------------| | `notification-saved` | `{ id }` | Notification saved | | `notification-deleted` | `{ id }` | Notification deleted | | `test-sent` | `{ email }` | Test email sent | ## Customizing the View Publish views: ```bash php artisan vendor:publish --tag=forms-views ``` Edit `resources/views/vendor/forms/livewire/notification-editor.blade.php`. ## Next Steps - [Notifications Usage](../usage/notifications.md) - Email notification guide - [FormBuilder](./form-builder.md) - Form builder component