fix: poin kehadiran dibuat otomatis via AttachAction after hook
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Filament\Resources\Activities\RelationManagers;
|
||||
|
||||
use App\Models\MemberPoint;
|
||||
use Filament\Actions\AttachAction;
|
||||
use Filament\Actions\BulkActionGroup;
|
||||
use Filament\Actions\DetachBulkAction;
|
||||
@@ -51,7 +52,16 @@ class ParticipantsRelationManager extends RelationManager
|
||||
->options(['hadir' => 'Hadir', 'izin' => 'Izin', 'alpha' => 'Alpha'])
|
||||
->default('hadir')->required(),
|
||||
Textarea::make('notes')->label('Catatan')->rows(2),
|
||||
]),
|
||||
])
|
||||
->after(function (AttachAction $action, array $data) {
|
||||
if (($data['status'] ?? 'hadir') === 'hadir') {
|
||||
$activity = $this->getOwnerRecord();
|
||||
MemberPoint::firstOrCreate(
|
||||
['user_id' => $data['recordId'], 'source_type' => 'activity', 'source_id' => $activity->id],
|
||||
['points' => 10, 'reason' => "Hadir di kegiatan: {$activity->title}"]
|
||||
);
|
||||
}
|
||||
}),
|
||||
])
|
||||
->recordActions([EditAction::make()])
|
||||
->toolbarActions([BulkActionGroup::make([DetachBulkAction::make()])]);
|
||||
|
||||
@@ -4,7 +4,6 @@ namespace App\Observers;
|
||||
|
||||
use App\Models\Activity;
|
||||
use App\Models\ActivityLog;
|
||||
use App\Models\MemberPoint;
|
||||
use App\Services\NotificationService;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
@@ -67,21 +66,4 @@ class ActivityObserver
|
||||
'description' => "Kegiatan baru dibuat: {$activity->title}",
|
||||
]);
|
||||
}
|
||||
|
||||
public function pivotAttached(Activity $activity, string $relationName, array $pivotIds, array $pivotIdsAttributes): void
|
||||
{
|
||||
if ($relationName !== 'participants') return;
|
||||
|
||||
foreach ($pivotIdsAttributes as $userId => $attrs) {
|
||||
if (($attrs['status'] ?? 'hadir') === 'hadir') {
|
||||
MemberPoint::create([
|
||||
'user_id' => $userId,
|
||||
'points' => 10,
|
||||
'reason' => "Hadir di kegiatan: {$activity->title}",
|
||||
'source_type' => 'activity',
|
||||
'source_id' => $activity->id,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user