NotificationChannelForm   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 106
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 1
eloc 91
c 1
b 0
f 1
dl 0
loc 106
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B configure() 0 104 1
1
<?php
2
3
namespace Usamamuneerchaudhary\Notifier\Filament\Resources\NotificationChannelResource\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
13
class NotificationChannelForm
14
{
15
    public static function configure(Schema $schema): Schema
16
    {
17
        return $schema
18
            ->components([
19
                Section::make('Channel Information')
20
                    ->description('Basic information about the notification channel')
21
                    ->schema([
22
                        TextInput::make('title')
23
                            ->label('Channel Title')
24
                            ->helperText('A friendly display name for this channel (e.g., "Email", "Slack", "SMS")')
25
                            ->placeholder('Email')
26
                            ->required()
27
                            ->maxLength(255)
28
                            ->columnSpanFull(),
29
30
                        Select::make('type')
31
                            ->label('Channel Type')
32
                            ->helperText('The unique identifier for this channel type. This must match one of the supported channel types.')
33
                            ->options([
34
                                'email' => 'Email - Send notifications via email',
35
                                'slack' => 'Slack - Send notifications to Slack workspace',
36
                                'discord' => 'Discord - Send notifications to Discord server via webhook',
37
                                'sms' => 'SMS - Send text message notifications',
38
                                'push' => 'Push - Send push notifications (Firebase FCM)',
39
                            ])
40
                            ->required()
41
                            ->unique(ignoreRecord: true)
42
                            ->searchable()
43
                            ->reactive()
44
                            ->columnSpanFull(),
45
46
                        TextInput::make('icon')
47
                            ->label('Icon')
48
                            ->helperText('Heroicon class name (e.g., heroicon-o-envelope, heroicon-o-chat-bubble-left-right). Leave empty to use default icon for channel type.')
49
                            ->placeholder('heroicon-o-envelope')
50
                            ->maxLength(255)
51
                            ->columnSpanFull(),
52
53
                        Toggle::make('is_active')
54
                            ->label('Active')
55
                            ->helperText('Enable or disable this channel. Inactive channels will not be used for sending notifications.')
56
                            ->default(true)
57
                            ->columnSpanFull(),
58
                    ])
59
                    ->columns(2),
60
61
                Section::make('Channel Settings')
62
                    ->description('Configure channel-specific settings. These settings will be used when sending notifications through this channel.')
63
                    ->schema([
64
                        KeyValue::make('settings')
65
                            ->label('Settings')
66
                            ->keyLabel('Setting Name')
67
                            ->valueLabel('Setting Value')
68
                            ->helperText('Add key-value pairs for channel-specific configuration. Examples: For email, you might add "from_address" and "from_name". For Slack, add "webhook_url".')
69
                            ->reorderable()
70
                            ->columnSpanFull()
71
                            ->addable(true)
72
                            ->deletable(true),
73
                    ]),
74
75
                Section::make('Setting Examples')
76
                    ->description('Common settings for different channel types. Click to expand and see examples.')
77
                    ->collapsible()
78
                    ->collapsed()
79
                    ->schema([
80
                        Textarea::make('email_example')
81
                            ->label('Email Channel Settings')
82
                            ->default("from_address: [email protected]\nfrom_name: Your App Name")
83
                            ->disabled()
84
                            ->dehydrated(false)
85
                            ->rows(3)
86
                            ->columnSpanFull(),
87
88
                        Textarea::make('slack_example')
89
                            ->label('Slack Channel Settings')
90
                            ->default("webhook_url: https://hooks.slack.com/services/YOUR/WEBHOOK/URL\nchannel: #notifications\nusername: Notification Bot")
91
                            ->disabled()
92
                            ->dehydrated(false)
93
                            ->rows(4)
94
                            ->columnSpanFull(),
95
96
                        Textarea::make('sms_example')
97
                            ->label('SMS Channel Settings (Twilio)')
98
                            ->default("twilio_account_sid: YOUR_ACCOUNT_SID\ntwilio_auth_token: YOUR_AUTH_TOKEN\ntwilio_phone_number: +1234567890")
99
                            ->disabled()
100
                            ->dehydrated(false)
101
                            ->rows(4)
102
                            ->columnSpanFull(),
103
104
                        Textarea::make('push_example')
105
                            ->label('Push Channel Settings (Firebase)')
106
                            ->default("firebase_server_key: YOUR_SERVER_KEY\nfirebase_project_id: YOUR_PROJECT_ID")
107
                            ->disabled()
108
                            ->dehydrated(false)
109
                            ->rows(3)
110
                            ->columnSpanFull(),
111
112
                        Textarea::make('discord_example')
113
                            ->label('Discord Channel Settings')
114
                            ->default("webhook_url: https://discord.com/api/webhooks/YOUR/WEBHOOK/URL\nusername: Notification Bot\navatar_url: https://example.com/avatar.png\ncolor: 3447003")
115
                            ->disabled()
116
                            ->dehydrated(false)
117
                            ->rows(4)
118
                            ->columnSpanFull(),
119
                    ]),
120
            ]);
121
    }
122
}
123