114 lines
5.3 KiB
PHP
114 lines
5.3 KiB
PHP
<?php
|
|
|
|
namespace App\Filament\Pages\AdminVerification\Actions\Concerns;
|
|
|
|
use App\Enums\DecisionAdmin;
|
|
use App\Enums\VerificationStatus;
|
|
use App\Filament\Pages\Verification;
|
|
use App\Filament\Support\CheerfulNotification;
|
|
use App\Models\VerificationRequest;
|
|
use App\Models\VerificationReview;
|
|
use App\Notifications\BroadcastNotification;
|
|
use Filament\Actions\Action;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
trait CanProcessReview
|
|
{
|
|
protected function processReview(int $requestId, DecisionAdmin $decision, ?string $note): void
|
|
{
|
|
$verificationRequest = VerificationRequest::with(['company.partnerMedia.journalists'])->find($requestId);
|
|
|
|
if (! $verificationRequest) {
|
|
CheerfulNotification::danger(
|
|
CheerfulNotification::getMessage('Belum ketemu nih 🙌', 'Data Tidak Ditemukan'),
|
|
CheerfulNotification::getMessage('Data verifikasi belum kami temukan. Coba sebentar lagi, ya.', 'Permintaan verifikasi tidak ditemukan dalam sistem kami.')
|
|
)
|
|
->send();
|
|
|
|
return;
|
|
}
|
|
|
|
try {
|
|
DB::beginTransaction();
|
|
|
|
// Create review record
|
|
VerificationReview::create([
|
|
'verification_request_id' => $verificationRequest->id,
|
|
'reviewer_id' => auth()->id(),
|
|
'decision' => $decision,
|
|
'note' => $note,
|
|
]);
|
|
|
|
// Update verification request status
|
|
$newStatus = match ($decision) {
|
|
DecisionAdmin::APPROVED => VerificationStatus::APPROVED,
|
|
DecisionAdmin::NEED_REVISION => VerificationStatus::NEED_REVISION,
|
|
DecisionAdmin::REJECTED => VerificationStatus::REJECTED,
|
|
};
|
|
|
|
$verificationRequest->update([
|
|
'status' => $newStatus,
|
|
]);
|
|
|
|
DB::commit();
|
|
|
|
$actionLabel = match ($decision) {
|
|
DecisionAdmin::APPROVED => 'disetujui',
|
|
DecisionAdmin::NEED_REVISION => 'diminta revisi',
|
|
DecisionAdmin::REJECTED => 'ditolak',
|
|
};
|
|
|
|
CheerfulNotification::success(
|
|
CheerfulNotification::getMessage('Berhasil Diproses! ✨', 'Berhasil Diproses'),
|
|
CheerfulNotification::getMessage("Mantap! Verifikasi telah {$actionLabel} dan notifikasi sudah dikirim ke pengguna. Kerja bagus, Admin! 💪", "Proses verifikasi telah {$actionLabel} dan notifikasi telah dikirimkan ke pihak pengguna.")
|
|
)
|
|
->send();
|
|
|
|
// Notify User
|
|
$partnerUser = $verificationRequest->company?->user;
|
|
if ($partnerUser) {
|
|
$statusTitle = match ($decision) {
|
|
DecisionAdmin::APPROVED => CheerfulNotification::getMessage('Horee! Verifikasi Disetujui 🎉', 'Verifikasi Disetujui'),
|
|
DecisionAdmin::NEED_REVISION => CheerfulNotification::getMessage('Yah, Ada Yang Perlu Direvisi nih 📝', 'Perlu Revisi Verifikasi'),
|
|
DecisionAdmin::REJECTED => CheerfulNotification::getMessage('Maaf, Verifikasi Ditolak 😔', 'Verifikasi Ditolak'),
|
|
};
|
|
|
|
$body = match ($decision) {
|
|
DecisionAdmin::APPROVED => CheerfulNotification::getMessage('Yeay! Pengajuan verifikasi perusahaan Anda telah disetujui. Sekarang Anda sudah resmi terverifikasi dan bekerja sama dengan kami! 🎊', 'Pengajuan verifikasi perusahaan Anda telah disetujui.'),
|
|
DecisionAdmin::NEED_REVISION => CheerfulNotification::getMessage('Ayo sedikit lagi! Admin meminta beberapa perbaikan pada pengajuan Anda agar bisa segera disetujui. 💪', 'Admin meminta beberapa perbaikan pada pengajuan verifikasi Anda.'),
|
|
DecisionAdmin::REJECTED => CheerfulNotification::getMessage('Yah, maaf banget... pengajuan verifikasi perusahaan Anda belum bisa kami terima saat ini. 💔', 'Pengajuan verifikasi perusahaan Anda tidak dapat kami setujui saat ini.'),
|
|
};
|
|
|
|
if ($note) {
|
|
$body .= "\n\n".CheerfulNotification::getMessage("Catatan Admin: {$note} 😊", "Catatan Admin: {$note}");
|
|
}
|
|
|
|
$partnerUser->notify(new BroadcastNotification([
|
|
'title' => $statusTitle,
|
|
'body' => $body,
|
|
'action' => [
|
|
Action::make('view')
|
|
->label('Lihat')
|
|
->url(Verification::getUrl()),
|
|
],
|
|
]));
|
|
}
|
|
} catch (\Throwable $e) {
|
|
DB::rollBack();
|
|
Log::error('Verification processing failed', [
|
|
'error' => $e->getMessage(),
|
|
'trace' => $e->getTraceAsString(),
|
|
'request_id' => $requestId,
|
|
'decision' => $decision->value,
|
|
]);
|
|
|
|
CheerfulNotification::danger(
|
|
CheerfulNotification::getMessage('Terjadi Kesalahan ⚠️', 'Terjadi Kesalahan Sistem'),
|
|
CheerfulNotification::getMessage('Proses verifikasi gagal karena kesalahan sistem. Tim kami sudah mencatat masalah ini. Silakan coba lagi nanti.', 'Proses verifikasi gagal dilakukan karena kendala teknis. Silakan laporkan jika masalah berlanjut.')
|
|
)
|
|
->send();
|
|
}
|
|
}
|
|
}
|