Skip to content

Commit 94ec2ad

Browse files
committed
add template description
1 parent 6773ab2 commit 94ec2ad

File tree

8 files changed

+75
-41
lines changed

8 files changed

+75
-41
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"ralphjsmit/laravel-filament-components": "^2.0",
3030
"socialiteproviders/manager": "^4.3",
3131
"spatie/data-transfer-object": "^3.9.1",
32+
"spatie/laravel-package-tools": "^1.19",
3233
"twig/twig": "^3.5.1"
3334
},
3435
"require-dev": {
@@ -40,8 +41,7 @@
4041
"pestphp/pest-plugin-faker": "^2.0",
4142
"pestphp/pest-plugin-laravel": "^2.0",
4243
"phpstan/extension-installer": "^1.2",
43-
"phpstan/phpstan-deprecation-rules": "^1.1.3",
44-
"spatie/laravel-package-tools": "^1.16"
44+
"phpstan/phpstan-deprecation-rules": "^1.1.3"
4545
},
4646
"autoload": {
4747
"psr-4": {
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
return new class extends Migration {
8+
public function up(): void
9+
{
10+
Schema::table('templates', function (Blueprint $table) {
11+
$table->text('description')->nullable();
12+
});
13+
}
14+
15+
public function down(): void
16+
{
17+
Schema::table('templates', function (Blueprint $table) {
18+
$table->dropColumn('description');
19+
});
20+
}
21+
};

resources/css/theme.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,7 @@
1616
.cm-editor {
1717
@apply h-full;
1818
}
19+
20+
.fi-fo-field-wrp-helper-text {
21+
@apply text-xs text-slate-500 pl-2;
22+
}

resources/dist/css/theme.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/MailCarrierServiceProvider.php

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,7 @@ public function configurePackage(Package $package): void
4646
TokenCommand::class,
4747
RetryCommand::class,
4848
])
49-
->hasMigrations([
50-
'2024_01_01_00000_create_users_table',
51-
'2024_01_01_00001_create_layouts_table',
52-
'2024_01_01_00002_create_templates_table',
53-
'2024_01_01_00003_create_logs_table',
54-
'2024_01_01_00004_create_attachments_table',
55-
'2024_01_01_00005_transform_logs_cc_bcc_array',
56-
'2024_01_01_00006_add_tries_to_logs_table',
57-
'2024_01_01_00007_add_tags_metadata_to_logs_table',
58-
'2024_01_01_00008_add_tags_to_templates_table',
59-
'2024_08_27_074130_add_replyto_to_logs_table',
60-
])
49+
->discoversMigrations()
6150
->runsMigrations();
6251
}
6352

src/Models/Template.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ class Template extends Model
3636
'slug',
3737
'content',
3838
'tags',
39+
'description',
3940
];
4041

