feat: add proposal link regeneration and copy-to-clipboard actions to edit page

This commit is contained in:
Ümit Tunç
2026-05-25 07:32:25 +03:00
parent 92af30f61b
commit 81b94e8635
3 changed files with 77 additions and 0 deletions
@@ -3,8 +3,11 @@
namespace App\Filament\Admin\Resources\Proposals\Pages;
use App\Filament\Admin\Resources\Proposals\ProposalResource;
use Filament\Actions\Action;
use Filament\Notifications\Notification;
use Filament\Resources\Pages\EditRecord;
use Filament\Support\Enums\Width;
use Illuminate\Support\Str;
class EditProposal extends EditRecord
{
@@ -19,5 +22,69 @@ class EditProposal extends EditRecord
{
return Width::Full;
}
protected function getHeaderActions(): array
{
return [
// Teklif linkini tarayıcı panosuna kopyala
Action::make('copy_link')
->label(__('proposal.copy_link'))
->icon('heroicon-o-clipboard-document-check')
->color('info')
->action(function () {
// JS ile kopyalama yapar, bildirim göster
})
->extraAttributes(function () {
$url = route('proposals.show', $this->record->slug);
return [
'x-data' => '',
'x-on:click' => "navigator.clipboard.writeText('{$url}').then(() => { \$dispatch('open-notification', { title: '" . __('proposal.link_copied') . "', type: 'success' }) })",
];
})
->visible(fn () => $this->record !== null),
// Yeni rastgele benzersiz slug üret ve kaydet
Action::make('regenerate_slug')
->label(__('proposal.regenerate_slug'))
->icon('heroicon-o-arrow-path')
->color('warning')
->requiresConfirmation()
->modalHeading(__('proposal.regenerate_slug_confirm_heading'))
->modalDescription(__('proposal.regenerate_slug_confirm_body'))
->modalSubmitActionLabel(__('proposal.regenerate_slug_confirm_button'))
->action(function () {
$newSlug = 'teklif-' . strtolower(Str::random(4)) . '-' . date('ymd') . '-' . strtolower(Str::random(4));
// Benzersizliği garanti et
while (\App\Models\Proposal::where('slug', $newSlug)->where('id', '!=', $this->record->id)->exists()) {
$newSlug = 'teklif-' . strtolower(Str::random(4)) . '-' . date('ymd') . '-' . strtolower(Str::random(4));
}
$this->record->update(['slug' => $newSlug]);
$newUrl = route('proposals.show', $newSlug);
Notification::make()
->title(__('proposal.regenerate_slug_success'))
->body($newUrl)
->success()
->duration(8000)
->send();
// Formu yenile
$this->fillForm();
})
->visible(fn () => $this->record !== null),
// Teklifi yeni sekmede önizle
Action::make('preview')
->label(__('proposal.preview'))
->icon('heroicon-o-eye')
->color('gray')
->url(fn () => $this->record ? route('proposals.show', $this->record->slug) : '#')
->openUrlInNewTab()
->visible(fn () => $this->record !== null),
];
}
}
+5
View File
@@ -53,4 +53,9 @@ return [
'copy_link' => 'Copy Proposal Link',
'link_copied' => 'Proposal link copied to clipboard!',
'preview' => 'Preview Proposal',
'regenerate_slug' => 'Generate New Link',
'regenerate_slug_confirm_heading' => 'Generate New Random Link',
'regenerate_slug_confirm_body' => 'The current URL will be replaced and the old link will no longer work. Are you sure?',
'regenerate_slug_confirm_button' => 'Yes, Generate New Link',
'regenerate_slug_success' => 'New proposal link generated!',
];
+5
View File
@@ -53,4 +53,9 @@ return [
'copy_link' => 'Teklif Linkini Kopyala',
'link_copied' => 'Teklif bağlantısı panoya kopyalandı!',
'preview' => 'Teklifi Önizle',
'regenerate_slug' => 'Yeni Link Üret',
'regenerate_slug_confirm_heading' => 'Yeni Rastgele Link Oluştur',
'regenerate_slug_confirm_body' => 'Mevcut bağlantı adresi değiştirilecek ve eski link artık çalışmayacak. Onaylıyor musunuz?',
'regenerate_slug_confirm_button' => 'Evet, Yeni Link Üret',
'regenerate_slug_success' => 'Yeni teklif linki oluşturuldu!',
];