Skip to content

Commit

Permalink
Feat: Create new Board
Browse files Browse the repository at this point in the history
  • Loading branch information
ismaail committed Oct 26, 2024
2 parents f2a0b1b + 28cdd38 commit dab23d1
Show file tree
Hide file tree
Showing 8 changed files with 122 additions and 5 deletions.
14 changes: 14 additions & 0 deletions app/Livewire/Board/Forms/BoardForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace App\Livewire\Board\Forms;

use Livewire\Attributes\Validate;
use Livewire\Form;

class BoardForm extends Form
{
#[Validate(['required', 'string', 'min:3', 'max:255'])]
public string $name;
}
44 changes: 44 additions & 0 deletions app/Livewire/Board/Modals/CreateBoard.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<?php

declare(strict_types=1);

namespace App\Livewire\Board\Modals;

use App\Livewire\Board\Forms\BoardForm;
use Domain\Board\Models\Board;
use Domain\Bucket\Models\Bucket;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\DB;
use LivewireUI\Modal\ModalComponent;

class CreateBoard extends ModalComponent
{
public BoardForm $form;

public bool $withDefaultBuckets = false;

public function create(): void
{
$this->validate();

DB::transaction(function () {
$board = Board::create($this->form->toArray());

if ($this->withDefaultBuckets) {
/** @var Bucket[] $buckets */
$buckets = collect(['Backlog', 'To Do', 'In Progress', 'Done'])
->map(fn ($name) => Bucket::make(['name' => $name]));

$board->buckets()->saveMany($buckets);
}
});

$this->dispatch('closeModal');
$this->dispatch('home-updated');
}

public function render(): View
{
return view('livewire.board.modals.create-board');
}
}
7 changes: 7 additions & 0 deletions app/Livewire/HomeComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ class HomeComponent extends Component
{
private User $user;

/**
* @var array<string, string>
*/
protected $listeners = [
'home-updated' => '$refresh',
];

public function boot(#[CurrentUser] User $user): void
{
$this->user = $user;
Expand Down
11 changes: 11 additions & 0 deletions resources/assets/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,23 @@
@tailwind utilities;

@layer base {
:root {
--image-checkbox: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3e%3cpath fill='none' stroke='%23fff' stroke-linecap='round' stroke-linejoin='round' stroke-width='3' d='M6 10l3 3l6-6'/%3e%3c/svg%3e");
}

html, body {
@apply h-screen;
}
body {
@apply flex flex-col items-start tracking-wide font-normal bg-secondary text-black;
}

input[type="checkbox"] {
@apply block w-4 h-4 bg-white dark:bg-gray-700 border border-gray-400 outline-none dark:border-gray-600 rounded text-blue-600 cursor-pointer appearance-none;
background-image: var(--image-checkbox);

&:checked { @apply bg-blue-600; }
}
}

.scrollbar {
Expand Down
4 changes: 4 additions & 0 deletions resources/views/components/icons/spinner.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<svg {{ $attributes->twMerge('inline size-6 text-white fill-gray-500 animate-spin') }} aria-hidden="true" role="status" viewBox="0 0 100 101" fill="fillColor" xmlns="http://www.w3.org/2000/svg">
<path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentFill"></path>
<path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentColor"></path>
</svg>
37 changes: 37 additions & 0 deletions resources/views/livewire/board/modals/create-board.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<div class="w-[600px] py-1">
<div class="flex px-2 justify-between items-center">
<h2 class="font-semibold">Create New Board</h2>
<button wire:click="$dispatch('closeModal')" class="fill-secondary text-white hover:fill-secondary/90 hover:text-white">
<x-icons.circle-close class="size-8"></x-icons.circle-close>
</button>
</div>
<form class="my-2 px-2 pt-2 space-y-4 border-t border-gray-300" wire:submit.prevent="create">
{{-- Name --}}
<div>
<label for="name" class="block textsm font-semibold">Name</label>
<input
type="text"
wire:model="form.name"
id="name"
required
autocomplete="name"
autofocus
class="block w-full mt-2 py-1 px-2 border border-gray-400 rounded-md shadow-sm outline-none focus:border-sky-500 focus:ring-sky-500">
@error('form.name')<span class="text-xs text-red-600">{{ $message }}</span>@enderror
</div>
{{-- Default Buckets --}}
<div>
<div class="flex items-center gap-x-1">
<input wire:model="withDefaultBuckets" type="checkbox" id="default-buckets">
<label for="default-buckets" class="block text-sm cursor-pointer">with default Buckets</label>
</div>
</div>
{{-- Buttons --}}
<div class="flex justify-end">
<button type="submit" class="floatend w-40 mr-2 px-5 py-2 rounded bg-secondary hover:bg-secondary/90 disabled:bg-gray-400 text-center font-semibold text-white tracking-wider">
<span wire:loading.class="hidden">Create</span>
<span wire:loading><x-icons.spinner /></span>
</button>
</div>
</form>
</div>
5 changes: 1 addition & 4 deletions resources/views/livewire/card/modals/create-card.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,7 @@
<div class="flex justify-end">
<button type="submit" class="floatend w-40 mr-2 px-5 py-2 rounded bg-secondary hover:bg-secondary/90 disabled:bg-gray-400 text-center font-semibold text-white tracking-wider">
<span wire:loading.class="hidden">Create</span>
<span wire:loading><svg class="inline w-5 h-5 text-white animate-spin" aria-hidden="true" role="status" viewBox="0 0 100 101" fill="#e5e7eb" xmlns="http://www.w3.org/2000/svg">
<path d="M100 50.5908C100 78.2051 77.6142 100.591 50 100.591C22.3858 100.591 0 78.2051 0 50.5908C0 22.9766 22.3858 0.59082 50 0.59082C77.6142 0.59082 100 22.9766 100 50.5908ZM9.08144 50.5908C9.08144 73.1895 27.4013 91.5094 50 91.5094C72.5987 91.5094 90.9186 73.1895 90.9186 50.5908C90.9186 27.9921 72.5987 9.67226 50 9.67226C27.4013 9.67226 9.08144 27.9921 9.08144 50.5908Z" fill="currentFill"></path>
<path d="M93.9676 39.0409C96.393 38.4038 97.8624 35.9116 97.0079 33.5539C95.2932 28.8227 92.871 24.3692 89.8167 20.348C85.8452 15.1192 80.8826 10.7238 75.2124 7.41289C69.5422 4.10194 63.2754 1.94025 56.7698 1.05124C51.7666 0.367541 46.6976 0.446843 41.7345 1.27873C39.2613 1.69328 37.813 4.19778 38.4501 6.62326C39.0873 9.04874 41.5694 10.4717 44.0505 10.1071C47.8511 9.54855 51.7191 9.52689 55.5402 10.0491C60.8642 10.7766 65.9928 12.5457 70.6331 15.2552C75.2735 17.9648 79.3347 21.5619 82.5849 25.841C84.9175 28.9121 86.7997 32.2913 88.1811 35.8758C89.083 38.2158 91.5421 39.6781 93.9676 39.0409Z" fill="currentColor"></path>
</svg></span>
<span wire:loading><x-icons.spinner /></span>
</button>
</div>
</form>
Expand Down
5 changes: 4 additions & 1 deletion resources/views/livewire/home-component.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
@endif
</a>
@endforeach
<button class="flex items-center gap-x-1 w-72 p-2 rounded text-white hover:text-primary font-semibold cursor-pointer">
<button
wire:click="$dispatch('openModal', { component: 'board.modals.create-board'})"
title="Create new Board"
class="flex items-center gap-x-1 w-72 p-2 rounded text-white hover:text-primary font-semibold cursor-pointer">
<x-icons.plus class="size-5" /> New Board
</button>
</div>
Expand Down

0 comments on commit dab23d1

Please sign in to comment.