Answer the inbox from the panel, with templates
A reply starts from a template filled in the language the person wrote in, is sent by the application when it has a mailer that delivers or handed to the replier's mail program otherwise, and is recorded on the submission. The same is available through the API. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\ReplyTemplates\Pages;
|
||||
|
||||
use App\Filament\Resources\ReplyTemplates\ReplyTemplateResource;
|
||||
use Filament\Resources\Pages\CreateRecord;
|
||||
|
||||
class CreateReplyTemplate extends CreateRecord
|
||||
{
|
||||
protected static string $resource = ReplyTemplateResource::class;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\ReplyTemplates\Pages;
|
||||
|
||||
use App\Filament\Resources\ReplyTemplates\ReplyTemplateResource;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Resources\Pages\EditRecord;
|
||||
|
||||
class EditReplyTemplate extends EditRecord
|
||||
{
|
||||
protected static string $resource = ReplyTemplateResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
DeleteAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\ReplyTemplates\Pages;
|
||||
|
||||
use App\Filament\Resources\ReplyTemplates\ReplyTemplateResource;
|
||||
use Filament\Actions\CreateAction;
|
||||
use Filament\Resources\Pages\ListRecords;
|
||||
|
||||
class ListReplyTemplates extends ListRecords
|
||||
{
|
||||
protected static string $resource = ReplyTemplateResource::class;
|
||||
|
||||
protected function getHeaderActions(): array
|
||||
{
|
||||
return [
|
||||
CreateAction::make(),
|
||||
];
|
||||
}
|
||||
}
|
||||
131
app/Filament/Resources/ReplyTemplates/ReplyTemplateResource.php
Normal file
131
app/Filament/Resources/ReplyTemplates/ReplyTemplateResource.php
Normal file
@@ -0,0 +1,131 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Filament\Resources\ReplyTemplates;
|
||||
|
||||
use App\Enums\ApplicationKind;
|
||||
use App\Filament\Resources\ReplyTemplates\Pages\CreateReplyTemplate;
|
||||
use App\Filament\Resources\ReplyTemplates\Pages\EditReplyTemplate;
|
||||
use App\Filament\Resources\ReplyTemplates\Pages\ListReplyTemplates;
|
||||
use App\Filament\Support\TranslatableTabs;
|
||||
use App\Models\ReplyTemplate;
|
||||
use BackedEnum;
|
||||
use Filament\Actions\DeleteAction;
|
||||
use Filament\Actions\EditAction;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Forms\Components\TextInput;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Components\Section;
|
||||
use Filament\Schemas\Schema;
|
||||
use Filament\Support\Icons\Heroicon;
|
||||
use Filament\Tables\Columns\TextColumn;
|
||||
use Filament\Tables\Table;
|
||||
use UnitEnum;
|
||||
|
||||
/**
|
||||
* The answers the inbox gives often enough to write once.
|
||||
*/
|
||||
class ReplyTemplateResource extends Resource
|
||||
{
|
||||
protected static ?string $model = ReplyTemplate::class;
|
||||
|
||||
protected static string|BackedEnum|null $navigationIcon = Heroicon::OutlinedChatBubbleBottomCenterText;
|
||||
|
||||
protected static ?int $navigationSort = 5;
|
||||
|
||||
protected static ?string $recordTitleAttribute = 'name';
|
||||
|
||||
public static function getModelLabel(): string
|
||||
{
|
||||
return __('panel.replies.templates.label');
|
||||
}
|
||||
|
||||
public static function getPluralModelLabel(): string
|
||||
{
|
||||
return __('panel.replies.templates.plural');
|
||||
}
|
||||
|
||||
public static function getNavigationGroup(): string|UnitEnum|null
|
||||
{
|
||||
return __('panel.groups.collective');
|
||||
}
|
||||
|
||||
public static function form(Schema $schema): Schema
|
||||
{
|
||||
return $schema->components([
|
||||
Section::make()
|
||||
->columns(2)
|
||||
->schema([
|
||||
TextInput::make('name')
|
||||
->label(__('panel.replies.templates.fields.name'))
|
||||
->helperText(__('panel.replies.templates.fields.name_hint'))
|
||||
->required()
|
||||
->maxLength(255),
|
||||
|
||||
Select::make('kind')
|
||||
->label(__('panel.replies.templates.fields.kind'))
|
||||
->options(ApplicationKind::options())
|
||||
->placeholder(__('panel.replies.templates.any_kind')),
|
||||
|
||||
TextInput::make('position')
|
||||
->label(__('panel.replies.templates.fields.position'))
|
||||
->numeric()
|
||||
->minValue(0)
|
||||
->default(0),
|
||||
]),
|
||||
|
||||
Section::make()
|
||||
->description(__('panel.replies.templates.placeholders', ['list' => implode(', ', ReplyTemplate::PLACEHOLDERS)]))
|
||||
->schema([
|
||||
TranslatableTabs::make(fn (string $locale, bool $isDefault) => [
|
||||
TextInput::make("subject.{$locale}")
|
||||
->label(__('panel.replies.fields.subject'))
|
||||
->required($isDefault)
|
||||
->maxLength(255),
|
||||
|
||||
Textarea::make("body.{$locale}")
|
||||
->label(__('panel.replies.fields.body'))
|
||||
->required($isDefault)
|
||||
->rows(10),
|
||||
]),
|
||||
]),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function table(Table $table): Table
|
||||
{
|
||||
return $table
|
||||
->defaultSort('position')
|
||||
->columns([
|
||||
TextColumn::make('name')
|
||||
->label(__('panel.replies.templates.fields.name'))
|
||||
->searchable()
|
||||
->weight('bold'),
|
||||
|
||||
TextColumn::make('kind')
|
||||
->label(__('panel.replies.templates.fields.kind'))
|
||||
->badge()
|
||||
->formatStateUsing(fn (?string $state) => $state ? ApplicationKind::from($state)->getLabel() : __('panel.replies.templates.any_kind'))
|
||||
->placeholder(__('panel.replies.templates.any_kind')),
|
||||
|
||||
TextColumn::make('subject')
|
||||
->label(__('panel.replies.fields.subject'))
|
||||
->limit(60),
|
||||
])
|
||||
->recordActions([
|
||||
EditAction::make(),
|
||||
DeleteAction::make(),
|
||||
]);
|
||||
}
|
||||
|
||||
public static function getPages(): array
|
||||
{
|
||||
return [
|
||||
'index' => ListReplyTemplates::route('/'),
|
||||
'create' => CreateReplyTemplate::route('/create'),
|
||||
'edit' => EditReplyTemplate::route('/{record}/edit'),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user