Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New letter #86

Merged
merged 2 commits into from
Aug 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2,484 changes: 1,384 additions & 1,100 deletions composer.lock

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions docs/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,16 @@ weight: 5

wind will fire these events:
- `LaraZeus\Wind\Events\LetterSent`
when a new letter sent from the website
- `LaraZeus\Wind\Events\ReplySent`
when you send a replay from the admin panel
- `LaraZeus\Wind\Events\NewLetterSent`
when you send a new letter from the admin panel

## Register a Listener:

* first create your listener:
*
```bash
php artisan make:listener SendWindNotification --event=LetterSent
```
Expand Down
9 changes: 7 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ parameters:
paths:
- src
- database

checkOctaneCompatibility: true
checkModelProperties: true
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false

ignoreErrors:
-
identifier: missingType.iterableValue
-
identifier: missingType.generics
1 change: 1 addition & 0 deletions resources/lang/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"status_NEW": "جديد",
"status_READ": "مقروء",
"status_REPLIED": "تم الرد",
"status_SENT": "تم الإرسال",
"reply_message": "نص الرد",
"reply_title": "عنوان الرد",
"message": "الرسالة",
Expand Down
1 change: 1 addition & 0 deletions resources/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"status_NEW": "NEW",
"status_READ": "READ",
"status_REPLIED": "REPLIED",
"status_SENT": "SENT",
"reply_message": "reply message",
"reply_title": "reply title",
"message": "message",
Expand Down
4 changes: 2 additions & 2 deletions src/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,8 @@ public function getWindModels(): array
public static function getModel(string $model): string
{
return array_merge(
(new static())->windModels,
(new static())::get()->getWindModels()
(new static)->windModels,
(new static)::get()->getWindModels()
)[$model];
}
}
37 changes: 37 additions & 0 deletions src/Events/NewLetterSent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace LaraZeus\Wind\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Queue\SerializesModels;
use LaraZeus\Wind\Models\Letter;

class NewLetterSent
{
use Dispatchable;
use InteractsWithSockets;
use SerializesModels;

public Letter $letter;

/**
* Create a new event instance.
*
* @return void
*/
public function __construct(Letter $letter)
{
$this->letter = $letter;
}

/**
* Get the channels the event should broadcast on.
*/
public function broadcastOn(): Channel | PrivateChannel | array
{
return new PrivateChannel('zeus-wind');
}
}
64 changes: 51 additions & 13 deletions src/Filament/Resources/LetterResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
namespace LaraZeus\Wind\Filament\Resources;

use Filament\Forms\Components\Placeholder;
use Filament\Forms\Components\RichEditor;
use Filament\Forms\Components\Section;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\Textarea;
use Filament\Forms\Components\TextInput;
use Filament\Forms\Form;
use Filament\Resources\Resource;
Expand All @@ -26,21 +26,22 @@
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Support\HtmlString;
use LaraZeus\Wind\Filament\Resources\LetterResource\Pages;
use LaraZeus\Wind\Models\Letter;
use LaraZeus\Wind\WindPlugin;

class LetterResource extends Resource
{
protected static ?string $navigationIcon = 'heroicon-o-inbox';

protected static ?int $navigationSort = 2;

public static function getModel(): string
{
return WindPlugin::get()->getModel('Letter');
}

protected static ?string $navigationIcon = 'heroicon-o-inbox';

protected static ?int $navigationSort = 2;

public static function getNavigationBadge(): ?string
{
return static::getModel()::where('status', WindPlugin::get()->getDefaultStatus())->count();
Expand All @@ -61,8 +62,8 @@ public static function form(Form $form): Form
{
return $form
->schema([

Section::make()
->visibleOn('edit')
->schema([
Placeholder::make('sender_info')
->label('Sender Info:')
Expand All @@ -73,6 +74,7 @@ public static function form(Form $form): Form
->required()
->disabled()
->maxLength(255),

TextInput::make('email')
->label(__('email'))
->email()
Expand All @@ -90,22 +92,23 @@ public static function form(Form $form): Form
->label(__('sent at'))
->disabled(),

Textarea::make('message')
Placeholder::make('message')
->label(__('message'))
->rows(10)
->disabled()
->maxLength(65535)
->content(fn (Letter $record) => new HtmlString($record->message))
->columnSpan(['sm' => 2]),
])
->columns(2),
->columns(),

Section::make()
->visibleOn('edit')
->schema([
Select::make('department_id')
->label(__('department'))
->options(WindPlugin::get()->getModel('Department')::pluck('name', 'id'))
->required()
->visible(fn (): bool => WindPlugin::get()->hasDepartmentResource()),

TextInput::make('status')
->label(__('status'))
->required()
Expand All @@ -116,13 +119,47 @@ public static function form(Form $form): Form
->required()
->maxLength(255)
->columnSpan(['sm' => 2]),
Textarea::make('reply_message')

RichEditor::make('reply_message')
->label(__('reply_message'))
->rows(10)
->required()
->maxLength(65535)
->columnSpan(['sm' => 2]),
])->columns(2),
])
->columns(),

Section::make()
->visibleOn('create')
->schema([
TextInput::make('name')
->label(__('to name'))
->required()
->maxLength(255),

TextInput::make('email')
->label(__('to email'))
->email()
->required()
->maxLength(255),

TextInput::make('title')
->label(__('title'))
->required()
->maxLength(255),

Select::make('department_id')
->label(__('department'))
->options(WindPlugin::get()->getModel('Department')::pluck('name', 'id'))
->required(fn (): bool => WindPlugin::get()->hasDepartmentResource())
->visible(fn (): bool => WindPlugin::get()->hasDepartmentResource()),

RichEditor::make('message')
->label(__('message'))
->required()
->maxLength(65535)
->columnSpan(['sm' => 2]),
])
->columns(),
]);
}

Expand Down Expand Up @@ -226,6 +263,7 @@ public static function getPages(): array
{
return [
'index' => Pages\ListLetters::route('/'),
'create' => Pages\CreateLetter::route('/create'),
'edit' => Pages\EditLetter::route('/{record}/edit'),
];
}
Expand Down
27 changes: 27 additions & 0 deletions src/Filament/Resources/LetterResource/Pages/CreateLetter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

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

use Filament\Resources\Pages\CreateRecord;
use LaraZeus\Wind\Events\NewLetterSent;
use LaraZeus\Wind\Filament\Resources\LetterResource;

/**
* @property mixed $record
*/
class CreateLetter extends CreateRecord
{
protected static string $resource = LetterResource::class;

protected function mutateFormDataBeforeCreate(array $data): array
{
$data['status'] = 'SENT';

return $data;
}

protected function afterCreate(): void
{
NewLetterSent::dispatch($this->record);
}
}
8 changes: 8 additions & 0 deletions src/Filament/Resources/LetterResource/Pages/ListLetters.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

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

use Filament\Actions;
use Filament\Resources\Pages\ListRecords;
use LaraZeus\Wind\Filament\Resources\LetterResource;

class ListLetters extends ListRecords
{
protected static string $resource = LetterResource::class;

protected function getHeaderActions(): array
{
return [
Actions\CreateAction::make(),
];
}
}
2 changes: 1 addition & 1 deletion src/WindPlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function register(Panel $panel): void

public static function make(): static
{
return new self();
return new self;
}

public static function get(): static
Expand Down