feat: Introduce announcement types (public/company) with conditional recipient selection in Filament forms and table views.
This commit is contained in:
parent
3ae2054ebd
commit
6dd0c26ac8
39
app/Enums/AnnouncementType.php
Normal file
39
app/Enums/AnnouncementType.php
Normal file
@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Enums;
|
||||
|
||||
use App\Traits\Enum\WithComment;
|
||||
use App\Traits\Enum\WithValue;
|
||||
use Filament\Support\Contracts\HasColor;
|
||||
use Filament\Support\Contracts\HasLabel;
|
||||
|
||||
enum AnnouncementType: int implements HasColor, HasLabel
|
||||
{
|
||||
use WithComment, WithValue;
|
||||
|
||||
case PUBLIC = 1;
|
||||
case COMPANY = 2;
|
||||
|
||||
public function getLabel(): ?string
|
||||
{
|
||||
return match ($this) {
|
||||
self::PUBLIC => 'Publik',
|
||||
self::COMPANY => 'Perusahaan',
|
||||
};
|
||||
}
|
||||
|
||||
public function getColor(): string|array|null
|
||||
{
|
||||
return match ($this) {
|
||||
self::PUBLIC => 'info',
|
||||
self::COMPANY => 'warning',
|
||||
};
|
||||
}
|
||||
|
||||
public static function options(): array
|
||||
{
|
||||
return collect(self::cases())
|
||||
->mapWithKeys(fn ($case) => [$case->value => $case->getLabel()])
|
||||
->toArray();
|
||||
}
|
||||
}
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\Publication\Announcements;
|
||||
|
||||
use App\Enums\AnnouncementType;
|
||||
use App\Filament\Actions\DefaultBulkActions;
|
||||
use App\Filament\Columns\TimestampColumns;
|
||||
use App\Filament\Resources\Publication\Announcements\Pages\ManageAnnouncements;
|
||||
@ -14,6 +15,7 @@
|
||||
use Filament\Actions\ForceDeleteAction;
|
||||
use Filament\Actions\RestoreAction;
|
||||
use Filament\Forms\Components\CheckboxList;
|
||||
use Filament\Forms\Components\Select;
|
||||
use Filament\Forms\Components\Textarea;
|
||||
use Filament\Resources\Resource;
|
||||
use Filament\Schemas\Schema;
|
||||
@ -55,10 +57,19 @@ public static function form(Schema $schema): Schema
|
||||
->rows(4)
|
||||
->columnSpanFull(),
|
||||
|
||||
Select::make('type')
|
||||
->label('Tipe Pengumuman')
|
||||
->options(AnnouncementType::class)
|
||||
->required()
|
||||
->native(false)
|
||||
->default(AnnouncementType::PUBLIC->value)
|
||||
->live(),
|
||||
|
||||
CheckboxList::make('partnerMedia')
|
||||
->label('Kirim Kepada')
|
||||
->required()
|
||||
->relationship('partnerMedia', 'name')
|
||||
->visible(fn ($get) => in_array($get('type'), [AnnouncementType::COMPANY, AnnouncementType::COMPANY->value]))
|
||||
->required(fn ($get) => in_array($get('type'), [AnnouncementType::COMPANY, AnnouncementType::COMPANY->value]))
|
||||
->options(function () {
|
||||
return PartnerMedia::query()->pluck('name', 'id');
|
||||
})
|
||||
@ -82,12 +93,17 @@ public static function table(Table $table): Table
|
||||
->wrap()
|
||||
->limit(100),
|
||||
|
||||
TextColumn::make('type')
|
||||
->label('Tipe')
|
||||
->badge()
|
||||
->sortable(),
|
||||
|
||||
TextColumn::make('partnerMedia.name')
|
||||
->label('Penerima')
|
||||
->listWithLineBreaks()
|
||||
->limitList(3)
|
||||
->expandableLimitedList()
|
||||
->placeholder('Tidak ada penerima'),
|
||||
->placeholder(fn ($record) => $record->type === AnnouncementType::PUBLIC ? 'Publik' : 'Tidak ada penerima'),
|
||||
|
||||
...TimestampColumns::make(),
|
||||
])
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Enums\AnnouncementType;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
@ -13,6 +14,13 @@ class Announcement extends Model
|
||||
|
||||
protected $guarded = ['id'];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'type' => AnnouncementType::class,
|
||||
];
|
||||
}
|
||||
|
||||
public function partnerMedia(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(PartnerMedia::class, 'announcement_media');
|
||||
|
||||
@ -28,7 +28,7 @@ public function up(): void
|
||||
$table->string('annual_tax_return', 100);
|
||||
$table->string('domicile_certificate', 100);
|
||||
$table->string('profile', 100);
|
||||
$table->enum('status', VerificationStatus::cases())->default(VerificationStatus::PENDING)->comment(VerificationStatus::comment())->after('validated_at');
|
||||
$table->enum('status', VerificationStatus::cases())->default(VerificationStatus::PENDING)->comment(VerificationStatus::comment());
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
$table->timestamp('updated_at')->nullable()->useCurrentOnUpdate();
|
||||
$table->softDeletes();
|
||||
|
||||
@ -25,7 +25,7 @@ public function up(): void
|
||||
$table->enum('classification', [MediaClassification::values()])->comment(MediaClassification::comment());
|
||||
$table->string('journalism_organization')->nullable();
|
||||
$table->string('press_council_certificate')->nullable();
|
||||
$table->enum('status', VerificationStatus::cases())->default(VerificationStatus::PENDING)->comment(VerificationStatus::comment())->after('profile');
|
||||
$table->enum('status', VerificationStatus::cases())->default(VerificationStatus::PENDING)->comment(VerificationStatus::comment());
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
$table->timestamp('updated_at')->nullable()->useCurrentOnUpdate();
|
||||
$table->softDeletes();
|
||||
|
||||
@ -21,7 +21,7 @@ public function up(): void
|
||||
$table->string('phone_number', 20);
|
||||
$table->string('press_card', 100)->nullable();
|
||||
$table->string('ukw_certificate', 100)->nullable();
|
||||
$table->enum('status', VerificationStatus::cases())->default(VerificationStatus::PENDING)->comment(VerificationStatus::comment())->after('profile');
|
||||
$table->enum('status', VerificationStatus::cases())->default(VerificationStatus::PENDING)->comment(VerificationStatus::comment());
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
$table->timestamp('updated_at')->nullable()->useCurrentOnUpdate();
|
||||
$table->softDeletes();
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
<?php
|
||||
|
||||
use App\Enums\AnnouncementType;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
@ -14,6 +15,7 @@ public function up(): void
|
||||
Schema::create('announcements', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->text('content');
|
||||
$table->enum('type', AnnouncementType::values())->default(AnnouncementType::PUBLIC)->comment(AnnouncementType::comment());
|
||||
$table->timestamp('created_at')->useCurrent();
|
||||
$table->timestamp('updated_at')->nullable()->useCurrentOnUpdate();
|
||||
$table->softDeletes();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user