-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* #13 - wip * #13 - wip, refactor * #13 - wip, refactor * #13 - wip, working on icons * #13 - wip, refactored views to match new changes in forms * #15 - wip * #13 - finished working on basic version, added test * #13 - added spatie/laravel-options
- Loading branch information
1 parent
de82ed6
commit e926d78
Showing
23 changed files
with
794 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Enums; | ||
|
||
enum Icons: string | ||
{ | ||
case AtSymbol = "at-symbol"; | ||
case Envelope = "envelope"; | ||
case Exclamation = "exclamation"; | ||
case Github = "github"; | ||
case Information = "information"; | ||
case Linkedin = "linkedin"; | ||
case Slack = "slack"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Controllers\Dashboard; | ||
|
||
use App\Enums\Icons; | ||
use App\Http\Controllers\Controller; | ||
use App\Http\Requests\ContactInfoRequest; | ||
use App\Models\ContactInfo; | ||
use Illuminate\Http\RedirectResponse; | ||
use Illuminate\Http\Request; | ||
use Inertia\Response; | ||
use Spatie\LaravelOptions\Options; | ||
|
||
class ContactInfoController extends Controller | ||
{ | ||
public function index(Request $request): Response | ||
{ | ||
$contactInfos = ContactInfo::query() | ||
->orderByDesc("created_at") | ||
->get(); | ||
|
||
return inertia("Dashboard/ContactInfo/Index", [ | ||
"contactInfos" => $contactInfos, | ||
"total" => ContactInfo::query()->count(), | ||
"lastUpdate" => ContactInfo::query()->orderByDesc("updated_at")->first()?->updated_at->diffForHumans(), | ||
]); | ||
} | ||
|
||
public function create(): Response | ||
{ | ||
return inertia("Dashboard/ContactInfo/Create", [ | ||
"icons" => Options::forEnum(Icons::class)->toArray(), | ||
]); | ||
} | ||
|
||
public function store(ContactInfoRequest $request): RedirectResponse | ||
{ | ||
ContactInfo::query()->create($request->validated()); | ||
|
||
return redirect() | ||
->route("contactInfo.index") | ||
->with("success", "Dodano formę kontaktu"); | ||
} | ||
|
||
public function edit(ContactInfo $contactInfo): Response | ||
{ | ||
return inertia("Dashboard/ContactInfo/Edit", [ | ||
"contactInfo" => $contactInfo, | ||
"icons" => Options::forEnum(Icons::class)->toArray(), | ||
]); | ||
} | ||
|
||
public function update(ContactInfoRequest $request, ContactInfo $contactInfo): RedirectResponse | ||
{ | ||
$contactInfo->update($request->validated()); | ||
|
||
return redirect() | ||
->route("contactInfo.index") | ||
->with("success", "Zaktualizowano formę kontaktu"); | ||
} | ||
|
||
public function destroy(ContactInfo $contactInfo): RedirectResponse | ||
{ | ||
$contactInfo->delete(); | ||
|
||
return redirect()->back() | ||
->with("success", "Usunięto formę kontaktu"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Http\Requests; | ||
|
||
use App\Enums\Icons; | ||
use Illuminate\Foundation\Http\FormRequest; | ||
use Illuminate\Validation\Rules\Enum; | ||
|
||
class ContactInfoRequest extends FormRequest | ||
{ | ||
public function rules(): array | ||
{ | ||
return [ | ||
"label" => ["required", "string", "max:255"], | ||
"identifier" => ["required", "string", "max:255"], | ||
"icon" => ["required", new Enum(Icons::class)], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace App\Models; | ||
|
||
use Carbon\Carbon; | ||
use Illuminate\Database\Eloquent\Concerns\HasUlids; | ||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
/** | ||
* @property string $id | ||
* @property string $email | ||
* @property string $github_handle | ||
* @property string $alternative_channel | ||
* @property Carbon $created_at | ||
* @property Carbon $updated_at | ||
*/ | ||
class ContactInfo extends Model | ||
{ | ||
use HasFactory; | ||
use HasUlids; | ||
|
||
protected $guarded = []; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Database\Factories; | ||
|
||
use App\Enums\Icons; | ||
use App\Models\ContactInfo; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
/** | ||
* @extends Factory<ContactInfo> | ||
*/ | ||
class ContactInfoFactory extends Factory | ||
{ | ||
public function definition(): array | ||
{ | ||
return [ | ||
"label" => fake()->domainWord(), | ||
"identifier" => fake()->url(), | ||
"icon" => fake()->randomElement(Icons::class), | ||
]; | ||
} | ||
} |
Oops, something went wrong.