diff --git a/app/Livewire/Modals/CreateBioPage.php b/app/Livewire/Modals/CreateBioPage.php index 88f63c1..7a0a0bd 100644 --- a/app/Livewire/Modals/CreateBioPage.php +++ b/app/Livewire/Modals/CreateBioPage.php @@ -3,12 +3,17 @@ namespace App\Livewire\Modals; use App\Domains\Bio\Models\BioPage; +use App\Domains\Workspace\Models\Workspace; use Illuminate\Support\Str; use Illuminate\View\View; use LivewireUI\Modal\ModalComponent; class CreateBioPage extends ModalComponent { + public string $workspaceUlid = ''; + + public int $workspaceId = 0; + public string $title = ''; public string $slug = ''; @@ -21,24 +26,39 @@ class CreateBioPage extends ModalComponent ]; } + public function mount(string $workspaceUlid = ''): void + { + if ($workspaceUlid) { + $workspace = Workspace::where('ulid', $workspaceUlid)->firstOrFail(); + abort_unless( + $workspace->owner_id === auth()->id() || + $workspace->members()->where('user_id', auth()->id())->exists(), + 404 + ); + $this->workspaceUlid = $workspaceUlid; + $this->workspaceId = $workspace->id; + } + } + public function save(): void { $this->validate(); - $workspace = app('current_workspace'); + + $wsId = $this->workspaceId ?: require_workspace()->id; if (empty($this->slug)) { $this->slug = Str::slug($this->title).'-'.Str::random(4); } BioPage::create([ - 'workspace_id' => $workspace->id, + 'workspace_id' => $wsId, 'slug' => $this->slug, 'title' => ['en' => $this->title, 'de' => $this->title], 'theme' => [], 'is_published' => false, ]); - $this->dispatch('bioPageCreated'); + $this->dispatch('bio-created')->to(\App\Livewire\Pages\Bio\Index::class); $this->dispatch('toast', message: 'Bio Page erstellt', type: 'success'); $this->closeModal(); } diff --git a/app/Livewire/Modals/CreateLink.php b/app/Livewire/Modals/CreateLink.php index a6bd76e..50ae888 100644 --- a/app/Livewire/Modals/CreateLink.php +++ b/app/Livewire/Modals/CreateLink.php @@ -2,24 +2,67 @@ namespace App\Livewire\Modals; +use App\Domains\Ai\Services\SlugSuggester; use App\Domains\Link\Models\Link; +use App\Domains\Workspace\Models\Workspace; use Illuminate\Support\Str; use Illuminate\View\View; +use Livewire\Attributes\Validate; use LivewireUI\Modal\ModalComponent; class CreateLink extends ModalComponent { + public string $workspaceUlid = ''; + + public int $workspaceId = 0; + + #[Validate('required|url|max:2048')] public string $targetUrl = ''; + #[Validate('nullable|alpha_dash|min:3|max:64')] public string $slug = ''; + #[Validate('nullable|string|max:200')] public string $title = ''; - protected $rules = [ - 'targetUrl' => 'required|url|max:2048', - 'slug' => 'nullable|alpha_dash|max:50|unique:links,slug', - 'title' => 'nullable|max:200', - ]; + public bool $autoSlug = true; + + /** @var string[] */ + public array $slugSuggestions = []; + + public bool $aiLoading = false; + + public function mount(string $workspaceUlid = ''): void + { + if ($workspaceUlid) { + $workspace = Workspace::where('ulid', $workspaceUlid)->firstOrFail(); + abort_unless( + $workspace->owner_id === auth()->id() || + $workspace->members()->where('user_id', auth()->id())->exists(), + 404 + ); + $this->workspaceUlid = $workspaceUlid; + $this->workspaceId = $workspace->id; + } + } + + public function updatedTargetUrl(string $value): void + { + if ($this->autoSlug && $value) { + $this->slug = Str::random(6); + } + } + + public function updatedSlug(): void + { + $this->autoSlug = false; + } + + public function regenerateSlug(): void + { + $this->slug = Str::random(6); + $this->autoSlug = true; + } public function generateSlug(): void { @@ -28,24 +71,49 @@ class CreateLink extends ModalComponent } } + public function suggestSlugs(): void + { + if (! $this->targetUrl) { + return; + } + $this->aiLoading = true; + $this->slugSuggestions = app(SlugSuggester::class)->suggest($this->targetUrl); + $this->aiLoading = false; + } + + public function pickSuggestion(string $slug): void + { + $this->slug = $slug; + $this->autoSlug = false; + $this->slugSuggestions = []; + } + public function save(): void { $this->validate(); - $workspace = app('current_workspace'); - if (empty($this->slug)) { - $this->slug = Str::random(6); + $wsId = $this->workspaceId; + if (! $wsId) { + $ws = current_workspace(); + if (! $ws) { + $this->addError('targetUrl', 'Workspace nicht gefunden.'); + return; + } + $wsId = $ws->id; } - Link::create([ - 'workspace_id' => $workspace->id, + $slug = $this->slug ?: Str::random(6); + + $link = Link::create([ + 'workspace_id' => $wsId, 'target_url' => $this->targetUrl, - 'slug' => $this->slug, + 'slug' => $slug, 'title' => $this->title ?: null, 'status' => 'active', + 'created_by' => auth()->id(), ]); - $this->dispatch('linkCreated'); + $this->dispatch('link-created', linkId: $link->ulid)->to(\App\Livewire\Pages\Links\Index::class); $this->dispatch('toast', message: 'Link erstellt', type: 'success'); $this->closeModal(); } diff --git a/app/Livewire/Modals/CreateQrCode.php b/app/Livewire/Modals/CreateQrCode.php index 9cad774..4f54bbe 100644 --- a/app/Livewire/Modals/CreateQrCode.php +++ b/app/Livewire/Modals/CreateQrCode.php @@ -3,46 +3,176 @@ namespace App\Livewire\Modals; use App\Domains\QrCode\Models\QrCode; +use App\Domains\Workspace\Models\Workspace; use Illuminate\View\View; use LivewireUI\Modal\ModalComponent; class CreateQrCode extends ModalComponent { - public string $label = ''; + public string $workspaceUlid = ''; - public string $url = ''; + public int $workspaceId = 0; public string $type = 'url'; - protected function rules(): array + public string $label = ''; + + // Generic payload (url, text, email, phone, sms, location) + public string $url = ''; + + // vCard + public string $vcardName = ''; + public string $vcardPhone = ''; + public string $vcardEmail = ''; + public string $vcardCompany = ''; + public string $vcardWebsite = ''; + + // WiFi + public string $wifiSsid = ''; + public string $wifiPassword = ''; + public string $wifiEncryption = 'WPA'; + public bool $wifiHidden = false; + + // Style + public string $fgColor = '#000000'; + public string $bgColor = '#ffffff'; + public string $logoUrl = ''; + public string $dotStyle = 'square'; + public int $size = 512; + public int $margin = 4; + public string $errorCorrection = 'M'; + public string $frame = 'none'; + public string $frameText = ''; + public string $frameColor = '#7c3aed'; + + // Advanced + public bool $isDynamic = true; + public ?int $scanLimit = null; + public string $expiresAt = ''; + + public function mount(string $workspaceUlid = ''): void { - return [ - 'url' => 'required|url|max:2048', - 'label' => 'nullable|max:200', - 'type' => 'required|in:url,vcard,wifi,pdf,mp3,text', - ]; + if ($workspaceUlid) { + $workspace = Workspace::where('ulid', $workspaceUlid)->firstOrFail(); + abort_unless( + $workspace->owner_id === auth()->id() || + $workspace->members()->where('user_id', auth()->id())->exists(), + 404 + ); + $this->workspaceUlid = $workspaceUlid; + $this->workspaceId = $workspace->id; + } + } + + public function updated(string $prop): void + { + $this->dispatch('qr-preview-update', payload: $this->buildPayload(), options: [ + 'size' => $this->size, + 'margin' => $this->margin, + 'errorCorrection' => $this->errorCorrection, + 'fgColor' => $this->fgColor, + 'bgColor' => $this->bgColor, + ]); + } + + public function buildPayload(): string + { + return match ($this->type) { + 'email' => 'mailto:' . $this->url, + 'phone' => 'tel:' . $this->url, + 'sms' => 'sms:' . $this->url, + 'location' => 'geo:' . $this->url, + 'vcard' => $this->buildVcard(), + 'wifi' => $this->buildWifi(), + default => $this->url, + }; + } + + private function buildVcard(): string + { + return implode("\n", array_filter([ + 'BEGIN:VCARD', + 'VERSION:3.0', + $this->vcardName ? "FN:{$this->vcardName}" : null, + $this->vcardPhone ? "TEL:{$this->vcardPhone}" : null, + $this->vcardEmail ? "EMAIL:{$this->vcardEmail}" : null, + $this->vcardCompany ? "ORG:{$this->vcardCompany}" : null, + $this->vcardWebsite ? "URL:{$this->vcardWebsite}" : null, + 'END:VCARD', + ])); + } + + private function buildWifi(): string + { + $enc = $this->wifiEncryption ?: 'nopass'; + $hidden = $this->wifiHidden ? 'true' : 'false'; + + return "WIFI:T:{$enc};S:{$this->wifiSsid};P:{$this->wifiPassword};H:{$hidden};;"; } public function save(): void { - $this->validate(); - $workspace = app('current_workspace'); + $urlRule = match ($this->type) { + 'url' => 'required|url|max:2048', + 'email', 'phone', 'sms', 'location', 'text' => 'required|max:2048', + default => 'nullable', + }; - QrCode::create([ - 'workspace_id' => $workspace->id, - 'type' => $this->type, - 'payload' => ['url' => $this->url], - 'is_dynamic' => true, + $this->validate([ + 'type' => 'required|in:url,vcard,wifi,text,email,phone,sms,location,pdf,mp3', + 'label' => 'nullable|max:200', + 'url' => $urlRule, ]); - $this->dispatch('qrCreated'); - $this->dispatch('toast', message: 'QR Code erstellt', type: 'success'); + $wsId = $this->workspaceId; + if (! $wsId) { + $ws = current_workspace(); + if (! $ws) { + $this->addError('url', 'Workspace nicht gefunden.'); + + return; + } + $wsId = $ws->id; + } + + $dbType = match ($this->type) { + 'email', 'phone', 'sms', 'location' => 'url', + default => $this->type, + }; + + QrCode::create([ + 'workspace_id' => $wsId, + 'type' => $dbType, + 'payload' => [ + 'data' => $this->buildPayload(), + 'label' => $this->label, + 'display_type' => $this->type, + ], + 'style' => [ + 'fg_color' => $this->fgColor, + 'bg_color' => $this->bgColor, + 'logo_url' => $this->logoUrl ?: null, + 'dot_style' => $this->dotStyle, + 'size' => $this->size, + 'margin' => $this->margin, + 'error_correction' => $this->errorCorrection, + 'frame' => $this->frame, + 'frame_text' => $this->frameText ?: null, + 'frame_color' => $this->frameColor, + ], + 'is_dynamic' => $this->isDynamic, + 'scan_limit' => $this->scanLimit ?: null, + 'expires_at' => $this->expiresAt ?: null, + ]); + + $this->dispatch('qr-created')->to(\App\Livewire\Pages\QrCodes\Index::class); + $this->dispatch('toast', message: 'QR-Code erstellt', type: 'success'); $this->closeModal(); } public static function modalMaxWidth(): string { - return 'md'; + return '4xl'; } public function render(): View diff --git a/app/Livewire/Modals/DeleteBioPage.php b/app/Livewire/Modals/DeleteBioPage.php index 0e8d6fa..3e297a4 100644 --- a/app/Livewire/Modals/DeleteBioPage.php +++ b/app/Livewire/Modals/DeleteBioPage.php @@ -3,36 +3,37 @@ namespace App\Livewire\Modals; use App\Domains\Bio\Models\BioPage; +use App\Domains\Workspace\Models\Workspace; use Illuminate\View\View; use LivewireUI\Modal\ModalComponent; class DeleteBioPage extends ModalComponent { + public int $workspaceId = 0; + public string $bioUlid = ''; public string $bioTitle = ''; public function mount(string $bioUlid): void { - $workspace = app('current_workspace'); - $bio = BioPage::where('ulid', $bioUlid) - ->where('workspace_id', $workspace->id) - ->firstOrFail(); + $bio = BioPage::where('ulid', $bioUlid)->firstOrFail(); + $this->authorizeWorkspace($bio->workspace_id); + + $this->workspaceId = $bio->workspace_id; $this->bioUlid = $bioUlid; $this->bioTitle = $bio->getTranslation('title', 'en') ?? $bio->slug; } public function delete(): void { - $workspace = app('current_workspace'); - BioPage::where('ulid', $this->bioUlid) - ->where('workspace_id', $workspace->id) + ->where('workspace_id', $this->workspaceId) ->firstOrFail() ->delete(); - $this->dispatch('bioPageDeleted', bioUlid: $this->bioUlid); + $this->dispatch('bio-deleted')->to(\App\Livewire\Pages\Bio\Index::class); $this->dispatch('toast', message: 'Bio Page gelöscht', type: 'success'); $this->closeModal(); } @@ -46,4 +47,13 @@ class DeleteBioPage extends ModalComponent { return view('livewire.modals.delete-bio-page'); } + + private function authorizeWorkspace(int $workspaceId): void + { + Workspace::where("id", $workspaceId) + ->where(fn ($q) => $q + ->where("owner_id", auth()->id()) + ->orWhereHas("members", fn ($q) => $q->where("user_id", auth()->id())) + )->firstOrFail(); + } } diff --git a/app/Livewire/Modals/DeleteLink.php b/app/Livewire/Modals/DeleteLink.php index 19339de..a37cbd7 100644 --- a/app/Livewire/Modals/DeleteLink.php +++ b/app/Livewire/Modals/DeleteLink.php @@ -3,36 +3,37 @@ namespace App\Livewire\Modals; use App\Domains\Link\Models\Link; +use App\Domains\Workspace\Models\Workspace; use Illuminate\View\View; use LivewireUI\Modal\ModalComponent; class DeleteLink extends ModalComponent { + public int $workspaceId = 0; + public string $linkUlid = ''; public string $linkTitle = ''; public function mount(string $linkUlid): void { - $workspace = app('current_workspace'); - $link = Link::where('ulid', $linkUlid) - ->where('workspace_id', $workspace->id) - ->firstOrFail(); + $link = Link::where('ulid', $linkUlid)->firstOrFail(); + $this->authorizeWorkspace($link->workspace_id); + + $this->workspaceId = $link->workspace_id; $this->linkUlid = $linkUlid; $this->linkTitle = $link->title ?? $link->slug; } public function delete(): void { - $workspace = app('current_workspace'); - Link::where('ulid', $this->linkUlid) - ->where('workspace_id', $workspace->id) + ->where('workspace_id', $this->workspaceId) ->firstOrFail() ->delete(); - $this->dispatch('linkDeleted', linkUlid: $this->linkUlid); + $this->dispatch('link-deleted', linkUlid: $this->linkUlid)->to(\App\Livewire\Pages\Links\Index::class); $this->dispatch('toast', message: 'Link gelöscht', type: 'success'); $this->closeModal(); } @@ -46,4 +47,13 @@ class DeleteLink extends ModalComponent { return view('livewire.modals.delete-link'); } + + private function authorizeWorkspace(int $workspaceId): void + { + Workspace::where("id", $workspaceId) + ->where(fn ($q) => $q + ->where("owner_id", auth()->id()) + ->orWhereHas("members", fn ($q) => $q->where("user_id", auth()->id())) + )->firstOrFail(); + } } diff --git a/app/Livewire/Modals/DeleteQrCode.php b/app/Livewire/Modals/DeleteQrCode.php index 1fe0525..c3a102b 100644 --- a/app/Livewire/Modals/DeleteQrCode.php +++ b/app/Livewire/Modals/DeleteQrCode.php @@ -3,36 +3,37 @@ namespace App\Livewire\Modals; use App\Domains\QrCode\Models\QrCode; +use App\Domains\Workspace\Models\Workspace; use Illuminate\View\View; use LivewireUI\Modal\ModalComponent; class DeleteQrCode extends ModalComponent { + public int $workspaceId = 0; + public string $qrUlid = ''; public string $qrLabel = ''; public function mount(string $qrUlid): void { - $workspace = app('current_workspace'); - $qr = QrCode::where('ulid', $qrUlid) - ->where('workspace_id', $workspace->id) - ->firstOrFail(); + $qr = QrCode::where('ulid', $qrUlid)->firstOrFail(); + $this->authorizeWorkspace($qr->workspace_id); + + $this->workspaceId = $qr->workspace_id; $this->qrUlid = $qrUlid; $this->qrLabel = $qr->label ?? $qr->ulid; } public function delete(): void { - $workspace = app('current_workspace'); - QrCode::where('ulid', $this->qrUlid) - ->where('workspace_id', $workspace->id) + ->where('workspace_id', $this->workspaceId) ->firstOrFail() ->delete(); - $this->dispatch('qrDeleted', qrUlid: $this->qrUlid); + $this->dispatch('qr-deleted')->to(\App\Livewire\Pages\QrCodes\Index::class); $this->dispatch('toast', message: 'QR Code gelöscht', type: 'success'); $this->closeModal(); } @@ -46,4 +47,13 @@ class DeleteQrCode extends ModalComponent { return view('livewire.modals.delete-qr-code'); } + + private function authorizeWorkspace(int $workspaceId): void + { + Workspace::where("id", $workspaceId) + ->where(fn ($q) => $q + ->where("owner_id", auth()->id()) + ->orWhereHas("members", fn ($q) => $q->where("user_id", auth()->id())) + )->firstOrFail(); + } } diff --git a/app/Livewire/Modals/EditBioPage.php b/app/Livewire/Modals/EditBioPage.php index 1aff302..e3b4a7c 100644 --- a/app/Livewire/Modals/EditBioPage.php +++ b/app/Livewire/Modals/EditBioPage.php @@ -3,11 +3,14 @@ namespace App\Livewire\Modals; use App\Domains\Bio\Models\BioPage; +use App\Domains\Workspace\Models\Workspace; use Illuminate\View\View; use LivewireUI\Modal\ModalComponent; class EditBioPage extends ModalComponent { + public int $workspaceId = 0; + public string $bioUlid = ''; public string $title = ''; @@ -18,11 +21,11 @@ class EditBioPage extends ModalComponent public function mount(string $bioUlid): void { - $workspace = app('current_workspace'); - $bio = BioPage::where('ulid', $bioUlid) - ->where('workspace_id', $workspace->id) - ->firstOrFail(); + $bio = BioPage::where('ulid', $bioUlid)->firstOrFail(); + $this->authorizeWorkspace($bio->workspace_id); + + $this->workspaceId = $bio->workspace_id; $this->bioUlid = $bioUlid; $this->title = $bio->getTranslation('title', 'en') ?? ''; $this->slug = $bio->slug; @@ -41,10 +44,9 @@ class EditBioPage extends ModalComponent public function save(): void { $this->validate(); - $workspace = app('current_workspace'); $bio = BioPage::where('ulid', $this->bioUlid) - ->where('workspace_id', $workspace->id) + ->where('workspace_id', $this->workspaceId) ->firstOrFail(); $bio->update([ @@ -53,7 +55,7 @@ class EditBioPage extends ModalComponent 'is_published' => $this->isPublished, ]); - $this->dispatch('bioPageUpdated', bioUlid: $this->bioUlid); + $this->dispatch('bio-updated')->to(\App\Livewire\Pages\Bio\Index::class); $this->dispatch('toast', message: 'Bio Page aktualisiert', type: 'success'); $this->closeModal(); } @@ -67,4 +69,13 @@ class EditBioPage extends ModalComponent { return view('livewire.modals.edit-bio-page'); } + + private function authorizeWorkspace(int $workspaceId): void + { + Workspace::where("id", $workspaceId) + ->where(fn ($q) => $q + ->where("owner_id", auth()->id()) + ->orWhereHas("members", fn ($q) => $q->where("user_id", auth()->id())) + )->firstOrFail(); + } } diff --git a/app/Livewire/Modals/EditLink.php b/app/Livewire/Modals/EditLink.php index cdba945..a3d308a 100644 --- a/app/Livewire/Modals/EditLink.php +++ b/app/Livewire/Modals/EditLink.php @@ -3,11 +3,14 @@ namespace App\Livewire\Modals; use App\Domains\Link\Models\Link; +use App\Domains\Workspace\Models\Workspace; use Illuminate\View\View; use LivewireUI\Modal\ModalComponent; class EditLink extends ModalComponent { + public int $workspaceId = 0; + public string $linkUlid = ''; public int $linkId = 0; @@ -22,11 +25,11 @@ class EditLink extends ModalComponent public function mount(string $linkUlid): void { - $workspace = app('current_workspace'); - $link = Link::where('ulid', $linkUlid) - ->where('workspace_id', $workspace->id) - ->firstOrFail(); + $link = Link::where('ulid', $linkUlid)->firstOrFail(); + $this->authorizeWorkspace($link->workspace_id); + + $this->workspaceId = $link->workspace_id; $this->linkUlid = $linkUlid; $this->linkId = $link->id; $this->targetUrl = $link->target_url; @@ -48,10 +51,9 @@ class EditLink extends ModalComponent public function save(): void { $this->validate(); - $workspace = app('current_workspace'); $link = Link::where('ulid', $this->linkUlid) - ->where('workspace_id', $workspace->id) + ->where('workspace_id', $this->workspaceId) ->firstOrFail(); $link->update([ @@ -61,7 +63,7 @@ class EditLink extends ModalComponent 'status' => $this->status, ]); - $this->dispatch('linkUpdated', linkUlid: $this->linkUlid); + $this->dispatch('link-updated', linkUlid: $this->linkUlid)->to(\App\Livewire\Pages\Links\Index::class); $this->dispatch('toast', message: 'Link aktualisiert', type: 'success'); $this->closeModal(); } @@ -70,4 +72,13 @@ class EditLink extends ModalComponent { return view('livewire.modals.edit-link'); } + + private function authorizeWorkspace(int $workspaceId): void + { + Workspace::where("id", $workspaceId) + ->where(fn ($q) => $q + ->where("owner_id", auth()->id()) + ->orWhereHas("members", fn ($q) => $q->where("user_id", auth()->id())) + )->firstOrFail(); + } } diff --git a/app/Livewire/Modals/EditQrCode.php b/app/Livewire/Modals/EditQrCode.php index 48e5743..62961cb 100644 --- a/app/Livewire/Modals/EditQrCode.php +++ b/app/Livewire/Modals/EditQrCode.php @@ -3,11 +3,14 @@ namespace App\Livewire\Modals; use App\Domains\QrCode\Models\QrCode; +use App\Domains\Workspace\Models\Workspace; use Illuminate\View\View; use LivewireUI\Modal\ModalComponent; class EditQrCode extends ModalComponent { + public int $workspaceId = 0; + public string $qrUlid = ''; public string $url = ''; @@ -18,11 +21,11 @@ class EditQrCode extends ModalComponent public function mount(string $qrUlid): void { - $workspace = app('current_workspace'); - $qr = QrCode::where('ulid', $qrUlid) - ->where('workspace_id', $workspace->id) - ->firstOrFail(); + $qr = QrCode::where('ulid', $qrUlid)->firstOrFail(); + $this->authorizeWorkspace($qr->workspace_id); + + $this->workspaceId = $qr->workspace_id; $this->qrUlid = $qrUlid; $this->url = $qr->payload['url'] ?? ''; $this->label = $qr->label ?? ''; @@ -41,10 +44,9 @@ class EditQrCode extends ModalComponent public function save(): void { $this->validate(); - $workspace = app('current_workspace'); $qr = QrCode::where('ulid', $this->qrUlid) - ->where('workspace_id', $workspace->id) + ->where('workspace_id', $this->workspaceId) ->firstOrFail(); $qr->update([ @@ -52,7 +54,7 @@ class EditQrCode extends ModalComponent 'payload' => ['url' => $this->url], ]); - $this->dispatch('qrUpdated', qrUlid: $this->qrUlid); + $this->dispatch('qr-updated')->to(\App\Livewire\Pages\QrCodes\Index::class); $this->dispatch('toast', message: 'QR Code aktualisiert', type: 'success'); $this->closeModal(); } @@ -66,4 +68,13 @@ class EditQrCode extends ModalComponent { return view('livewire.modals.edit-qr-code'); } + + private function authorizeWorkspace(int $workspaceId): void + { + Workspace::where("id", $workspaceId) + ->where(fn ($q) => $q + ->where("owner_id", auth()->id()) + ->orWhereHas("members", fn ($q) => $q->where("user_id", auth()->id())) + )->firstOrFail(); + } } diff --git a/app/Livewire/Pages/Bio/Index.php b/app/Livewire/Pages/Bio/Index.php index 1e8dd4f..dacd217 100644 --- a/app/Livewire/Pages/Bio/Index.php +++ b/app/Livewire/Pages/Bio/Index.php @@ -2,14 +2,41 @@ namespace App\Livewire\Pages\Bio; +use App\Domains\Bio\Models\BioPage; use Illuminate\View\View; +use Livewire\Attributes\On; use Livewire\Component; +use Livewire\WithPagination; class Index extends Component { + use WithPagination; + + public string $search = ''; + + public function updatingSearch(): void + { + $this->resetPage(); + } + + #[On('bio-created')] + #[On('bio-updated')] + #[On('bio-deleted')] + public function refresh(): void + { + $this->resetPage(); + } + public function render(): View { - return view('livewire.pages.bio.index') + $workspace = require_workspace(); + + $bioPages = BioPage::where('workspace_id', $workspace->id) + ->when($this->search, fn ($q) => $q->where('slug', 'like', "%{$this->search}%")) + ->latest() + ->paginate(20); + + return view('livewire.pages.bio.index', compact('bioPages')) ->layout('layouts.nimuli-app', ['title' => 'Link-in-Bio']); } } diff --git a/app/Livewire/Pages/Links/Index.php b/app/Livewire/Pages/Links/Index.php index ff34bec..f7812cc 100644 --- a/app/Livewire/Pages/Links/Index.php +++ b/app/Livewire/Pages/Links/Index.php @@ -26,9 +26,9 @@ class Index extends Component $this->resetPage(); } - #[On('linkCreated')] - #[On('linkUpdated')] - #[On('linkDeleted')] + #[On('link-created')] + #[On('link-updated')] + #[On('link-deleted')] public function refresh(): void { $this->resetPage(); @@ -36,7 +36,7 @@ class Index extends Component public function render(): View { - $workspace = app('current_workspace'); + $workspace = require_workspace(); $links = Link::where('workspace_id', $workspace->id) ->when($this->search, fn ($q) => $q->where(function ($q) { diff --git a/app/Livewire/Pages/QrCodes/Index.php b/app/Livewire/Pages/QrCodes/Index.php index a73fb47..f41bb53 100644 --- a/app/Livewire/Pages/QrCodes/Index.php +++ b/app/Livewire/Pages/QrCodes/Index.php @@ -2,14 +2,41 @@ namespace App\Livewire\Pages\QrCodes; +use App\Domains\QrCode\Models\QrCode; use Illuminate\View\View; +use Livewire\Attributes\On; use Livewire\Component; +use Livewire\WithPagination; class Index extends Component { + use WithPagination; + + public string $search = ''; + + public function updatingSearch(): void + { + $this->resetPage(); + } + + #[On('qr-created')] + #[On('qr-updated')] + #[On('qr-deleted')] + public function refresh(): void + { + $this->resetPage(); + } + public function render(): View { - return view('livewire.pages.qr-codes.index') + $workspace = require_workspace(); + + $qrCodes = QrCode::where('workspace_id', $workspace->id) + ->when($this->search, fn ($q) => $q->where('label', 'like', "%{$this->search}%")) + ->latest() + ->paginate(20); + + return view('livewire.pages.qr-codes.index', compact('qrCodes')) ->layout('layouts.nimuli-app', ['title' => 'QR Codes']); } } diff --git a/resources/views/livewire/pages/bio/index.blade.php b/resources/views/livewire/pages/bio/index.blade.php index 31471ae..668d115 100644 --- a/resources/views/livewire/pages/bio/index.blade.php +++ b/resources/views/livewire/pages/bio/index.blade.php @@ -1,21 +1,61 @@
Create a beautiful link-in-bio page for Instagram, TikTok and more.
-Create a beautiful link-in-bio page for Instagram, TikTok and more.
+ @if($ws) +No links yet.
-Create QR codes for URLs, vCards, WiFi and more.
-Create QR codes for URLs, vCards, WiFi and more.
+ @if($ws) +