4142
/**

src/Providers/Filament/MailCarrierPanelProvider.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Filament\Panel;
1010
use Filament\PanelProvider;
1111
use Filament\Support\Colors\Color;
12+
use Filament\Support\Enums\MaxWidth;
1213
use Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse;
1314
use Illuminate\Cookie\Middleware\EncryptCookies;
1415
use Illuminate\Foundation\Http\Middleware\VerifyCsrfToken;
@@ -31,12 +32,14 @@ public function panel(Panel $panel): Panel
3132
->id('mailcarrier')
3233
->path('')
3334
->login()
35+
->unsavedChangesAlerts()
3436
->font('Poppins')
3537
->brandName('MailCarrier')
3638
->favicon(asset('vendor/mailcarrier/images/favicon.ico'))
3739
->brandLogo(asset('vendor/mailcarrier/images/logo-dark.svg'))
3840
->darkModeBrandLogo(asset('vendor/mailcarrier/images/logo-light.svg'))
3941
->theme(asset('vendor/mailcarrier/css/theme.css'))
42+
->maxContentWidth(MaxWidth::Full)
4043
->colors([
4144
'primary' => Color::Indigo,
4245
])

src/Resources/TemplateResource.php

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace MailCarrier\Resources;
44

55
use Filament\Forms;
6+
use Filament\Forms\Components\Grid;
67
use Filament\Forms\Form;
78
use Filament\Resources\Resource;
89
use Filament\Tables;
@@ -139,35 +140,50 @@ protected static function getTableFilters(): array
139140
/**
140141
* Get the form content.
141142
*/
142-
protected static function getFormContent(): Forms\Components\Section
143+
protected static function getFormContent(): Forms\Components\Grid
143144
{
144-
return Forms\Components\Section::make([
145-
Forms\Components\TextInput::make('name')
146-
->label('Internal name')
147-
->required()
148-
->autofocus()
149-
->columnSpanFull()
150-
// Disable field UI if the record exists and user can't unlock it
151-
->disabled(fn (?Template $record) => !is_null($record) && $record->is_locked)
152-
// Save the field if record does not exist or user can unlock it
153-
->dehydrated(fn (?Template $record) => is_null($record) || !$record->is_locked),
154-
155-
Forms\Components\TextInput::make('slug')
156-
->label('Unique identifier (slug)')
157-
->placeholder('Leave empty to auto generate')
158-
->helperText(new HtmlString('<span class="text-xs text-slate-500 pl-2">Use this as "template" key in your APIs</span>'))
159-
->columnSpanFull()
160-
->required(fn (?Template $record) => !is_null($record))
161-
// Disable field UI if the record exists and user can't unlock it
162-
->disabled(fn (?Template $record) => !is_null($record) && $record->is_locked)
163-
// Save the field if record does not exist or user can unlock it
164-
->dehydrated(fn (?Template $record) => is_null($record) || !$record->is_locked)
165-
->extraInputAttributes([
166-
'onClick' => 'this.select()',
145+
return Grid::make(1)
146+
->schema([
147+
Forms\Components\Section::make([
148+
Forms\Components\TextInput::make('name')
149+
->label('Internal name')
150+
->required()
151+
->autofocus()
152+
->columnSpanFull()
153+
// Disable field UI if the record exists and user can't unlock it
154+
->disabled(fn (?Template $record) => !is_null($record) && $record->is_locked)
155+
// Save the field if record does not exist or user can unlock it
156+
->dehydrated(fn (?Template $record) => is_null($record) || !$record->is_locked),
157+
158+
Forms\Components\TextInput::make('slug')
159+
->label('Unique identifier (slug)')
160+
->placeholder('Leave empty to auto generate')
161+
->helperText('Use this as "template" key in your APIs')
162+
->columnSpanFull()
163+
->required(fn (?Template $record) => !is_null($record))
164+
// Disable field UI if the record exists and user can't unlock it
165+
->disabled(fn (?Template $record) => !is_null($record) && $record->is_locked)
166+
// Save the field if record does not exist or user can unlock it
167+
->dehydrated(fn (?Template $record) => is_null($record) || !$record->is_locked)
168+
->extraInputAttributes([
169+
'onClick' => 'this.select()',
170+
]),
171+
172+
static::getFormEditor(),
167173
]),
168174

169-
static::getFormEditor(),
170-
]);
175+
Forms\Components\Section::make([
176+
Forms\Components\Textarea::make('description')
177+
->label('Description')
178+
->helperText('A short description of the template, visible only in the admin area')
179+
->placeholder('How is this template being used? What\'s the purpose?')
180+
->columnSpanFull()
181+
// Disable field UI if the record exists and user can't unlock it
182+
->disabled(fn (?Template $record) => !is_null($record) && $record->is_locked)
183+
// Save the field if record does not exist or user can unlock it
184+
->dehydrated(fn (?Template $record) => is_null($record) || !$record->is_locked),
185+
]),
186+
]);
171187
}
172188

173189
/**

0 commit comments

Comments
 (0)