33namespace LaraZeus \Wind \Filament \Resources ;
44
55use Filament \Forms \Components \Placeholder ;
6+ use Filament \Forms \Components \RichEditor ;
67use Filament \Forms \Components \Section ;
78use Filament \Forms \Components \Select ;
8- use Filament \Forms \Components \Textarea ;
99use Filament \Forms \Components \TextInput ;
1010use Filament \Forms \Form ;
1111use Filament \Resources \Resource ;
2626use Filament \Tables \Table ;
2727use Illuminate \Database \Eloquent \Builder ;
2828use Illuminate \Database \Eloquent \SoftDeletingScope ;
29+ use Illuminate \Support \HtmlString ;
2930use LaraZeus \Wind \Filament \Resources \LetterResource \Pages ;
3031use LaraZeus \Wind \Models \Letter ;
3132use LaraZeus \Wind \WindPlugin ;
3233
3334class LetterResource extends Resource
3435{
36+ protected static ?string $ navigationIcon = 'heroicon-o-inbox ' ;
37+
38+ protected static ?int $ navigationSort = 2 ;
39+
3540 public static function getModel (): string
3641 {
3742 return WindPlugin::get ()->getModel ('Letter ' );
3843 }
3944
40- protected static ?string $ navigationIcon = 'heroicon-o-inbox ' ;
41-
42- protected static ?int $ navigationSort = 2 ;
43-
4445 public static function getNavigationBadge (): ?string
4546 {
4647 return static ::getModel ()::where ('status ' , WindPlugin::get ()->getDefaultStatus ())->count ();
@@ -61,8 +62,8 @@ public static function form(Form $form): Form
6162 {
6263 return $ form
6364 ->schema ([
64-
6565 Section::make ()
66+ ->visibleOn ('edit ' )
6667 ->schema ([
6768 Placeholder::make ('sender_info ' )
6869 ->label ('Sender Info: ' )
@@ -73,6 +74,7 @@ public static function form(Form $form): Form
7374 ->required ()
7475 ->disabled ()
7576 ->maxLength (255 ),
77+
7678 TextInput::make ('email ' )
7779 ->label (__ ('email ' ))
7880 ->email ()
@@ -90,22 +92,23 @@ public static function form(Form $form): Form
9092 ->label (__ ('sent at ' ))
9193 ->disabled (),
9294
93- Textarea ::make ('message ' )
95+ Placeholder ::make ('message ' )
9496 ->label (__ ('message ' ))
95- ->rows (10 )
9697 ->disabled ()
97- ->maxLength ( 65535 )
98+ ->content ( fn ( Letter $ record ) => new HtmlString ( $ record -> message ) )
9899 ->columnSpan (['sm ' => 2 ]),
99100 ])
100- ->columns (2 ),
101+ ->columns (),
101102
102103 Section::make ()
104+ ->visibleOn ('edit ' )
103105 ->schema ([
104106 Select::make ('department_id ' )
105107 ->label (__ ('department ' ))
106108 ->options (WindPlugin::get ()->getModel ('Department ' )::pluck ('name ' , 'id ' ))
107109 ->required ()
108110 ->visible (fn (): bool => WindPlugin::get ()->hasDepartmentResource ()),
111+
109112 TextInput::make ('status ' )
110113 ->label (__ ('status ' ))
111114 ->required ()
@@ -116,13 +119,47 @@ public static function form(Form $form): Form
116119 ->required ()
117120 ->maxLength (255 )
118121 ->columnSpan (['sm ' => 2 ]),
119- Textarea::make ('reply_message ' )
122+
123+ RichEditor::make ('reply_message ' )
120124 ->label (__ ('reply_message ' ))
121- ->rows (10 )
122125 ->required ()
123126 ->maxLength (65535 )
124127 ->columnSpan (['sm ' => 2 ]),
125- ])->columns (2 ),
128+ ])
129+ ->columns (),
130+
131+ Section::make ()
132+ ->visibleOn ('create ' )
133+ ->schema ([
134+ TextInput::make ('name ' )
135+ ->label (__ ('to name ' ))
136+ ->required ()
137+ ->maxLength (255 ),
138+
139+ TextInput::make ('email ' )
140+ ->label (__ ('to email ' ))
141+ ->email ()
142+ ->required ()
143+ ->maxLength (255 ),
144+
145+ TextInput::make ('title ' )
146+ ->label (__ ('title ' ))
147+ ->required ()
148+ ->maxLength (255 ),
149+
150+ Select::make ('department_id ' )
151+ ->label (__ ('department ' ))
152+ ->options (WindPlugin::get ()->getModel ('Department ' )::pluck ('name ' , 'id ' ))
153+ ->required (fn (): bool => WindPlugin::get ()->hasDepartmentResource ())
154+ ->visible (fn (): bool => WindPlugin::get ()->hasDepartmentResource ()),
155+
156+ RichEditor::make ('message ' )
157+ ->label (__ ('message ' ))
158+ ->required ()
159+ ->maxLength (65535 )
160+ ->columnSpan (['sm ' => 2 ]),
161+ ])
162+ ->columns (),
126163 ]);
127164 }
128165
@@ -226,6 +263,7 @@ public static function getPages(): array
226263 {
227264 return [
228265 'index ' => Pages \ListLetters::route ('/ ' ),
266+ 'create ' => Pages \CreateLetter::route ('/create ' ),
229267 'edit ' => Pages \EditLetter::route ('/{record}/edit ' ),
230268 ];
231269 }
0 commit comments