Files
ecdown 177f122c10
tests / ci (push) Canceled after 0s
added roles and organizations
2026-10-15 20:59:32 -07:00

1146 lines
46 KiB
PHP

<?php
use App\FolderRole;
use App\FolderVisibility;
use App\Mail\InvitationMail;
use App\Models\Folder;
use App\Models\Invitation;
use App\Models\Organization;
use App\Models\Todo;
use App\Models\User;
use App\TodoStatus;
use Flux\Flux;
use Illuminate\Support\Carbon;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\Mail;
use Illuminate\Support\Str;
use Illuminate\Validation\Rule;
use Livewire\Attributes\Computed;
use Livewire\Attributes\Locked;
use Livewire\Attributes\Title;
use Livewire\Component;
new #[Title('Folders')] class extends Component
{
public string $newFolderName = '';
public string $newFolderColor = '';
#[Locked]
public ?int $creatingChildOf = null;
public string $newChildName = '';
public string $newChildColor = '';
#[Locked]
public ?int $renamingFolderId = null;
public string $renameName = '';
#[Locked]
public ?int $confirmingFolderDelete = null;
#[Locked]
public ?int $expandedFolderId = null;
#[Locked]
public ?int $colorEditingFolderId = null;
public string $colorDraft = '';
#[Locked]
public ?int $sharingFolderId = null;
public string $inviteEmail = '';
public string $inviteRole = 'viewer';
public string $shareVisibility = 'private';
/** @var array<int, string> */
public array $collaboratorRoles = [];
public bool $showTodoForm = false;
#[Locked]
public ?int $todoFolderId = null;
public string $todoDescription = '';
public string $todoStatus = 'open';
public ?string $todoDueDate = null;
public string $todoNotes = '';
public function createTopLevelFolder(): void
{
$organization = auth()->user()->currentOrganization()->first();
abort_unless(
$organization !== null && auth()->user()->can('create', [Folder::class, $organization]),
403
);
$validated = $this->validate([
'newFolderName' => $this->folderNameRules($organization->id, parentId: null),
'newFolderColor' => $this->folderColorRules(),
]);
Folder::create([
'user_id' => auth()->id(),
'name' => $validated['newFolderName'],
'color' => filled($validated['newFolderColor']) ? $validated['newFolderColor'] : null,
'parent_id' => null,
]);
$this->reset('newFolderName', 'newFolderColor');
}
public function startChildCreate(int $folderId): void
{
$this->folderForAction($folderId, 'createChild');
$this->creatingChildOf = $folderId;
$this->reset('newChildName', 'newChildColor');
$this->resetErrorBag('newChildName', 'newChildColor');
}
public function cancelChildCreate(): void
{
$this->reset('creatingChildOf', 'newChildName', 'newChildColor');
}
public function createChildFolder(): void
{
$parent = $this->folderForAction($this->creatingChildOf ?? 0, 'createChild');
$validated = $this->validate([
'newChildName' => $this->folderNameRules($parent->organization_id, parentId: $parent->id),
'newChildColor' => $this->folderColorRules(),
]);
Folder::create([
'user_id' => auth()->id(),
'organization_id' => $parent->organization_id,
'name' => $validated['newChildName'],
'color' => filled($validated['newChildColor']) ? $validated['newChildColor'] : null,
'parent_id' => $parent->id,
]);
$this->reset('creatingChildOf', 'newChildName', 'newChildColor');
}
public function startRename(int $folderId): void
{
$folder = $this->folderForAction($folderId, 'update');
$this->renamingFolderId = $folder->id;
$this->renameName = $folder->name;
$this->resetErrorBag('renameName');
}
public function cancelRename(): void
{
$this->reset('renamingFolderId', 'renameName');
}
public function saveRename(): void
{
$folder = $this->folderForAction($this->renamingFolderId ?? 0, 'update');
$validated = $this->validate([
'renameName' => $this->folderNameRules($folder->organization_id, parentId: $folder->parent_id, ignoreId: $folder->id),
]);
$folder->update(['name' => $validated['renameName']]);
$this->reset('renamingFolderId', 'renameName');
}
public function confirmFolderDelete(int $folderId): void
{
$this->folderForAction($folderId, 'delete');
$this->confirmingFolderDelete = $folderId;
$this->modal('confirm-folder-delete')->show();
}
public function deleteFolder(): void
{
$folder = $this->folderForAction($this->confirmingFolderDelete ?? 0, 'delete');
if ($this->expandedFolderId === $folder->id) {
$this->expandedFolderId = null;
}
$folder->delete();
$this->confirmingFolderDelete = null;
$this->modal('confirm-folder-delete')->close();
}
public function toggleExpandFolder(int $folderId): void
{
$this->visibleFolder($folderId);
$this->expandedFolderId = $this->expandedFolderId === $folderId ? null : $folderId;
}
public function startColorEdit(int $folderId): void
{
$folder = $this->folderForAction($folderId, 'update');
$this->colorEditingFolderId = $folder->id;
$this->colorDraft = $folder->color ?? '';
$this->resetErrorBag('colorDraft');
$this->modal('folder-color')->show();
}
public function saveFolderColor(): void
{
$folder = $this->folderForAction($this->colorEditingFolderId ?? 0, 'update');
$validated = $this->validate([
'colorDraft' => $this->folderColorRules(),
]);
$folder->update([
'color' => filled($validated['colorDraft']) ? $validated['colorDraft'] : null,
]);
$this->reset('colorEditingFolderId', 'colorDraft');
$this->modal('folder-color')->close();
}
public function startShare(int $folderId): void
{
$folder = $this->folderForAction($folderId, 'manageShares');
$this->sharingFolderId = $folder->id;
$this->shareVisibility = $folder->visibility->value;
$this->collaboratorRoles = $folder->shares()
->get()
->mapWithKeys(fn (User $user): array => [$user->id => (string) $user->pivot->role])
->all();
$this->reset('inviteEmail', 'inviteRole');
$this->resetErrorBag('inviteEmail', 'inviteRole');
$this->modal('folder-share')->show();
}
public function closeShare(): void
{
$this->reset('sharingFolderId', 'inviteEmail', 'inviteRole', 'collaboratorRoles');
$this->modal('folder-share')->close();
}
public function updatedCollaboratorRoles(string $value, string $key): void
{
$this->updateCollaboratorRole((int) $key, $value);
}
public function updatedShareVisibility(string $value): void
{
$this->updateVisibility($value);
}
public function updateVisibility(string $visibility): void
{
$folder = $this->folderForAction($this->sharingFolderId ?? 0, 'manageShares');
$validated = validator(
['shareVisibility' => $visibility],
['shareVisibility' => ['required', Rule::enum(FolderVisibility::class)]],
)->validate();
// Personal workspaces hold a single member, so there is nothing to
// share a folder with. Only ever move such a folder back to private.
if ($validated['shareVisibility'] === FolderVisibility::Workspace->value
&& $folder->organization?->isPersonal()) {
return;
}
$folder->update(['visibility' => $validated['shareVisibility']]);
unset($this->sharingFolder);
Flux::toast(variant: 'success', text: __('Folder sharing updated.'));
}
public function inviteCollaborator(): void
{
$folder = $this->folderForAction($this->sharingFolderId ?? 0, 'manageShares');
$validated = $this->validate([
'inviteEmail' => ['required', 'string', 'email', 'max:255'],
'inviteRole' => ['required', Rule::enum(FolderRole::class)],
]);
$email = Str::lower($validated['inviteEmail']);
if ($folder->shares()->where('users.email', $email)->exists()) {
$this->addError('inviteEmail', __('That person already has access to this folder.'));
return;
}
if (Str::lower((string) $folder->user?->email) === $email) {
$this->addError('inviteEmail', __('That person already owns this folder.'));
return;
}
$invitation = Invitation::updateOrCreate(
[
'inviteable_type' => Folder::class,
'inviteable_id' => $folder->id,
'email' => $email,
],
[
'inviter_id' => auth()->id(),
'role' => $validated['inviteRole'],
'token' => Str::random(64),
'expires_at' => now()->addDays(Invitation::EXPIRY_DAYS),
'accepted_at' => null,
'accepted_by_id' => null,
],
);
Mail::to($email)->send(new InvitationMail($invitation));
$this->reset('inviteEmail', 'inviteRole');
unset($this->sharingInvitations);
Flux::toast(variant: 'success', text: __('Invitation sent to :email.', ['email' => $email]));
}
public function updateCollaboratorRole(int $userId, string $role): void
{
$folder = $this->folderForAction($this->sharingFolderId ?? 0, 'manageShares');
if ($userId === $folder->user_id) {
return;
}
$validated = validator(
['role' => $role],
['role' => ['required', Rule::enum(FolderRole::class)]],
)->validate();
$folder->shares()->updateExistingPivot($userId, ['role' => $validated['role']]);
unset($this->sharingCollaborators);
Flux::toast(variant: 'success', text: __('Collaborator role updated.'));
}
public function removeCollaborator(int $userId): void
{
$folder = $this->folderForAction($this->sharingFolderId ?? 0, 'manageShares');
if ($userId === $folder->user_id) {
return;
}
$folder->shares()->detach($userId);
unset($this->sharingCollaborators);
Flux::toast(variant: 'success', text: __('Collaborator removed.'));
}
public function revokeFolderInvitation(int $invitationId): void
{
$folder = $this->folderForAction($this->sharingFolderId ?? 0, 'manageShares');
$invitation = $folder->invitations()->whereKey($invitationId)->firstOrFail();
abort_unless(auth()->user()->can('delete', $invitation), 403);
$invitation->delete();
unset($this->sharingInvitations);
Flux::toast(variant: 'success', text: __('Invitation revoked.'));
}
public function moveTodoToFolder(int $todoId, int $folderId): void
{
$todo = Todo::query()
->visibleTo(auth()->id(), $this->activeWorkspaceId())
->with('folder')
->findOrFail($todoId);
abort_unless(auth()->user()->can('update', $todo), 403);
$folder = $this->visibleFolder($folderId);
abort_unless(auth()->user()->can('create', [Todo::class, $folder]), 403);
$todo->update(['folder_id' => $folder->id]);
}
public function moveFolderToTopLevel(int $folderId): void
{
$folder = $this->folderForAction($folderId, 'update');
$hasSiblingConflict = Folder::query()
->where('organization_id', $folder->organization_id)
->whereNull('parent_id')
->whereKeyNot($folder->id)
->where('name', $folder->name)
->exists();
if ($hasSiblingConflict) {
return;
}
$folder->update(['parent_id' => null]);
}
public function moveFolderToFolder(int $folderId, int $targetFolderId): void
{
$folder = $this->folderForAction($folderId, 'update');
$target = $this->folderForAction($targetFolderId, 'createChild');
if ($folder->id === $target->id || $this->isDescendantOf($target, $folder)) {
return;
}
$hasSiblingConflict = $target->children()
->whereKeyNot($folder->id)
->where('name', $folder->name)
->exists();
if ($hasSiblingConflict) {
return;
}
$folder->update(['parent_id' => $target->id]);
}
private function isDescendantOf(Folder $folder, Folder $ancestor): bool
{
$cursor = $folder->parent;
while ($cursor !== null) {
if ($cursor->id === $ancestor->id) {
return true;
}
$cursor = $cursor->parent;
}
return false;
}
public function todosForFolder(int $folderId): Collection
{
return Todo::query()
->visibleTo(auth()->id(), $this->activeWorkspaceId())
->where('folder_id', $folderId)
->active()
->priority()
->get();
}
public function startTodoCreate(int $folderId): void
{
$this->folderForTodoCreate($folderId);
$this->todoFolderId = $folderId;
$this->reset('todoDescription', 'todoStatus', 'todoDueDate', 'todoNotes');
$this->resetErrorBag('todoDescription', 'todoStatus', 'todoDueDate', 'todoNotes');
$this->showTodoForm = true;
}
public function saveFolderTodo(): void
{
$folder = $this->folderForTodoCreate($this->todoFolderId ?? 0);
$validated = $this->validate([
'todoDescription' => ['required', 'string', 'max:255'],
'todoStatus' => ['required', Rule::enum(TodoStatus::class)],
'todoDueDate' => ['nullable', 'date'],
'todoNotes' => ['nullable', 'string', 'max:'.auth()->user()->notesLimit()],
]);
Todo::create([
'user_id' => auth()->id(),
'folder_id' => $folder->id,
'description' => $validated['todoDescription'],
'status' => TodoStatus::from($validated['todoStatus']),
'due_date' => filled($validated['todoDueDate']) ? Carbon::parse($validated['todoDueDate']) : null,
'notes' => filled($validated['todoNotes']) ? $validated['todoNotes'] : null,
'position' => Todo::nextPositionFor($folder),
]);
$this->reset('showTodoForm', 'todoFolderId', 'todoDescription', 'todoStatus', 'todoDueDate', 'todoNotes');
}
#[Computed]
public function folderTree(): Collection
{
return Folder::treeForVisibleTo(auth()->id(), $this->activeWorkspaceId());
}
#[Computed]
public function todoFolder(): ?Folder
{
if ($this->todoFolderId === null) {
return null;
}
return Folder::query()
->with('parent')
->visibleTo(auth()->id(), $this->activeWorkspaceId())
->find($this->todoFolderId);
}
#[Computed]
public function todoFolderPath(): string
{
if ($this->todoFolder === null) {
return '';
}
return collect([$this->todoFolder->parent?->name, $this->todoFolder->name])
->filter()
->implode(' / ');
}
#[Computed]
public function openCounts(): Collection
{
return Todo::query()
->visibleTo(auth()->id(), $this->activeWorkspaceId())
->active()
->pluck('folder_id')
->countBy();
}
#[Computed]
public function sharingFolder(): ?Folder
{
if ($this->sharingFolderId === null) {
return null;
}
return Folder::query()
->with('organization')
->visibleTo(auth()->id(), $this->activeWorkspaceId())
->find($this->sharingFolderId);
}
/**
* @return Collection<int, User>
*/
#[Computed]
public function sharingCollaborators(): Collection
{
return $this->sharingFolder?->shares()->orderBy('name')->get() ?? collect();
}
/**
* @return Collection<int, Invitation>
*/
#[Computed]
public function sharingInvitations(): Collection
{
return $this->sharingFolder?->invitations()->pending()->orderBy('email')->get() ?? collect();
}
/**
* @return array<int, mixed>
*/
private function folderColorRules(): array
{
return ['nullable', 'string', 'max:20', Rule::in([...Folder::COLORS, ''])];
}
/**
* @return array<int, mixed>
*/
private function folderNameRules(int $organizationId, ?int $parentId = null, ?int $ignoreId = null): array
{
return [
'required',
'string',
'max:255',
Rule::unique('folders', 'name')
->ignore($ignoreId)
->where(fn ($query) => $query
->where('organization_id', $organizationId)
->where('parent_id', $parentId)),
];
}
private function activeWorkspaceId(): int
{
return (int) auth()->user()->current_organization_id;
}
private function visibleFolder(int $folderId): Folder
{
return Folder::query()
->visibleTo(auth()->id(), $this->activeWorkspaceId())
->findOrFail($folderId);
}
private function folderForAction(int $folderId, string $ability): Folder
{
$folder = $this->visibleFolder($folderId);
abort_unless(auth()->user()->can($ability, $folder), 403);
return $folder;
}
private function folderForTodoCreate(int $folderId): Folder
{
$folder = $this->visibleFolder($folderId);
abort_unless(auth()->user()->can('create', [Todo::class, $folder]), 403);
return $folder;
}
}; ?>
<div class="flex h-full w-full flex-1 flex-col gap-6">
<div class="flex flex-wrap items-center justify-between gap-4">
<div>
<flux:heading size="xl">{{ __('Folders') }}</flux:heading>
<flux:text class="mt-1">{{ __('Organize your todos into a top-level and nested folder hierarchy.') }}</flux:text>
</div>
</div>
@if ($this->folderTree->isEmpty())
<flux:callout variant="warning" icon="folder">
{{ __('No folders yet. Create your first top-level folder below.') }}
</flux:callout>
@endif
<flux:card>
<form wire:submit="createTopLevelFolder" class="flex flex-wrap items-end gap-3">
<div class="min-w-64 flex-1">
<flux:label>{{ __('New top-level folder') }}</flux:label>
<flux:input
wire:model="newFolderName"
placeholder="{{ __('e.g. Work, Business, Personal') }}"
data-test="new-folder-input"
/>
<flux:error name="newFolderName" />
</div>
<div>
<flux:label>{{ __('Color') }}</flux:label>
<x-color-picker model="newFolderColor" />
<flux:error name="newFolderColor" />
</div>
<flux:button variant="primary" type="submit" icon="plus" data-test="add-folder-button">
{{ __('Add folder') }}
</flux:button>
</form>
</flux:card>
<div
x-data="{
draggingFolder: false,
droppingTopLevel: false,
dropFolder(folderId) {
if (window.__mtFolderDrag) {
if (window.__mtFolderDrag.folderId !== folderId) $wire.moveFolderToFolder(window.__mtFolderDrag.folderId, folderId);
window.__mtFolderDrag = null;
}
},
dropTodo(folderId) {
if (window.__mtTodoDrag && window.__mtTodoDrag.folderId !== folderId) $wire.moveTodoToFolder(window.__mtTodoDrag.todoId, folderId);
window.__mtTodoDrag = null;
}
}"
@folder-drag-start="draggingFolder = true; droppingTopLevel = false"
@folder-drag-end="draggingFolder = false; droppingTopLevel = false"
class="flex flex-col divide-y divide-zinc-200 rounded-xl border border-zinc-200 bg-white dark:divide-zinc-700 dark:border-zinc-700 dark:bg-zinc-900"
data-test="folder-list"
>
@forelse ($this->folderTree as $node)
<div
x-show="draggingFolder"
class="p-4"
:class="droppingTopLevel && 'rounded-lg bg-blue-50 ring-2 ring-inset ring-blue-400 dark:bg-blue-500/10'"
@dragover.prevent="droppingTopLevel = true"
@dragleave="!$el.contains($event.relatedTarget) && (droppingTopLevel = false)"
@drop.prevent="droppingTopLevel = false; if (window.__mtFolderDrag) { $wire.moveFolderToTopLevel(window.__mtFolderDrag.folderId); window.__mtFolderDrag = null; }"
data-test="top-level-drop-zone"
>
<div class="flex items-center justify-center gap-2 border-2 border-dashed border-zinc-300 p-3 text-sm text-zinc-500 dark:border-zinc-600 dark:text-zinc-400">
<flux:icon.arrow-up-on-square variant="micro" class="size-4" />
{{ __('Drop here to make it a top-level folder') }}
</div>
</div>
<div class="p-4" :style="'margin-left: {{ $node['depth'] * 1.5 }}rem'">
<div
x-data="{ drop: false }"
class="flex flex-wrap items-center gap-3 transition-colors"
:class="drop && 'rounded-lg bg-blue-50 ring-2 ring-inset ring-blue-400 dark:bg-blue-500/10'"
@dragover.prevent="drop = true"
@dragleave="!$el.contains($event.relatedTarget) && (drop = false)"
@drop.prevent="drop = false; window.__mtFolderDrag ? dropFolder({{ $node['folder']->id }}) : dropTodo({{ $node['folder']->id }})"
data-test="folder-row-{{ $node['folder']->id }}"
>
@if ($renamingFolderId === $node['folder']->id)
<form wire:submit="saveRename" class="flex flex-1 flex-wrap items-center gap-3">
<flux:input
wire:model="renameName"
size="sm"
class="min-w-48 flex-1"
autofocus
data-test="rename-input"
/>
<div class="flex gap-2">
<flux:button size="sm" type="submit" variant="primary" icon="check" data-test="save-rename-button">
{{ __('Save') }}
</flux:button>
<flux:button size="sm" variant="ghost" wire:click="cancelRename">
{{ __('Cancel') }}
</flux:button>
</div>
<flux:error name="renameName" />
</form>
@else
<div class="flex min-w-0 items-center gap-2">
@can('update', $node['folder'])
<div
x-data="{ dragging: false }"
draggable="true"
class="inline-flex shrink-0 cursor-grab text-zinc-400 dark:text-zinc-500"
:class="dragging && 'opacity-40'"
@dragstart="dragging = true; window.__mtFolderDrag = { folderId: {{ $node['folder']->id }} }; $dispatch('folder-drag-start')"
@dragend="dragging = false; window.__mtFolderDrag = null; $dispatch('folder-drag-end')"
title="{{ __('Drag to move this folder') }}"
data-test="drag-folder-{{ $node['folder']->id }}"
>
<flux:icon.chevrons-up-down variant="micro" />
</div>
@endcan
<x-folder-dot :color="$node['folder']->color" data-test="folder-dot-{{ $node['folder']->id }}" />
<flux:heading size="sm" class="truncate" data-test="folder-name-{{ $node['folder']->id }}">
{{ $node['folder']->name }}
</flux:heading>
<span
class="truncate text-xs text-zinc-400 dark:text-zinc-500"
title="{{ __('Workspace') }}"
data-test="folder-workspace-{{ $node['folder']->id }}"
>
{{ $node['folder']->organization?->name }}
</span>
@if ($node['folder']->visibility === \App\FolderVisibility::Workspace || $node['folder']->shares_count > 0)
<flux:badge size="sm" color="zinc" icon="users" data-test="folder-shared-{{ $node['folder']->id }}">
{{ __('Shared') }}
</flux:badge>
@endif
</div>
<flux:badge
size="sm"
color="blue"
class="cursor-pointer select-none"
wire:click="toggleExpandFolder({{ $node['folder']->id }})"
data-test="expand-folder-{{ $node['folder']->id }}"
>
<flux:icon.chevron-down
variant="micro"
:class="'me-0.5' . ($expandedFolderId === $node['folder']->id ? ' rotate-180 transition-transform' : ' transition-transform')"
/>
{{ $this->openCounts->get($node['folder']->id, 0) }} {{ __('open') }}
</flux:badge>
<flux:spacer />
<div class="flex items-center gap-1">
@can('manageShares', $node['folder'])
<flux:tooltip :content="__('Share')">
<flux:button
size="sm"
variant="ghost"
icon="user-plus"
wire:click="startShare({{ $node['folder']->id }})"
data-test="share-folder-{{ $node['folder']->id }}"
/>
</flux:tooltip>
@endcan
@can('update', $node['folder'])
<flux:tooltip :content="__('Choose color')">
<flux:button
size="sm"
variant="ghost"
icon="swatch"
wire:click="startColorEdit({{ $node['folder']->id }})"
data-test="color-folder-{{ $node['folder']->id }}"
/>
</flux:tooltip>
@endcan
<flux:tooltip :content="__('View todos')">
<flux:button
size="sm"
variant="ghost"
icon="magnifying-glass"
:href="route('dashboard', ['folder' => $node['folder']->id])"
wire:navigate
data-test="view-todos-{{ $node['folder']->id }}"
/>
</flux:tooltip>
@can('create', [App\Models\Todo::class, $node['folder']])
<flux:tooltip :content="__('Add todo')">
<flux:button
size="sm"
variant="ghost"
icon="document-plus"
wire:click="startTodoCreate({{ $node['folder']->id }})"
data-test="add-todo-{{ $node['folder']->id }}"
/>
</flux:tooltip>
@endcan
@can('createChild', $node['folder'])
<flux:tooltip :content="__('Add sub-folder')">
<flux:button
size="sm"
variant="ghost"
icon="folder-plus"
wire:click="startChildCreate({{ $node['folder']->id }})"
data-test="add-child-{{ $node['folder']->id }}"
/>
</flux:tooltip>
@endcan
@can('update', $node['folder'])
<flux:tooltip :content="__('Rename')">
<flux:button
size="sm"
variant="ghost"
icon="pencil-square"
wire:click="startRename({{ $node['folder']->id }})"
data-test="rename-folder-{{ $node['folder']->id }}"
/>
</flux:tooltip>
<flux:tooltip :content="__('Delete')">
<flux:button
size="sm"
variant="ghost"
icon="trash"
wire:click="confirmFolderDelete({{ $node['folder']->id }})"
data-test="delete-folder-{{ $node['folder']->id }}"
/>
</flux:tooltip>
@endcan
</div>
@endif
</div>
@if ($expandedFolderId === $node['folder']->id)
<div class="mt-3 flex flex-col gap-2 rounded-lg border border-zinc-200 bg-zinc-50 p-3 dark:border-zinc-700 dark:bg-zinc-800/50" data-test="folder-todos-{{ $node['folder']->id }}">
<flux:text size="sm" class="text-zinc-500">{{ __('Drag a todo onto any folder row to move it.') }}</flux:text>
@forelse ($this->todosForFolder($node['folder']->id) as $todo)
<div
x-data="{ dragging: false }"
draggable="true"
class="flex cursor-grab select-none flex-wrap items-center gap-3"
:class="dragging && 'opacity-40'"
@dragstart="dragging = true; window.__mtTodoDrag = { todoId: {{ $todo->id }}, folderId: {{ $node['folder']->id }} }"
@dragend="dragging = false; window.__mtTodoDrag = null"
data-test="folder-todo-row-{{ $todo->id }}"
>
<flux:icon.chevrons-up-down variant="micro" class="text-zinc-400 dark:text-zinc-500" />
<flux:heading size="sm" class="min-w-0 flex-1 truncate" data-test="folder-todo-description-{{ $todo->id }}">
{{ $todo->description }}
</flux:heading>
<flux:badge size="sm" :color="$todo->status->badgeColor()">
{{ $todo->status->label() }}
</flux:badge>
</div>
@empty
<flux:text class="text-sm text-zinc-500">{{ __('No open todos in this folder.') }}</flux:text>
@endforelse
</div>
@endif
@if ($creatingChildOf === $node['folder']->id)
<form wire:submit="createChildFolder" class="mt-3 flex flex-wrap items-end gap-3">
<div class="min-w-64 flex-1">
<flux:label size="sm">{{ __('Sub-folder of') }} {{ $node['folder']->name }}</flux:label>
<flux:input
wire:model="newChildName"
size="sm"
placeholder="{{ __('Sub-folder name') }}"
data-test="new-child-input"
/>
<flux:error name="newChildName" />
</div>
<div>
<flux:label size="sm">{{ __('Color') }}</flux:label>
<x-color-picker model="newChildColor" />
<flux:error name="newChildColor" />
</div>
<div class="flex gap-2">
<flux:button size="sm" variant="primary" type="submit" icon="plus" data-test="add-child-button">
{{ __('Add') }}
</flux:button>
<flux:button size="sm" variant="ghost" wire:click="cancelChildCreate">
{{ __('Cancel') }}
</flux:button>
</div>
</form>
@endif
</div>
@empty
<div class="p-8">
<flux:text align="center" class="text-sm text-zinc-500">{{ __('No folders to display.') }}</flux:text>
</div>
@endforelse
</div>
<flux:modal wire:model.self="showTodoForm" class="md:w-xl">
<form wire:submit="saveFolderTodo" class="space-y-6">
<div>
@if ($this->todoFolder !== null)
<flux:heading size="lg" class="truncate">
{{ __('Add todo') }} - <span class="text-zinc-500 dark:text-zinc-400" data-test="add-todo-title-folder">{{ $this->todoFolderPath }}</span>
</flux:heading>
@else
<flux:heading size="lg">{{ __('Add todo') }}</flux:heading>
@endif
<flux:text class="mt-2">{{ __('Add a task with a description. A due date is optional.') }}</flux:text>
@if ($this->todoFolder !== null)
<div class="mt-3 flex items-center gap-1.5" data-test="add-todo-folder-name">
<flux:icon.folder variant="micro" class="text-zinc-500 dark:text-zinc-400" />
<flux:text size="sm" class="text-zinc-600 dark:text-zinc-300">
{{ __('Adding to') }}
<strong class="text-zinc-900 dark:text-zinc-100">
{{ $this->todoFolderPath }}
</strong>
</flux:text>
</div>
@endif
</div>
<flux:field>
<flux:label>{{ __('Description') }}</flux:label>
<flux:input
wire:model="todoDescription"
type="text"
autofocus
placeholder="{{ __('What needs to be done?') }}"
data-test="todo-description-input"
/>
<flux:error name="todoDescription" />
</flux:field>
<flux:field>
<flux:label>{{ __('Status') }}</flux:label>
<flux:select wire:model="todoStatus" data-test="todo-status-select">
@foreach (TodoStatus::cases() as $status)
<flux:select.option :value="$status->value">{{ $status->label() }}</flux:select.option>
@endforeach
</flux:select>
<flux:error name="todoStatus" />
</flux:field>
<flux:field>
<flux:label>{{ __('Due date') }}</flux:label>
<flux:input wire:model="todoDueDate" type="date" data-test="todo-due-date-input" />
<flux:error name="todoDueDate" />
</flux:field>
<flux:field>
<flux:label>{{ __('Notes') }}</flux:label>
<flux:textarea
wire:model="todoNotes"
rows="3"
placeholder="{{ __('Add any extra details…') }}"
data-test="todo-notes-input"
/>
<flux:error name="todoNotes" />
</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">{{ __('Add todo') }}</flux:button>
</div>
</form>
</flux:modal>
<flux:modal name="folder-color" class="md:w-lg">
<form wire:submit="saveFolderColor" class="space-y-6">
<div>
<flux:heading size="lg">{{ __('Folder color') }}</flux:heading>
<flux:text class="mt-2">{{ __('Choose a color for this folder, or clear it to remove any color.') }}</flux:text>
</div>
<flux:field>
<flux:label>{{ __('Color') }}</flux:label>
<x-color-picker model="colorDraft" />
<flux:error name="colorDraft" />
</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" data-test="save-folder-color">
{{ __('Save color') }}
</flux:button>
</div>
</form>
</flux:modal>
<flux:modal name="confirm-folder-delete" class="md:w-lg">
<div class="space-y-6">
<div>
<flux:heading size="lg">{{ __('Delete folder?') }}</flux:heading>
<flux:text class="mt-2">
{{ __('Deleting a folder also deletes its sub-folders and every todo inside them. This action cannot be undone.') }}
</flux:text>
</div>
<div class="flex justify-end gap-3">
<flux:modal.close>
<flux:button variant="ghost">{{ __('Cancel') }}</flux:button>
</flux:modal.close>
<flux:button variant="danger" wire:click="deleteFolder" data-test="confirm-delete-folder">
{{ __('Delete folder') }}
</flux:button>
</div>
</div>
</flux:modal>
<flux:modal name="folder-share" class="md:w-2xl">
@if ($this->sharingFolder !== null)
<div class="space-y-6" data-test="folder-share-panel">
<div>
<flux:heading size="lg">{{ __('Share folder') }}</flux:heading>
<flux:text class="mt-2">
{{ __('Manage who can access ":name" and what they can do.', ['name' => $this->sharingFolder->name]) }}
</flux:text>
</div>
@if ($this->sharingFolder->organization !== null && ! $this->sharingFolder->organization->isPersonal())
<flux:field>
<flux:label>{{ __('Visibility') }}</flux:label>
<flux:select wire:model.live="shareVisibility" data-test="visibility-select">
@foreach (FolderVisibility::cases() as $visibility)
<flux:select.option value="{{ $visibility->value }}">{{ $visibility->label() }}</flux:select.option>
@endforeach
</flux:select>
<flux:error name="shareVisibility" />
<flux:description>
{{ __('Workspace folders are visible to every member of :name.', ['name' => $this->sharingFolder->organization->name]) }}
</flux:description>
</flux:field>
@else
<flux:callout icon="lock-closed" data-test="personal-share-notice">
{{ __('This folder is only visible to you. Personal workspaces cannot hold other members.') }}
</flux:callout>
@endif
<div class="space-y-3">
<flux:heading size="sm">{{ __('Collaborators') }}</flux:heading>
<div class="flex items-center justify-between gap-3" data-test="folder-owner-row">
<flux:text>{{ $this->sharingFolder->user?->name }}</flux:text>
<flux:badge size="sm" color="blue">{{ __('Owner') }}</flux:badge>
</div>
@forelse ($this->sharingCollaborators as $collaborator)
<div class="flex flex-wrap items-center justify-between gap-3" data-test="collaborator-row-{{ $collaborator->id }}">
<div class="flex min-w-0 items-center gap-2">
<flux:text class="truncate">{{ $collaborator->name }}</flux:text>
<flux:text size="sm" class="truncate text-zinc-500 dark:text-zinc-400">{{ $collaborator->email }}</flux:text>
</div>
<div class="flex items-center gap-2">
<flux:select
size="sm"
wire:model.live="collaboratorRoles.{{ $collaborator->id }}"
data-test="collaborator-role-{{ $collaborator->id }}"
>
@foreach (FolderRole::assignable() as $role)
<flux:select.option value="{{ $role->value }}">{{ $role->label() }}</flux:select.option>
@endforeach
</flux:select>
<flux:button
size="sm"
variant="ghost"
icon="trash"
wire:click="removeCollaborator({{ $collaborator->id }})"
data-test="remove-collaborator-{{ $collaborator->id }}"
/>
</div>
</div>
@empty
<flux:text size="sm" class="text-zinc-500 dark:text-zinc-400">{{ __('No one else has access yet.') }}</flux:text>
@endforelse
</div>
<form wire:submit="inviteCollaborator" class="space-y-3">
<flux:heading size="sm">{{ __('Invite by email') }}</flux:heading>
<div class="flex flex-wrap items-start gap-3">
<div class="min-w-56 flex-1">
<flux:input
wire:model="inviteEmail"
type="email"
placeholder="name@example.com"
data-test="invite-email-input"
/>
<flux:error name="inviteEmail" />
</div>
<div>
<flux:select wire:model="inviteRole" data-test="invite-role-select">
@foreach (FolderRole::assignable() as $role)
<flux:select.option value="{{ $role->value }}">{{ $role->label() }}</flux:select.option>
@endforeach
</flux:select>
<flux:error name="inviteRole" />
</div>
<flux:button type="submit" variant="primary" icon="paper-airplane" data-test="invite-collaborator-button">
{{ __('Send invite') }}
</flux:button>
</div>
</form>
@if ($this->sharingInvitations->isNotEmpty())
<div class="space-y-3">
<flux:heading size="sm">{{ __('Pending invitations') }}</flux:heading>
@foreach ($this->sharingInvitations as $invitation)
<div class="flex flex-wrap items-center justify-between gap-3" data-test="invitation-row-{{ $invitation->id }}">
<div class="flex min-w-0 items-center gap-2">
<flux:text class="truncate">{{ $invitation->email }}</flux:text>
<flux:badge size="sm">{{ $invitation->roleLabel() }}</flux:badge>
</div>
<flux:button
size="sm"
variant="ghost"
icon="x-mark"
wire:click="revokeFolderInvitation({{ $invitation->id }})"
data-test="revoke-invitation-{{ $invitation->id }}"
>
{{ __('Revoke') }}
</flux:button>
</div>
@endforeach
</div>
@endif
<div class="flex justify-end gap-3">
<flux:button variant="ghost" wire:click="closeShare" data-test="close-share-button">
{{ __('Done') }}
</flux:button>
</div>
</div>
@endif
</flux:modal>
</div>