This commit is contained in:
Mekan1206
2026-06-03 22:15:17 +05:00
parent 6f3069f619
commit 7cef2543b9
3 changed files with 1 additions and 122 deletions

View File

@@ -43,10 +43,6 @@ class SendSms extends Page
*/
public ?array $data = [];
public ?int $activeCampaignId = null;
public bool $campaignNotificationSent = false;
public static function getNavigationLabel(): string
{
return __('filament.send_sms.navigation');
@@ -131,8 +127,7 @@ class SendSms extends Page
->modalHeading(__('filament.send_sms.actions.send_confirm_heading'))
->modalDescription(fn (): string => $this->confirmationDescription())
->modalSubmitActionLabel(__('filament.send_sms.actions.send_confirm_submit'))
->action('sendCampaign')
->disabled(fn (): bool => $this->activeCampaignId !== null && ! $this->isCampaignComplete()),
->action('sendCampaign'),
]),
]),
]);
@@ -140,15 +135,6 @@ class SendSms extends Page
public function sendCampaign(): void
{
if ($this->activeCampaignId !== null && ! $this->isCampaignComplete()) {
Notification::make()
->title(__('filament.send_sms.notifications.campaign_still_sending'))
->warning()
->send();
return;
}
$data = $this->form->getState();
$validator = Validator::make($data, [
@@ -192,9 +178,6 @@ class SendSms extends Page
excludedIds: $excludedIds,
);
$this->activeCampaignId = $campaign->id;
$this->campaignNotificationSent = false;
if ($campaign->isComplete()) {
$this->notifyCampaignFinished($campaign);
} else {
@@ -206,32 +189,8 @@ class SendSms extends Page
}
}
public function refreshCampaignProgress(): void
{
if ($this->activeCampaignId === null) {
return;
}
$campaign = SmsCampaign::query()->find($this->activeCampaignId);
if ($campaign === null) {
$this->activeCampaignId = null;
return;
}
if ($campaign->isComplete()) {
$this->notifyCampaignFinished($campaign);
}
}
protected function notifyCampaignFinished(SmsCampaign $campaign): void
{
if ($this->campaignNotificationSent) {
return;
}
$this->campaignNotificationSent = true;
$campaign->refresh();
if ($campaign->failed_count > 0 && $campaign->sent_count === 0) {
@@ -259,18 +218,6 @@ class SendSms extends Page
}
}
protected function isCampaignComplete(): bool
{
if ($this->activeCampaignId === null) {
return true;
}
return SmsCampaign::query()
->whereKey($this->activeCampaignId)
->whereNotNull('completed_at')
->exists();
}
protected function confirmationDescription(): string
{
$message = (string) ($this->data['message'] ?? '');
@@ -297,47 +244,6 @@ class SendSms extends Page
->count();
}
public function getCampaignProgressPercent(): int
{
if ($this->activeCampaignId === null) {
return 0;
}
$campaign = SmsCampaign::query()->find($this->activeCampaignId);
return $campaign?->progressPercent() ?? 0;
}
public function getCampaignProgressLabel(): string
{
if ($this->activeCampaignId === null) {
return '';
}
$campaign = SmsCampaign::query()->find($this->activeCampaignId);
if ($campaign === null) {
return '';
}
return __('filament.send_sms.progress.processed', [
'processed' => $campaign->processedCount(),
'total' => $campaign->recipient_count,
'sent' => $campaign->sent_count,
]);
}
/**
* @return array<string, mixed>
*/
protected function getViewData(): array
{
return [
'campaignProgressPercent' => $this->getCampaignProgressPercent(),
'campaignProgressLabel' => $this->getCampaignProgressLabel(),
];
}
/**
* @return array<int, string>
*/