feat: add ShareAttendanceAction to class sessions to generate and share attendance links via WhatsApp
This commit is contained in:
parent
95b89efcaa
commit
1f8fec8ccf
@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Filament\Resources\Learning\ClassSessions\Actions;
|
||||
|
||||
use App\Models\ClassSession;
|
||||
use Filament\Actions\Action;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class ShareAttendanceAction extends Action
|
||||
{
|
||||
public static function getDefaultName(): ?string
|
||||
{
|
||||
return 'shareAttendance';
|
||||
}
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
|
||||
$this->label('Bagikan')
|
||||
->icon('heroicon-o-share')
|
||||
->color('info')
|
||||
->link()
|
||||
->action(function (array $arguments, $livewire) {
|
||||
$course = $livewire->course;
|
||||
if (empty($course->sharing_token)) {
|
||||
$course->update(['sharing_token' => Str::random(32)]);
|
||||
}
|
||||
|
||||
$session = ClassSession::find($arguments['session'] ?? null);
|
||||
$date = $session ? $session->date->toDateString() : null;
|
||||
|
||||
$url = route('share.attendance', ['token' => $course->sharing_token, 'date' => $date]);
|
||||
|
||||
$text = "*Info Kelas {$course->name}*\nSesi ke-".($session->session_number ?? '-').' ('.($session->date->translatedFormat('d M Y') ?? '').")\n\nSilakan cek detail/rekap kehadiran melalui tautan ini:\n\n{$url}";
|
||||
|
||||
$escapedText = json_encode($text);
|
||||
|
||||
$livewire->js(
|
||||
<<<JS
|
||||
const text = {$escapedText};
|
||||
const url = 'https://wa.me/?text=' + encodeURIComponent(text);
|
||||
|
||||
if (navigator.clipboard) {
|
||||
navigator.clipboard.writeText(text).catch(() => {});
|
||||
}
|
||||
window.open(url, '_blank');
|
||||
JS
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
@ -7,6 +7,7 @@
|
||||
use App\Filament\Resources\Learning\ClassSessions\Actions\DeleteSessionAction;
|
||||
use App\Filament\Resources\Learning\ClassSessions\Actions\EditSessionAction;
|
||||
use App\Filament\Resources\Learning\ClassSessions\Actions\GenerateSessionsAction;
|
||||
use App\Filament\Resources\Learning\ClassSessions\Actions\ShareAttendanceAction;
|
||||
use App\Filament\Resources\Learning\ClassSessions\Actions\ViewAssignmentDetailAction;
|
||||
use App\Filament\Resources\Learning\ClassSessions\Actions\ViewAssignmentsAction;
|
||||
use App\Filament\Resources\Learning\ClassSessions\Actions\ViewAttendanceAction;
|
||||
@ -142,6 +143,7 @@ protected function getHeaderActions(): array
|
||||
protected function getActions(): array
|
||||
{
|
||||
return [
|
||||
$this->shareAttendanceAction(),
|
||||
$this->viewAttendanceAction(),
|
||||
$this->viewMaterialsAction(),
|
||||
$this->viewAssignmentsAction(),
|
||||
@ -152,6 +154,11 @@ protected function getActions(): array
|
||||
];
|
||||
}
|
||||
|
||||
public function shareAttendanceAction(): Action
|
||||
{
|
||||
return ShareAttendanceAction::make();
|
||||
}
|
||||
|
||||
public function viewAttendanceAction(): Action
|
||||
{
|
||||
return ViewAttendanceAction::make();
|
||||
|
||||
@ -54,6 +54,7 @@
|
||||
|
||||
|
||||
<div class="flex flex-wrap items-center gap-3 px-4 py-3 border-t border-gray-100 dark:border-gray-700">
|
||||
{{ ($this->shareAttendanceAction)(['session' => $session->id]) }}
|
||||
{{ ($this->viewAttendanceAction)(['session' => $session->id]) }}
|
||||
{{ ($this->viewMaterialsAction)(['session' => $session->id]) }}
|
||||
{{ ($this->viewAssignmentsAction)(['session' => $session->id]) }}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user