78 lines
1.7 KiB
PHP
78 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Livewire\Modals;
|
|
|
|
use Illuminate\View\View;
|
|
use Livewire\Attributes\Computed;
|
|
use LivewireUI\Modal\ModalComponent;
|
|
|
|
class UtmBuilder extends ModalComponent
|
|
{
|
|
public string $baseUrl = '';
|
|
|
|
public string $utmSource = '';
|
|
|
|
public string $utmMedium = '';
|
|
|
|
public string $utmCampaign = '';
|
|
|
|
public string $utmContent = '';
|
|
|
|
public string $utmTerm = '';
|
|
|
|
public bool $copied = false;
|
|
|
|
#[Computed]
|
|
public function fullUrl(): string
|
|
{
|
|
if (! $this->baseUrl) {
|
|
return '';
|
|
}
|
|
|
|
$params = array_filter([
|
|
'utm_source' => $this->utmSource,
|
|
'utm_medium' => $this->utmMedium,
|
|
'utm_campaign' => $this->utmCampaign,
|
|
'utm_content' => $this->utmContent,
|
|
'utm_term' => $this->utmTerm,
|
|
]);
|
|
|
|
if (! $params) {
|
|
return $this->baseUrl;
|
|
}
|
|
|
|
$sep = str_contains($this->baseUrl, '?') ? '&' : '?';
|
|
|
|
return $this->baseUrl.$sep.http_build_query($params);
|
|
}
|
|
|
|
public function copyToClipboard(): void
|
|
{
|
|
$this->dispatch('copy-to-clipboard', text: $this->fullUrl);
|
|
$this->copied = true;
|
|
}
|
|
|
|
public function createLink(): void
|
|
{
|
|
$url = $this->fullUrl;
|
|
$this->closeModal();
|
|
$ws = current_workspace();
|
|
if ($ws) {
|
|
$this->dispatch('openModal', component: 'modals.create-link', arguments: [
|
|
'workspaceUlid' => $ws->ulid,
|
|
'prefillUrl' => $url,
|
|
]);
|
|
}
|
|
}
|
|
|
|
public static function modalMaxWidth(): string
|
|
{
|
|
return 'lg';
|
|
}
|
|
|
|
public function render(): View
|
|
{
|
|
return view('livewire.modals.utm-builder');
|
|
}
|
|
}
|