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 ?array $data = [];
public ?int $activeCampaignId = null;
public bool $campaignNotificationSent = false;
public static function getNavigationLabel(): string public static function getNavigationLabel(): string
{ {
return __('filament.send_sms.navigation'); return __('filament.send_sms.navigation');
@@ -131,8 +127,7 @@ class SendSms extends Page
->modalHeading(__('filament.send_sms.actions.send_confirm_heading')) ->modalHeading(__('filament.send_sms.actions.send_confirm_heading'))
->modalDescription(fn (): string => $this->confirmationDescription()) ->modalDescription(fn (): string => $this->confirmationDescription())
->modalSubmitActionLabel(__('filament.send_sms.actions.send_confirm_submit')) ->modalSubmitActionLabel(__('filament.send_sms.actions.send_confirm_submit'))
->action('sendCampaign') ->action('sendCampaign'),
->disabled(fn (): bool => $this->activeCampaignId !== null && ! $this->isCampaignComplete()),
]), ]),
]), ]),
]); ]);
@@ -140,15 +135,6 @@ class SendSms extends Page
public function sendCampaign(): void 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(); $data = $this->form->getState();
$validator = Validator::make($data, [ $validator = Validator::make($data, [
@@ -192,9 +178,6 @@ class SendSms extends Page
excludedIds: $excludedIds, excludedIds: $excludedIds,
); );
$this->activeCampaignId = $campaign->id;
$this->campaignNotificationSent = false;
if ($campaign->isComplete()) { if ($campaign->isComplete()) {
$this->notifyCampaignFinished($campaign); $this->notifyCampaignFinished($campaign);
} else { } 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 protected function notifyCampaignFinished(SmsCampaign $campaign): void
{ {
if ($this->campaignNotificationSent) {
return;
}
$this->campaignNotificationSent = true;
$campaign->refresh(); $campaign->refresh();
if ($campaign->failed_count > 0 && $campaign->sent_count === 0) { 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 protected function confirmationDescription(): string
{ {
$message = (string) ($this->data['message'] ?? ''); $message = (string) ($this->data['message'] ?? '');
@@ -297,47 +244,6 @@ class SendSms extends Page
->count(); ->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> * @return array<int, string>
*/ */

View File

@@ -35,12 +35,7 @@ return [
'send_confirm_heading' => 'SMS häzir ibermeli?', 'send_confirm_heading' => 'SMS häzir ibermeli?',
'send_confirm_submit' => 'Iber', 'send_confirm_submit' => 'Iber',
], ],
'progress' => [
'sending' => 'Habarlar iberilýär…',
'processed' => ':processed / :total işlendi · :sent iberildi',
],
'notifications' => [ 'notifications' => [
'campaign_still_sending' => 'Kampaniýa entek iberilýär',
'no_valid_recipients' => 'Dogry alyjy ýok', 'no_valid_recipients' => 'Dogry alyjy ýok',
'no_valid_recipients_body' => 'Saýlawy ýa-da aýyrmalary üýtgediň — dogry telefon belgili kupon eýesi bu habary almaz.', 'no_valid_recipients_body' => 'Saýlawy ýa-da aýyrmalary üýtgediň — dogry telefon belgili kupon eýesi bu habary almaz.',
'queued' => 'SMS kampaniýasy nobata goýuldy', 'queued' => 'SMS kampaniýasy nobata goýuldy',

View File

@@ -1,25 +1,3 @@
<x-filament-panels::page> <x-filament-panels::page>
@if ($activeCampaignId)
<div
wire:poll.2s="refreshCampaignProgress"
class="mb-6 rounded-xl border border-primary-200 bg-primary-50 p-4 dark:border-primary-800 dark:bg-primary-950"
>
<div class="mb-2 flex items-center justify-between gap-4">
<p class="text-sm font-medium text-primary-900 dark:text-primary-100">
{{ __('filament.send_sms.progress.sending') }}
</p>
<p class="text-sm text-primary-700 dark:text-primary-300">
{{ $campaignProgressLabel }}
</p>
</div>
<div class="h-2 overflow-hidden rounded-full bg-primary-200 dark:bg-primary-900">
<div
class="h-full rounded-full bg-primary-600 transition-all duration-300 dark:bg-primary-400"
style="width: {{ $campaignProgressPercent }}%"
></div>
</div>
</div>
@endif
{{ $this->content }} {{ $this->content }}
</x-filament-panels::page> </x-filament-panels::page>