|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Usamamuneerchaudhary\Notifier\Filament\Resources\NotificationTemplateResource\Schemas; |
|
4
|
|
|
|
|
5
|
|
|
use Filament\Forms\Components\KeyValue; |
|
6
|
|
|
use Filament\Forms\Components\Select; |
|
7
|
|
|
use Filament\Forms\Components\Textarea; |
|
8
|
|
|
use Filament\Forms\Components\TextInput; |
|
9
|
|
|
use Filament\Forms\Components\Toggle; |
|
10
|
|
|
use Filament\Schemas\Components\Section; |
|
11
|
|
|
use Filament\Schemas\Schema; |
|
12
|
|
|
use Usamamuneerchaudhary\Notifier\Models\NotificationEvent; |
|
13
|
|
|
|
|
14
|
|
|
class NotificationTemplateForm |
|
15
|
|
|
{ |
|
16
|
|
|
public static function configure(Schema $schema): Schema |
|
17
|
|
|
{ |
|
18
|
|
|
return $schema |
|
19
|
|
|
->components([ |
|
20
|
|
|
Section::make('Template Information') |
|
21
|
|
|
->description('Basic information about the notification template') |
|
22
|
|
|
->schema([ |
|
23
|
|
|
TextInput::make('name') |
|
24
|
|
|
->label('Template Name') |
|
25
|
|
|
->helperText('A friendly display name for this template (e.g., "Welcome Email", "Order Confirmation"). This is also used as the unique identifier to reference the template in code.') |
|
26
|
|
|
->placeholder('welcome-email') |
|
27
|
|
|
->required() |
|
28
|
|
|
->unique(ignoreRecord: true) |
|
29
|
|
|
->maxLength(255) |
|
30
|
|
|
->columnSpanFull(), |
|
31
|
|
|
|
|
32
|
|
|
Select::make('event_key') |
|
33
|
|
|
->label('Linked Event') |
|
34
|
|
|
->helperText('Link this template to a specific notification event. This is required and helps organize templates. The template will be used when this event is triggered.') |
|
35
|
|
|
->options(fn() => NotificationEvent::where('is_active', true)->pluck('name', 'key')->toArray()) |
|
36
|
|
|
->searchable() |
|
37
|
|
|
->required() |
|
38
|
|
|
->columnSpanFull(), |
|
39
|
|
|
|
|
40
|
|
|
TextInput::make('subject') |
|
41
|
|
|
->label('Subject Line') |
|
42
|
|
|
->helperText('The subject line for email notifications. For SMS/Slack/Discord, this may be used as a title. Use {{variable}} for dynamic content.') |
|
43
|
|
|
->placeholder('Welcome to {{app_name}}, {{name}}!') |
|
44
|
|
|
->required() |
|
45
|
|
|
->maxLength(255) |
|
46
|
|
|
->columnSpanFull(), |
|
47
|
|
|
|
|
48
|
|
|
Toggle::make('is_active') |
|
49
|
|
|
->label('Active') |
|
50
|
|
|
->helperText('Enable or disable this template. Inactive templates will not be used for sending notifications.') |
|
51
|
|
|
->default(true) |
|
52
|
|
|
->columnSpanFull(), |
|
53
|
|
|
]) |
|
54
|
|
|
->columns(2), |
|
55
|
|
|
|
|
56
|
|
|
Section::make('Template Content') |
|
57
|
|
|
->description('The actual content of the notification template') |
|
58
|
|
|
->schema([ |
|
59
|
|
|
Textarea::make('content') |
|
60
|
|
|
->label('Template Content') |
|
61
|
|
|
->helperText('The main content of your notification. Use {{variable}} syntax to insert dynamic values. Example: "Hi {{name}}, welcome to {{app_name}}!"') |
|
62
|
|
|
->placeholder("Hi {{name}},\n\nWelcome to {{app_name}}! We're excited to have you on board.\n\nBest regards,\nThe {{app_name}} Team") |
|
63
|
|
|
->required() |
|
64
|
|
|
->rows(12) |
|
65
|
|
|
->columnSpanFull(), |
|
66
|
|
|
]), |
|
67
|
|
|
|
|
68
|
|
|
Section::make('Template Variables') |
|
69
|
|
|
->description('Define the variables that can be used in this template. These help document what data should be passed when sending notifications.') |
|
70
|
|
|
->schema([ |
|
71
|
|
|
KeyValue::make('variables') |
|
72
|
|
|
->label('Variables') |
|
73
|
|
|
->keyLabel('Variable Name') |
|
74
|
|
|
->valueLabel('Description') |
|
75
|
|
|
->helperText('Document the variables used in your template. Key should match the variable name (without {{}}), value should describe what it represents. Example: name ā "User\'s full name", app_name ā "Application name"') |
|
76
|
|
|
->addable(true) |
|
77
|
|
|
->deletable(true) |
|
78
|
|
|
->reorderable() |
|
79
|
|
|
->columnSpanFull(), |
|
80
|
|
|
]), |
|
81
|
|
|
|
|
82
|
|
|
Section::make('Template Examples') |
|
83
|
|
|
->description('Example templates for different use cases. Click to expand.') |
|
84
|
|
|
->collapsible() |
|
85
|
|
|
->collapsed() |
|
86
|
|
|
->schema([ |
|
87
|
|
|
Textarea::make('email_example') |
|
88
|
|
|
->label('Email Template Example') |
|
89
|
|
|
->default("Subject: Welcome to {{app_name}}, {{name}}!\n\nContent:\nHi {{name}},\n\nWelcome to {{app_name}}! We're excited to have you on board.\n\nYour account has been created successfully. You can now log in using:\nEmail: {{email}}\n\nBest regards,\nThe {{app_name}} Team") |
|
90
|
|
|
->disabled() |
|
91
|
|
|
->dehydrated(false) |
|
92
|
|
|
->rows(8) |
|
93
|
|
|
->columnSpanFull(), |
|
94
|
|
|
|
|
95
|
|
|
Textarea::make('sms_example') |
|
96
|
|
|
->label('SMS Template Example') |
|
97
|
|
|
->default("Subject: Order Confirmation\n\nContent:\nHi {{name}}, your order #{{order_number}} has been confirmed. Total: {{amount}}. Track at {{tracking_url}}") |
|
98
|
|
|
->disabled() |
|
99
|
|
|
->dehydrated(false) |
|
100
|
|
|
->rows(5) |
|
101
|
|
|
->columnSpanFull(), |
|
102
|
|
|
|
|
103
|
|
|
Textarea::make('slack_example') |
|
104
|
|
|
->label('Slack Template Example') |
|
105
|
|
|
->default("Subject: New Project Created\n\nContent:\nš New project created!\n\nProject: {{project_name}}\nCreated by: {{user_name}}\nView: {{project_url}}") |
|
106
|
|
|
->disabled() |
|
107
|
|
|
->dehydrated(false) |
|
108
|
|
|
->rows(6) |
|
109
|
|
|
->columnSpanFull(), |
|
110
|
|
|
|
|
111
|
|
|
Textarea::make('discord_example') |
|
112
|
|
|
->label('Discord Template Example') |
|
113
|
|
|
->default("Subject: New Project Created\n\nContent:\nš New project created!\n\nProject: {{project_name}}\nCreated by: {{user_name}}\nView: {{project_url}}") |
|
114
|
|
|
->disabled() |
|
115
|
|
|
->dehydrated(false) |
|
116
|
|
|
->rows(6) |
|
117
|
|
|
->columnSpanFull(), |
|
118
|
|
|
]), |
|
119
|
|
|
]); |
|
120
|
|
|
} |
|
121
|
|
|
} |
|
122
|
|
|
|