Skip to content

Commit 502be4a

Browse files
authored
Merge pull request #86 from lara-zeus/new-letter
New letter
2 parents 2b8a4ea + 442e078 commit 502be4a

File tree

9 files changed

+1522
-1115
lines changed

9 files changed

+1522
-1115
lines changed

composer.lock

Lines changed: 1384 additions & 1100 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/events.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,16 @@ weight: 5
77

88
wind will fire these events:
99
- `LaraZeus\Wind\Events\LetterSent`
10+
when a new letter sent from the website
1011
- `LaraZeus\Wind\Events\ReplySent`
12+
when you send a replay from the admin panel
13+
- `LaraZeus\Wind\Events\NewLetterSent`
14+
when you send a new letter from the admin panel
1115

1216
## Register a Listener:
17+
1318
* first create your listener:
19+
*
1420
```bash
1521
php artisan make:listener SendWindNotification --event=LetterSent
1622
```

phpstan.neon.dist

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ parameters:
66
paths:
77
- src
88
- database
9+
910
checkOctaneCompatibility: true
1011
checkModelProperties: true
11-
checkMissingIterableValueType: false
12-
checkGenericClassInNonGenericObjectType: false
12+
13+
ignoreErrors:
14+
-
15+
identifier: missingType.iterableValue
16+
-
17+
identifier: missingType.generics

resources/lang/ar.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"status_NEW": "جديد",
1818
"status_READ": "مقروء",
1919
"status_REPLIED": "تم الرد",
20+
"status_SENT": "تم الإرسال",
2021
"reply_message": "نص الرد",
2122
"reply_title": "عنوان الرد",
2223
"message": "الرسالة",

resources/lang/en.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"status_NEW": "NEW",
1717
"status_READ": "READ",
1818
"status_REPLIED": "REPLIED",
19+
"status_SENT": "SENT",
1920
"reply_message": "reply message",
2021
"reply_title": "reply title",
2122
"message": "message",

src/Events/NewLetterSent.php

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
namespace LaraZeus\Wind\Events;
4+
5+
use Illuminate\Broadcasting\Channel;
6+
use Illuminate\Broadcasting\InteractsWithSockets;
7+
use Illuminate\Broadcasting\PrivateChannel;
8+
use Illuminate\Foundation\Events\Dispatchable;
9+
use Illuminate\Queue\SerializesModels;
10+
use LaraZeus\Wind\Models\Letter;
11+
12+
class NewLetterSent
13+
{
14+
use Dispatchable;
15+
use InteractsWithSockets;
16+
use SerializesModels;
17+
18+
public Letter $letter;
19+
20+
/**
21+
* Create a new event instance.
22+
*
23+
* @return void
24+
*/
25+
public function __construct(Letter $letter)
26+
{
27+
$this->letter = $letter;
28+
}
29+
30+
/**
31+
* Get the channels the event should broadcast on.
32+
*/
33+
public function broadcastOn(): Channel | PrivateChannel | array
34+
{
35+
return new PrivateChannel('zeus-wind');
36+
}
37+
}

src/Filament/Resources/LetterResource.php

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
namespace LaraZeus\Wind\Filament\Resources;
44

55
use Filament\Forms\Components\Placeholder;
6+
use Filament\Forms\Components\RichEditor;
67
use Filament\Forms\Components\Section;
78
use Filament\Forms\Components\Select;
8-
use Filament\Forms\Components\Textarea;
99
use Filament\Forms\Components\TextInput;
1010
use Filament\Forms\Form;
1111
use Filament\Resources\Resource;
@@ -26,21 +26,22 @@
2626
use Filament\Tables\Table;
2727
use Illuminate\Database\Eloquent\Builder;
2828
use Illuminate\Database\Eloquent\SoftDeletingScope;
29+
use Illuminate\Support\HtmlString;
2930
use LaraZeus\Wind\Filament\Resources\LetterResource\Pages;
3031
use LaraZeus\Wind\Models\Letter;
3132
use LaraZeus\Wind\WindPlugin;
3233

3334
class 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
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
3+
namespace LaraZeus\Wind\Filament\Resources\LetterResource\Pages;
4+
5+
use Filament\Resources\Pages\CreateRecord;
6+
use LaraZeus\Wind\Events\NewLetterSent;
7+
use LaraZeus\Wind\Filament\Resources\LetterResource;
8+
9+
/**
10+
* @property mixed $record
11+
*/
12+
class CreateLetter extends CreateRecord
13+
{
14+
protected static string $resource = LetterResource::class;
15+
16+
protected function mutateFormDataBeforeCreate(array $data): array
17+
{
18+
$data['status'] = 'SENT';
19+
20+
return $data;
21+
}
22+
23+
protected function afterCreate(): void
24+
{
25+
NewLetterSent::dispatch($this->record);
26+
}
27+
}

src/Filament/Resources/LetterResource/Pages/ListLetters.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,18 @@
22

33
namespace LaraZeus\Wind\Filament\Resources\LetterResource\Pages;
44

5+
use Filament\Actions;
56
use Filament\Resources\Pages\ListRecords;
67
use LaraZeus\Wind\Filament\Resources\LetterResource;
78

89
class ListLetters extends ListRecords
910
{
1011
protected static string $resource = LetterResource::class;
12+
13+
protected function getHeaderActions(): array
14+
{
15+
return [
16+
Actions\CreateAction::make(),
17+
];
18+
}
1119
}

0 commit comments

Comments
 (0)