2026-09-17 23:01:26 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
use App\Models\User;
|
|
|
|
|
use Flux\Flux;
|
2026-10-15 20:59:32 -07:00
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
|
use Illuminate\Pagination\LengthAwarePaginator;
|
|
|
|
|
use Illuminate\Support\Facades\Gate;
|
2026-09-17 23:01:26 -07:00
|
|
|
use Livewire\Attributes\Computed;
|
|
|
|
|
use Livewire\Attributes\Locked;
|
|
|
|
|
use Livewire\Attributes\Title;
|
|
|
|
|
use Livewire\Component;
|
2026-10-15 20:59:32 -07:00
|
|
|
use Livewire\WithPagination;
|
2026-09-17 23:01:26 -07:00
|
|
|
|
|
|
|
|
new #[Title('Notes limits')] class extends Component
|
|
|
|
|
{
|
2026-10-15 20:59:32 -07:00
|
|
|
use WithPagination;
|
|
|
|
|
|
|
|
|
|
private const PER_PAGE = 10;
|
|
|
|
|
|
2026-09-17 23:01:26 -07:00
|
|
|
public function mount(): void
|
|
|
|
|
{
|
2026-10-15 20:59:32 -07:00
|
|
|
Gate::authorize('accessAdmin');
|
2026-09-17 23:01:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[Locked]
|
|
|
|
|
public ?int $editingUserId = null;
|
|
|
|
|
|
|
|
|
|
public bool $showLimitForm = false;
|
|
|
|
|
|
|
|
|
|
public string $notesLimitInput = '';
|
|
|
|
|
|
2026-10-15 20:59:32 -07:00
|
|
|
public string $search = '';
|
|
|
|
|
|
|
|
|
|
public function updatedSearch(): void
|
|
|
|
|
{
|
|
|
|
|
$this->resetPage();
|
|
|
|
|
}
|
|
|
|
|
|
2026-09-17 23:01:26 -07:00
|
|
|
#[Computed]
|
2026-10-15 20:59:32 -07:00
|
|
|
public function users(): LengthAwarePaginator
|
|
|
|
|
{
|
|
|
|
|
return $this->filteredUserQuery()
|
|
|
|
|
->orderBy('name')
|
|
|
|
|
->paginate(self::PER_PAGE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return Builder<User>
|
|
|
|
|
*/
|
|
|
|
|
private function filteredUserQuery(): Builder
|
2026-09-17 23:01:26 -07:00
|
|
|
{
|
|
|
|
|
return User::query()
|
2026-10-15 20:59:32 -07:00
|
|
|
->when(
|
|
|
|
|
$this->search !== '',
|
|
|
|
|
fn (Builder $query) => $query->where(fn (Builder $query) => $query
|
|
|
|
|
->where('name', 'like', '%'.$this->search.'%')
|
|
|
|
|
->orWhere('email', 'like', '%'.$this->search.'%'))
|
|
|
|
|
);
|
2026-09-17 23:01:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function startEditLimit(int $userId): void
|
|
|
|
|
{
|
|
|
|
|
$user = $this->userById($userId);
|
|
|
|
|
|
|
|
|
|
$this->editingUserId = $user->id;
|
|
|
|
|
$this->notesLimitInput = (string) $user->notesLimit();
|
|
|
|
|
$this->resetErrorBag('notesLimitInput');
|
|
|
|
|
$this->showLimitForm = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function saveNotesLimit(): void
|
|
|
|
|
{
|
2026-10-15 20:59:32 -07:00
|
|
|
Gate::authorize('accessAdmin');
|
|
|
|
|
|
2026-09-17 23:01:26 -07:00
|
|
|
$user = $this->userById($this->editingUserId);
|
|
|
|
|
|
|
|
|
|
$validated = $this->validate([
|
|
|
|
|
'notesLimitInput' => ['required', 'integer', 'min:1', 'max:1000000'],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$user->update(['notes_limit' => (int) $validated['notesLimitInput']]);
|
|
|
|
|
|
|
|
|
|
$this->reset('showLimitForm', 'editingUserId', 'notesLimitInput');
|
|
|
|
|
|
|
|
|
|
Flux::toast(variant: 'success', text: __('Notes limit updated.'));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function userById(int $userId): User
|
|
|
|
|
{
|
|
|
|
|
return User::query()->findOrFail($userId);
|
|
|
|
|
}
|
|
|
|
|
}; ?>
|
|
|
|
|
|
|
|
|
|
<div class="flex h-full w-full flex-1 flex-col gap-6">
|
|
|
|
|
<div>
|
|
|
|
|
<flux:heading size="xl">{{ __('Notes limits') }}</flux:heading>
|
|
|
|
|
<flux:text class="mt-1">{{ __('Set how many characters each user may write in todo notes.') }}</flux:text>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-10-15 20:59:32 -07:00
|
|
|
<div class="flex flex-wrap items-center gap-2">
|
|
|
|
|
<flux:input
|
|
|
|
|
size="sm"
|
|
|
|
|
type="search"
|
|
|
|
|
icon="magnifying-glass"
|
|
|
|
|
wire:model.live.debounce.300ms="search"
|
|
|
|
|
placeholder="{{ __('Search users…') }}"
|
|
|
|
|
class="w-full sm:w-64"
|
|
|
|
|
data-test="search-input"
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
@if ($search !== '')
|
|
|
|
|
<flux:button
|
|
|
|
|
size="sm"
|
|
|
|
|
variant="danger"
|
|
|
|
|
icon="x-mark"
|
|
|
|
|
wire:click="$set('search', '')"
|
|
|
|
|
class="shrink-0"
|
|
|
|
|
data-test="clear-search"
|
|
|
|
|
>
|
|
|
|
|
{{ __('Clear') }}
|
|
|
|
|
</flux:button>
|
|
|
|
|
@endif
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-09-17 23:01:26 -07:00
|
|
|
<flux:card>
|
2026-10-15 20:59:32 -07:00
|
|
|
<flux:table :paginate="$this->users">
|
2026-09-17 23:01:26 -07:00
|
|
|
<flux:table.columns>
|
|
|
|
|
<flux:table.column>{{ __('Name') }}</flux:table.column>
|
|
|
|
|
<flux:table.column>{{ __('Email') }}</flux:table.column>
|
2026-10-15 20:59:32 -07:00
|
|
|
<flux:table.column>{{ __('Site role') }}</flux:table.column>
|
2026-09-17 23:01:26 -07:00
|
|
|
<flux:table.column>{{ __('Notes limit') }}</flux:table.column>
|
|
|
|
|
<flux:table.column align="end" width="5rem">{{ __('Actions') }}</flux:table.column>
|
|
|
|
|
</flux:table.columns>
|
|
|
|
|
|
|
|
|
|
<flux:table.rows>
|
2026-10-15 20:59:32 -07:00
|
|
|
@forelse ($this->users as $user)
|
2026-09-17 23:01:26 -07:00
|
|
|
<flux:table.row :key="$user->id" data-test="user-row-{{ $user->id }}">
|
|
|
|
|
<flux:table.cell>{{ $user->name }}</flux:table.cell>
|
|
|
|
|
<flux:table.cell class="text-zinc-500">{{ $user->email }}</flux:table.cell>
|
|
|
|
|
<flux:table.cell>
|
2026-10-15 20:59:32 -07:00
|
|
|
@if ($user->isSiteAdmin())
|
|
|
|
|
<flux:badge size="sm" color="blue">{{ __('Site admin') }}</flux:badge>
|
2026-09-17 23:01:26 -07:00
|
|
|
@else
|
|
|
|
|
<flux:badge size="sm" color="zinc">{{ __('Member') }}</flux:badge>
|
|
|
|
|
@endif
|
|
|
|
|
</flux:table.cell>
|
|
|
|
|
<flux:table.cell data-test="notes-limit-{{ $user->id }}">
|
|
|
|
|
{{ $user->notesLimit() }} {{ __('characters') }}
|
|
|
|
|
</flux:table.cell>
|
|
|
|
|
<flux:table.cell class="py-0">
|
|
|
|
|
<div class="flex justify-end gap-1">
|
|
|
|
|
<flux:button
|
|
|
|
|
size="sm"
|
|
|
|
|
variant="ghost"
|
|
|
|
|
icon="pencil-square"
|
|
|
|
|
:title="__('Edit notes limit')"
|
|
|
|
|
wire:click="startEditLimit({{ $user->id }})"
|
|
|
|
|
data-test="edit-notes-limit-{{ $user->id }}"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
</flux:table.cell>
|
|
|
|
|
</flux:table.row>
|
2026-10-15 20:59:32 -07:00
|
|
|
@empty
|
|
|
|
|
<flux:table.row>
|
|
|
|
|
<flux:table.cell colspan="5" align="center" class="py-10">
|
|
|
|
|
<flux:text>{{ __('No users match your search.') }}</flux:text>
|
|
|
|
|
</flux:table.cell>
|
|
|
|
|
</flux:table.row>
|
|
|
|
|
@endforelse
|
2026-09-17 23:01:26 -07:00
|
|
|
</flux:table.rows>
|
|
|
|
|
</flux:table>
|
|
|
|
|
</flux:card>
|
|
|
|
|
|
|
|
|
|
<flux:modal wire:model.self="showLimitForm" class="md:w-lg">
|
|
|
|
|
<form wire:submit="saveNotesLimit" class="space-y-6">
|
|
|
|
|
<div>
|
|
|
|
|
<flux:heading size="lg">{{ __('Edit notes limit') }}</flux:heading>
|
|
|
|
|
<flux:text class="mt-2">{{ __('Enter the maximum number of characters allowed in todo notes.') }}</flux:text>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<flux:field>
|
|
|
|
|
<flux:label>{{ __('Notes limit (characters)') }}</flux:label>
|
|
|
|
|
<flux:input
|
|
|
|
|
wire:model="notesLimitInput"
|
|
|
|
|
type="number"
|
|
|
|
|
min="1"
|
|
|
|
|
max="1000000"
|
|
|
|
|
inputmode="numeric"
|
|
|
|
|
data-test="notes-limit-input"
|
|
|
|
|
/>
|
|
|
|
|
<flux:error name="notesLimitInput" />
|
|
|
|
|
</flux:field>
|
|
|
|
|
|
|
|
|
|
<div class="flex justify-end gap-3">
|
|
|
|
|
<flux:modal.close>
|
|
|
|
|
<flux:button variant="ghost">{{ __('Cancel') }}</flux:button>
|
|
|
|
|
</flux:modal.close>
|
|
|
|
|
<flux:button type="submit" variant="primary">{{ __('Save') }}</flux:button>
|
|
|
|
|
</div>
|
|
|
|
|
</form>
|
|
|
|
|
</flux:modal>
|
|
|
|
|
</div>
|