|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Usamamuneerchaudhary\Notifier\Filament\Resources\NotificationEventResource\Schemas; |
|
4
|
|
|
|
|
5
|
|
|
use Filament\Forms\Components\KeyValue; |
|
6
|
|
|
use Filament\Forms\Components\Textarea; |
|
7
|
|
|
use Filament\Forms\Components\TextInput; |
|
8
|
|
|
use Filament\Forms\Components\Toggle; |
|
9
|
|
|
use Filament\Schemas\Components\Section; |
|
10
|
|
|
use Filament\Schemas\Schema; |
|
11
|
|
|
|
|
12
|
|
|
class NotificationEventForm |
|
13
|
|
|
{ |
|
14
|
|
|
public static function configure(Schema $schema): Schema |
|
15
|
|
|
{ |
|
16
|
|
|
return $schema |
|
17
|
|
|
->components([ |
|
18
|
|
|
Section::make('Event Information') |
|
19
|
|
|
->description('Basic information about the notification event') |
|
20
|
|
|
->schema([ |
|
21
|
|
|
TextInput::make('group') |
|
22
|
|
|
->label('Event Group') |
|
23
|
|
|
->helperText('Organize events into groups (e.g., "Users", "Projects", "Orders", "Files"). This helps categorize events in the admin panel.') |
|
24
|
|
|
->placeholder('Users') |
|
25
|
|
|
->required() |
|
26
|
|
|
->maxLength(255) |
|
27
|
|
|
->columnSpanFull(), |
|
28
|
|
|
|
|
29
|
|
|
TextInput::make('name') |
|
30
|
|
|
->label('Event Name') |
|
31
|
|
|
->helperText('A friendly display name for this event (e.g., "User Registered", "Order Completed", "Project Created")') |
|
32
|
|
|
->placeholder('User Registered') |
|
33
|
|
|
->required() |
|
34
|
|
|
->maxLength(255) |
|
35
|
|
|
->columnSpanFull(), |
|
36
|
|
|
|
|
37
|
|
|
TextInput::make('key') |
|
38
|
|
|
->label('Event Key') |
|
39
|
|
|
->helperText('Unique identifier used to trigger this event in code. Use dot notation (e.g., user.registered, order.completed, project.created). This key is used when calling Notifier::send($user, "event.key", $data)') |
|
40
|
|
|
->placeholder('user.registered') |
|
41
|
|
|
->required() |
|
42
|
|
|
->unique(ignoreRecord: true) |
|
43
|
|
|
->maxLength(255) |
|
44
|
|
|
->columnSpanFull(), |
|
45
|
|
|
|
|
46
|
|
|
Textarea::make('description') |
|
47
|
|
|
->label('Description') |
|
48
|
|
|
->helperText('Describe when and why this event is triggered. This helps other developers understand the event\'s purpose.') |
|
49
|
|
|
->placeholder('Triggered when a new user successfully registers an account') |
|
50
|
|
|
->maxLength(65535) |
|
51
|
|
|
->rows(4) |
|
52
|
|
|
->columnSpanFull(), |
|
53
|
|
|
|
|
54
|
|
|
Toggle::make('is_active') |
|
55
|
|
|
->label('Active') |
|
56
|
|
|
->helperText('Enable or disable this event. Inactive events will not trigger notifications even if called in code.') |
|
57
|
|
|
->default(true) |
|
58
|
|
|
->inline(false) |
|
59
|
|
|
->columnSpanFull(), |
|
60
|
|
|
]) |
|
61
|
|
|
->columns(2), |
|
62
|
|
|
|
|
63
|
|
|
Section::make('Event Configuration') |
|
64
|
|
|
->description('Configure which channels and templates to use for this event. You can also configure this in config/notifier.php. Note: This requires running the migration to add the settings column.') |
|
65
|
|
|
->collapsible() |
|
66
|
|
|
->collapsed() |
|
67
|
|
|
->schema([ |
|
68
|
|
|
KeyValue::make('settings') |
|
69
|
|
|
->label('Event Settings') |
|
70
|
|
|
->keyLabel('Setting Name') |
|
71
|
|
|
->valueLabel('Setting Value') |
|
72
|
|
|
->helperText('Optional: Configure event-specific settings. Common settings include "channels" (array of channel types) and "template" (template key). You can also configure these in config/notifier.php. Note: Run migrations to add the settings column if you see an error.') |
|
73
|
|
|
->addable(true) |
|
74
|
|
|
->deletable(true) |
|
75
|
|
|
->reorderable() |
|
76
|
|
|
->columnSpanFull(), |
|
77
|
|
|
]), |
|
78
|
|
|
|
|
79
|
|
|
Section::make('Event Examples') |
|
80
|
|
|
->description('Common event examples. Click to expand and see how events are structured.') |
|
81
|
|
|
->collapsible() |
|
82
|
|
|
->collapsed() |
|
83
|
|
|
->schema([ |
|
84
|
|
|
Textarea::make('user_event_example') |
|
85
|
|
|
->label('User Events Example') |
|
86
|
|
|
->default("Group: Users\nName: User Registered\nKey: user.registered\nDescription: Triggered when a new user successfully registers an account\n\nGroup: Users\nName: Password Reset\nKey: user.password_reset\nDescription: Triggered when a user requests a password reset") |
|
87
|
|
|
->disabled() |
|
88
|
|
|
->dehydrated(false) |
|
89
|
|
|
->rows(6) |
|
90
|
|
|
->columnSpanFull(), |
|
91
|
|
|
|
|
92
|
|
|
Textarea::make('order_event_example') |
|
93
|
|
|
->label('Order Events Example') |
|
94
|
|
|
->default("Group: Orders\nName: Order Completed\nKey: order.completed\nDescription: Triggered when an order is successfully completed\n\nGroup: Orders\nName: Order Shipped\nKey: order.shipped\nDescription: Triggered when an order is shipped to the customer") |
|
95
|
|
|
->disabled() |
|
96
|
|
|
->dehydrated(false) |
|
97
|
|
|
->rows(6) |
|
98
|
|
|
->columnSpanFull(), |
|
99
|
|
|
|
|
100
|
|
|
Textarea::make('project_event_example') |
|
101
|
|
|
->label('Project Events Example') |
|
102
|
|
|
->default("Group: Projects\nName: Project Created\nKey: project.created\nDescription: Triggered when a new project is created\n\nGroup: Projects\nName: Project Updated\nKey: project.updated\nDescription: Triggered when a project is updated") |
|
103
|
|
|
->disabled() |
|
104
|
|
|
->dehydrated(false) |
|
105
|
|
|
->rows(6) |
|
106
|
|
|
->columnSpanFull(), |
|
107
|
|
|
]), |
|
108
|
|
|
]); |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|