This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
use App\Models\Folder;
|
||||
use App\Models\Todo;
|
||||
use App\TodoStatus;
|
||||
use Illuminate\Support\Carbon;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Validation\Rule;
|
||||
@@ -34,6 +35,8 @@ new #[Title('Folders')] class extends Component
|
||||
|
||||
public string $todoDescription = '';
|
||||
|
||||
public string $todoStatus = 'open';
|
||||
|
||||
public ?string $todoDueDate = null;
|
||||
|
||||
public string $todoNotes = '';
|
||||
@@ -132,8 +135,8 @@ new #[Title('Folders')] class extends Component
|
||||
$this->folderForUser($folderId);
|
||||
|
||||
$this->todoFolderId = $folderId;
|
||||
$this->reset('todoDescription', 'todoDueDate', 'todoNotes');
|
||||
$this->resetErrorBag('todoDescription', 'todoDueDate', 'todoNotes');
|
||||
$this->reset('todoDescription', 'todoStatus', 'todoDueDate', 'todoNotes');
|
||||
$this->resetErrorBag('todoDescription', 'todoStatus', 'todoDueDate', 'todoNotes');
|
||||
$this->showTodoForm = true;
|
||||
}
|
||||
|
||||
@@ -143,6 +146,7 @@ new #[Title('Folders')] class extends Component
|
||||
|
||||
$validated = $this->validate([
|
||||
'todoDescription' => ['required', 'string', 'max:255'],
|
||||
'todoStatus' => ['required', Rule::enum(TodoStatus::class)],
|
||||
'todoDueDate' => ['nullable', 'date'],
|
||||
'todoNotes' => ['nullable', 'string', 'max:'.auth()->user()->notesLimit()],
|
||||
]);
|
||||
@@ -151,11 +155,12 @@ new #[Title('Folders')] class extends Component
|
||||
'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,
|
||||
]);
|
||||
|
||||
$this->reset('showTodoForm', 'todoFolderId', 'todoDescription', 'todoDueDate', 'todoNotes');
|
||||
$this->reset('showTodoForm', 'todoFolderId', 'todoDescription', 'todoStatus', 'todoDueDate', 'todoNotes');
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
@@ -164,12 +169,34 @@ new #[Title('Folders')] class extends Component
|
||||
return Folder::treeForUser(auth()->id());
|
||||
}
|
||||
|
||||
#[Computed]
|
||||
public function todoFolder(): ?Folder
|
||||
{
|
||||
if ($this->todoFolderId === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Folder::query()->with('parent')->forUser(auth()->id())->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()
|
||||
->forUser(auth()->id())
|
||||
->incomplete()
|
||||
->active()
|
||||
->pluck('folder_id')
|
||||
->countBy();
|
||||
}
|
||||
@@ -347,8 +374,26 @@ new #[Title('Folders')] class extends Component
|
||||
<flux:modal wire:model.self="showTodoForm" class="md:w-xl">
|
||||
<form wire:submit="saveFolderTodo" class="space-y-6">
|
||||
<div>
|
||||
<flux:heading size="lg">{{ __('Add todo') }}</flux:heading>
|
||||
@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>
|
||||
@@ -363,6 +408,16 @@ new #[Title('Folders')] class extends Component
|
||||
<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" />
|
||||
|
||||
Reference in New Issue
Block a user