Refactor SMS campaign handling to dispatch a job for starting campaigns and update notification messages for improved user feedback.
This commit is contained in:
@@ -2,8 +2,8 @@
|
||||
|
||||
namespace App\Filament\Pages;
|
||||
|
||||
use App\Jobs\StartSmsCampaignJob;
|
||||
use App\Models\Coupon;
|
||||
use App\Models\SmsCampaign;
|
||||
use App\Services\SmsBroadcastService;
|
||||
use App\Services\SmsMessageAnalyzer;
|
||||
use BackedEnum;
|
||||
@@ -170,52 +170,19 @@ class SendSms extends Page
|
||||
return;
|
||||
}
|
||||
|
||||
$campaign = $service->startCampaign(
|
||||
admin: auth()->user(),
|
||||
StartSmsCampaignJob::dispatch(
|
||||
adminId: auth()->id(),
|
||||
message: $data['message'],
|
||||
sendToAll: $sendToAll,
|
||||
selectedIds: $selectedIds,
|
||||
excludedIds: $excludedIds,
|
||||
);
|
||||
|
||||
if ($campaign->isComplete()) {
|
||||
$this->notifyCampaignFinished($campaign);
|
||||
} else {
|
||||
Notification::make()
|
||||
->title(__('filament.send_sms.notifications.queued'))
|
||||
->body(__('filament.send_sms.notifications.queued_body', ['count' => $campaign->recipient_count]))
|
||||
->success()
|
||||
->send();
|
||||
}
|
||||
}
|
||||
|
||||
protected function notifyCampaignFinished(SmsCampaign $campaign): void
|
||||
{
|
||||
$campaign->refresh();
|
||||
|
||||
if ($campaign->failed_count > 0 && $campaign->sent_count === 0) {
|
||||
Notification::make()
|
||||
->title(__('filament.send_sms.notifications.failed'))
|
||||
->body(__('filament.send_sms.notifications.failed_body', ['count' => $campaign->failed_count]))
|
||||
->danger()
|
||||
->send();
|
||||
} elseif ($campaign->failed_count > 0) {
|
||||
Notification::make()
|
||||
->title(__('filament.send_sms.notifications.finished_with_errors'))
|
||||
->body(__('filament.send_sms.notifications.finished_with_errors_body', [
|
||||
'sent' => $campaign->sent_count,
|
||||
'failed' => $campaign->failed_count,
|
||||
'skipped' => $campaign->skipped_count,
|
||||
]))
|
||||
->warning()
|
||||
->send();
|
||||
} else {
|
||||
Notification::make()
|
||||
->title(__('filament.send_sms.notifications.completed'))
|
||||
->body(__('filament.send_sms.notifications.completed_body', ['count' => $campaign->sent_count]))
|
||||
->success()
|
||||
->send();
|
||||
}
|
||||
Notification::make()
|
||||
->title(__('filament.send_sms.notifications.submitted'))
|
||||
->body(__('filament.send_sms.notifications.submitted_body', ['count' => $willReceive]))
|
||||
->success()
|
||||
->send();
|
||||
}
|
||||
|
||||
protected function confirmationDescription(): string
|
||||
|
||||
Reference in New Issue
Block a user