refactor: replace client-side clipboard copy logic with server-side JS injection and Filament notifications
This commit is contained in:
@@ -32,14 +32,18 @@ class EditProposal extends EditRecord
|
|||||||
->icon('heroicon-o-clipboard-document-check')
|
->icon('heroicon-o-clipboard-document-check')
|
||||||
->color('info')
|
->color('info')
|
||||||
->action(function () {
|
->action(function () {
|
||||||
// JS ile kopyalama yapar, bildirim göster
|
|
||||||
})
|
|
||||||
->extraAttributes(function () {
|
|
||||||
$url = route('proposals.show', $this->record->slug);
|
$url = route('proposals.show', $this->record->slug);
|
||||||
return [
|
|
||||||
'x-data' => '',
|
// Livewire v3: sunucu tarafında JS enjekte et (user-gesture gerektirmez)
|
||||||
'x-on:click' => "navigator.clipboard.writeText('{$url}').then(() => { \$dispatch('open-notification', { title: '" . __('proposal.link_copied') . "', type: 'success' }) })",
|
$escaped = addslashes($url);
|
||||||
];
|
$this->js("(function(){var t=document.createElement('textarea');t.value='{$escaped}';t.style.position='fixed';t.style.opacity='0';document.body.appendChild(t);t.focus();t.select();try{document.execCommand('copy')}catch(e){}document.body.removeChild(t);})();");
|
||||||
|
|
||||||
|
Notification::make()
|
||||||
|
->title(__('proposal.link_copied'))
|
||||||
|
->body($url)
|
||||||
|
->success()
|
||||||
|
->duration(6000)
|
||||||
|
->send();
|
||||||
})
|
})
|
||||||
->visible(fn () => $this->record !== null),
|
->visible(fn () => $this->record !== null),
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user