From f96fe2eaa0a46f3669794a0ecb33876b49be9eee Mon Sep 17 00:00:00 2001 From: KarolZygadlo Date: Sun, 24 Sep 2023 11:18:05 +0200 Subject: [PATCH 1/8] #13 - wip --- .../Controllers/ContactInfoController.php | 28 ++++++++ .../Requests/UpdateContactInfoRequest.php | 19 +++++ app/Models/ContactInfo.php | 26 +++++++ app/Models/User.php | 21 +++--- database/factories/ContactInfoFactory.php | 23 ++++++ database/factories/UserFactory.php | 21 ++---- .../2014_10_12_000000_create_users_table.php | 4 +- ...9_23_135710_create_contact_infos_table.php | 25 +++++++ database/seeders/DatabaseSeeder.php | 10 ++- resources/js/Layouts/DashboardLayout.vue | 2 +- resources/js/Pages/Dashboard/ContactInfo.vue | 68 ++++++++++++++++++ routes/web.php | 3 + tests/Feature/ContactInfoTest.php | 71 +++++++++++++++++++ 13 files changed, 289 insertions(+), 32 deletions(-) create mode 100644 app/Http/Controllers/ContactInfoController.php create mode 100644 app/Http/Requests/UpdateContactInfoRequest.php create mode 100644 app/Models/ContactInfo.php create mode 100644 database/factories/ContactInfoFactory.php create mode 100644 database/migrations/2023_09_23_135710_create_contact_infos_table.php create mode 100644 resources/js/Pages/Dashboard/ContactInfo.vue create mode 100644 tests/Feature/ContactInfoTest.php diff --git a/app/Http/Controllers/ContactInfoController.php b/app/Http/Controllers/ContactInfoController.php new file mode 100644 index 0000000..039f195 --- /dev/null +++ b/app/Http/Controllers/ContactInfoController.php @@ -0,0 +1,28 @@ + ContactInfo::query()->first(), + ]); + } + + public function update(UpdateContactInfoRequest $request): RedirectResponse + { + ContactInfo::query()->first()->update($request->validated()); + + return redirect()->back() + ->with("success", "Zaktualizowano formy kontaktu"); + } +} diff --git a/app/Http/Requests/UpdateContactInfoRequest.php b/app/Http/Requests/UpdateContactInfoRequest.php new file mode 100644 index 0000000..a484cb4 --- /dev/null +++ b/app/Http/Requests/UpdateContactInfoRequest.php @@ -0,0 +1,19 @@ + ["required", "email", "max:255"], + "github_handle" => ["nullable", "url"], + "alternative_channel" => ["nullable", "url"], + ]; + } +} diff --git a/app/Models/ContactInfo.php b/app/Models/ContactInfo.php new file mode 100644 index 0000000..f1bb1f0 --- /dev/null +++ b/app/Models/ContactInfo.php @@ -0,0 +1,26 @@ + "datetime", "password" => "hashed", ]; } diff --git a/database/factories/ContactInfoFactory.php b/database/factories/ContactInfoFactory.php new file mode 100644 index 0000000..0ea6355 --- /dev/null +++ b/database/factories/ContactInfoFactory.php @@ -0,0 +1,23 @@ + + */ +class ContactInfoFactory extends Factory +{ + public function definition(): array + { + return [ + "email" => fake()->unique()->email(), + "github_handle" => fake()->optional()->url(), + "alternative_channel" => fake()->optional()->url(), + ]; + } +} diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index aa9c54b..3553ec8 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -4,11 +4,12 @@ namespace Database\Factories; +use App\Models\User; use Illuminate\Database\Eloquent\Factories\Factory; -use Illuminate\Support\Str; +use Illuminate\Support\Facades\Hash; /** - * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User> + * @extends Factory */ class UserFactory extends Factory { @@ -21,20 +22,8 @@ public function definition(): array { return [ "name" => fake()->name(), - "email" => fake()->unique()->safeEmail(), - "email_verified_at" => now(), - "password" => "$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi", - "remember_token" => Str::random(10), + "email" => "user@example.pl", + "password" => Hash::make("password"), ]; } - - /** - * Indicate that the model's email address should be unverified. - */ - public function unverified(): static - { - return $this->state(fn(array $attributes) => [ - "email_verified_at" => null, - ]); - } } diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index 4ceb0bd..95e81f4 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -10,12 +10,10 @@ public function up(): void { Schema::create("users", function (Blueprint $table): void { - $table->id(); + $table->ulid("id")->primary(); $table->string("name"); $table->string("email")->unique(); - $table->timestamp("email_verified_at")->nullable(); $table->string("password"); - $table->rememberToken(); $table->timestamps(); }); } diff --git a/database/migrations/2023_09_23_135710_create_contact_infos_table.php b/database/migrations/2023_09_23_135710_create_contact_infos_table.php new file mode 100644 index 0000000..155973e --- /dev/null +++ b/database/migrations/2023_09_23_135710_create_contact_infos_table.php @@ -0,0 +1,25 @@ +ulid("id")->primary(); + $table->string("email"); + $table->string("github_handle")->nullable(); + $table->string("alternative_channel")->nullable(); + $table->timestamps(); + }); + } + + public function down(): void + { + Schema::dropIfExists("contact_infos"); + } +}; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index 6425c0d..34a3338 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -4,14 +4,18 @@ namespace Database\Seeders; +use App\Models\ContactInfo; +use App\Models\User; use Illuminate\Database\Seeder; class DatabaseSeeder extends Seeder { - /** - * Seed the application's database. - */ public function run(): void { + User::factory(1)->create([ + "email" => "user@example.com", + ]); + + ContactInfo::factory(1)->create(); } } diff --git a/resources/js/Layouts/DashboardLayout.vue b/resources/js/Layouts/DashboardLayout.vue index 830d61e..6c33d1d 100644 --- a/resources/js/Layouts/DashboardLayout.vue +++ b/resources/js/Layouts/DashboardLayout.vue @@ -39,7 +39,7 @@ const navigation = [ { name: 'Ustawienia', href: '#', icon: Cog6ToothIcon, current: false }, { name: 'Aktualności', href: '#', icon: NewspaperIcon, current: false }, { name: 'FAQ', href: '#', icon: QuestionMarkCircleIcon, current: false }, - { name: 'Formy kontaktu', href: '#', icon: AtSymbolIcon, current: false }, + { name: 'Formy kontaktu', href: '/dashboard/contact-info', icon: AtSymbolIcon, current: false }, ], }, { diff --git a/resources/js/Pages/Dashboard/ContactInfo.vue b/resources/js/Pages/Dashboard/ContactInfo.vue new file mode 100644 index 0000000..cc2b544 --- /dev/null +++ b/resources/js/Pages/Dashboard/ContactInfo.vue @@ -0,0 +1,68 @@ + + + diff --git a/routes/web.php b/routes/web.php index 048cad3..9dce03e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -2,6 +2,7 @@ declare(strict_types=1); +use App\Http\Controllers\ContactInfoController; use App\Http\Controllers\Dashboard\DashboardController; use App\Http\Controllers\Dashboard\StudentController; use App\Http\Controllers\Public\HomeController; @@ -13,6 +14,8 @@ Route::prefix("dashboard")->group(function (): void { Route::get("/", DashboardController::class); + Route::get("/contact-info", [ContactInfoController::class, "edit"])->name("contactInfo.edit"); + Route::patch("/contact-info", [ContactInfoController::class, "update"])->name("contactInfo.update"); Route::controller(StudentController::class)->group(function (): void { Route::get("/students", "index")->name("students.index"); Route::get("/students/create", "create")->name("students.create"); diff --git a/tests/Feature/ContactInfoTest.php b/tests/Feature/ContactInfoTest.php new file mode 100644 index 0000000..48cc495 --- /dev/null +++ b/tests/Feature/ContactInfoTest.php @@ -0,0 +1,71 @@ +user = User::factory()->create(); + $this->contactInfo = ContactInfo::factory()->create([ + "github_handle" => null, + "alternative_channel" => null + ]); + } + + public function testContactInfoCanBeUpdated(): void + { + $this->assertDatabaseMissing("contact_infos", [ + "email" => "user@collegiumwitelona.pl", + "github_handle" => "https://test@test.pl", + "alternative_channel" => "https://test@test.pl", + ]); + + $this->actingAs($this->user)->patch("/dashboard/contact-info", [ + "email" => "user@collegiumwitelona.pl", + "github_handle" => "https://test@test.pl", + "alternative_channel" => "https://test@test.pl", + ])->assertSessionHasNoErrors(); + + $this->assertDatabaseHas("contact_infos", [ + "email" => "user@collegiumwitelona.pl", + "github_handle" => "https://test@test.pl", + "alternative_channel" => "https://test@test.pl", + ]); + } + + public function testContactInfoCanBeUpdatedWithOnlyEmail(): void + { + $this->actingAs($this->user)->patch("/dashboard/contact-info", [ + "email" => "user@collegiumwitelona.pl", + ])->assertSessionHasNoErrors(); + + $this->assertDatabaseHas("contact_infos", [ + "email" => "user@collegiumwitelona.pl", + "github_handle" => null, + "alternative_channel" => null, + ]); + } + + public function testContactInfoCannotBeUpdatedWithoutEmail(): void + { + $this->actingAs($this->user)->patch("/dashboard/contact-info", [ + "email" => null, + "github_handle" => "https://test@test.pl", + "alternative_channel" => "https://test@test.pl", + ])->assertSessionHasErrors("email"); + } + +} From 599a9d9073563b6c18577559af3a61279347a52f Mon Sep 17 00:00:00 2001 From: KarolZygadlo Date: Mon, 25 Sep 2023 21:51:25 +0200 Subject: [PATCH 2/8] #13 - wip, refactor --- .../Controllers/ContactInfoController.php | 28 ----- .../Dashboard/ContactInfoController.php | 74 +++++++++++ app/Http/Requests/ContactInfoRequest.php | 18 +++ .../Requests/UpdateContactInfoRequest.php | 19 --- database/factories/ContactInfoFactory.php | 5 +- ...9_23_135710_create_contact_infos_table.php | 5 +- resources/js/Layouts/DashboardLayout.vue | 2 +- .../js/Pages/Dashboard/ContactInfo/Create.vue | 67 ++++++++++ .../{ContactInfo.vue => ContactInfo/Edit.vue} | 36 +++--- .../js/Pages/Dashboard/ContactInfo/Index.vue | 111 ++++++++++++++++ resources/js/Shared/Forms/ImageUploader.vue | 118 ++++++++++++++++++ routes/web.php | 16 ++- 12 files changed, 417 insertions(+), 82 deletions(-) delete mode 100644 app/Http/Controllers/ContactInfoController.php create mode 100644 app/Http/Controllers/Dashboard/ContactInfoController.php create mode 100644 app/Http/Requests/ContactInfoRequest.php delete mode 100644 app/Http/Requests/UpdateContactInfoRequest.php create mode 100644 resources/js/Pages/Dashboard/ContactInfo/Create.vue rename resources/js/Pages/Dashboard/{ContactInfo.vue => ContactInfo/Edit.vue} (52%) create mode 100644 resources/js/Pages/Dashboard/ContactInfo/Index.vue create mode 100644 resources/js/Shared/Forms/ImageUploader.vue diff --git a/app/Http/Controllers/ContactInfoController.php b/app/Http/Controllers/ContactInfoController.php deleted file mode 100644 index 039f195..0000000 --- a/app/Http/Controllers/ContactInfoController.php +++ /dev/null @@ -1,28 +0,0 @@ - ContactInfo::query()->first(), - ]); - } - - public function update(UpdateContactInfoRequest $request): RedirectResponse - { - ContactInfo::query()->first()->update($request->validated()); - - return redirect()->back() - ->with("success", "Zaktualizowano formy kontaktu"); - } -} diff --git a/app/Http/Controllers/Dashboard/ContactInfoController.php b/app/Http/Controllers/Dashboard/ContactInfoController.php new file mode 100644 index 0000000..d1fc283 --- /dev/null +++ b/app/Http/Controllers/Dashboard/ContactInfoController.php @@ -0,0 +1,74 @@ +query("search"); + $contactInfos = ContactInfo::query() + ->when( + $searchText !== null, + fn(Builder $query): Builder => $query + ->where("label", "ILIKE", "%$searchText%") + ->orWhere("link", "ILIKE", "%$searchText%") + ) + ->paginate() + ->withQueryString(); + + 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"); + } + + 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, + ]); + } + + 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"); + } +} diff --git a/app/Http/Requests/ContactInfoRequest.php b/app/Http/Requests/ContactInfoRequest.php new file mode 100644 index 0000000..8fd9286 --- /dev/null +++ b/app/Http/Requests/ContactInfoRequest.php @@ -0,0 +1,18 @@ + ["required", "string", "max:255"], + "link" => ["required", "url", "max:255"], + ]; + } +} diff --git a/app/Http/Requests/UpdateContactInfoRequest.php b/app/Http/Requests/UpdateContactInfoRequest.php deleted file mode 100644 index a484cb4..0000000 --- a/app/Http/Requests/UpdateContactInfoRequest.php +++ /dev/null @@ -1,19 +0,0 @@ - ["required", "email", "max:255"], - "github_handle" => ["nullable", "url"], - "alternative_channel" => ["nullable", "url"], - ]; - } -} diff --git a/database/factories/ContactInfoFactory.php b/database/factories/ContactInfoFactory.php index 0ea6355..5a904f7 100644 --- a/database/factories/ContactInfoFactory.php +++ b/database/factories/ContactInfoFactory.php @@ -15,9 +15,8 @@ class ContactInfoFactory extends Factory public function definition(): array { return [ - "email" => fake()->unique()->email(), - "github_handle" => fake()->optional()->url(), - "alternative_channel" => fake()->optional()->url(), + "label" => fake()->domainWord(), + "link" => fake()->url(), ]; } } diff --git a/database/migrations/2023_09_23_135710_create_contact_infos_table.php b/database/migrations/2023_09_23_135710_create_contact_infos_table.php index 155973e..d49def4 100644 --- a/database/migrations/2023_09_23_135710_create_contact_infos_table.php +++ b/database/migrations/2023_09_23_135710_create_contact_infos_table.php @@ -11,9 +11,8 @@ public function up(): void { Schema::create("contact_infos", function (Blueprint $table): void { $table->ulid("id")->primary(); - $table->string("email"); - $table->string("github_handle")->nullable(); - $table->string("alternative_channel")->nullable(); + $table->string("label"); + $table->string("link"); $table->timestamps(); }); } diff --git a/resources/js/Layouts/DashboardLayout.vue b/resources/js/Layouts/DashboardLayout.vue index 91af27f..c148768 100644 --- a/resources/js/Layouts/DashboardLayout.vue +++ b/resources/js/Layouts/DashboardLayout.vue @@ -41,7 +41,7 @@ const navigation = [ { name: 'Aktualizacja hasła', href: '/dashboard/password', icon: LockOpenIcon, current: false }, { name: 'Aktualności', href: '#', icon: NewspaperIcon, current: false }, { name: 'FAQ', href: '#', icon: QuestionMarkCircleIcon, current: false }, - { name: 'Formy kontaktu', href: '/dashboard/contact-info', icon: AtSymbolIcon, current: false }, + { name: 'Formy kontaktu', href: '/dashboard/contact-infos', icon: AtSymbolIcon, current: false }, ], }, { diff --git a/resources/js/Pages/Dashboard/ContactInfo/Create.vue b/resources/js/Pages/Dashboard/ContactInfo/Create.vue new file mode 100644 index 0000000..d6d9edc --- /dev/null +++ b/resources/js/Pages/Dashboard/ContactInfo/Create.vue @@ -0,0 +1,67 @@ + + + diff --git a/resources/js/Pages/Dashboard/ContactInfo.vue b/resources/js/Pages/Dashboard/ContactInfo/Edit.vue similarity index 52% rename from resources/js/Pages/Dashboard/ContactInfo.vue rename to resources/js/Pages/Dashboard/ContactInfo/Edit.vue index cc2b544..b6d233f 100644 --- a/resources/js/Pages/Dashboard/ContactInfo.vue +++ b/resources/js/Pages/Dashboard/ContactInfo/Edit.vue @@ -14,13 +14,12 @@ const props = defineProps({ }) const form = useForm({ - email: props.contactInfo.email, - github_handle: props.contactInfo.github_handle, - alternative_channel: props.contactInfo.alternative_channel, + label: props.contactInfo.label, + link: props.contactInfo.link, }) -function updateContact() { - form.patch(`/dashboard/contact-info`) +function updateContactInfo() { + form.patch(`/dashboard/contact-infos/${props.contactInfo.id}`) } @@ -29,33 +28,26 @@ function updateContact() {

Edycja form kontaktu

-
+
- - E-mail uczelniany + + Etykieta - - + + - - Github link + + Link do kontaktu - - - - - - Alternatywny kontakt - - - + +
- + Cofnij diff --git a/resources/js/Pages/Dashboard/ContactInfo/Index.vue b/resources/js/Pages/Dashboard/ContactInfo/Index.vue new file mode 100644 index 0000000..d1ace9f --- /dev/null +++ b/resources/js/Pages/Dashboard/ContactInfo/Index.vue @@ -0,0 +1,111 @@ + + + diff --git a/resources/js/Shared/Forms/ImageUploader.vue b/resources/js/Shared/Forms/ImageUploader.vue new file mode 100644 index 0000000..d547d54 --- /dev/null +++ b/resources/js/Shared/Forms/ImageUploader.vue @@ -0,0 +1,118 @@ + + + diff --git a/routes/web.php b/routes/web.php index ff058e4..fdcb8be 100644 --- a/routes/web.php +++ b/routes/web.php @@ -2,7 +2,7 @@ declare(strict_types=1); -use App\Http\Controllers\ContactInfoController; +use App\Http\Controllers\Dashboard\ContactInfoController; use App\Http\Controllers\Dashboard\DashboardController; use App\Http\Controllers\Dashboard\LogoutController; use App\Http\Controllers\Dashboard\PasswordUpdateController; @@ -15,10 +15,6 @@ Route::get("/", HomeController::class)->name("main"); Route::get("/aktualnosci", NewsController::class); -Route::prefix("dashboard")->group(function (): void { - Route::get("/", DashboardController::class); - Route::get("/contact-info", [ContactInfoController::class, "edit"])->name("contactInfo.edit"); - Route::patch("/contact-info", [ContactInfoController::class, "update"])->name("contactInfo.update"); Route::middleware("guest")->group(function (): void { Route::get("/login", [LoginController::class, "create"])->name("login"); Route::post("/login", [LoginController::class, "store"]); @@ -26,9 +22,17 @@ Route::middleware("auth")->prefix("dashboard")->group(function (): void { Route::get("/", DashboardController::class)->name("dashboard"); + Route::post("/logout", LogoutController::class); Route::get("/password", [PasswordUpdateController::class, "edit"])->name("password.edit"); Route::patch("/password", [PasswordUpdateController::class, "update"])->name("password.update"); - Route::post("/logout", LogoutController::class); + Route::controller(ContactInfoController::class)->group(function (): void { + Route::get("/contact-infos", "index")->name("contactInfo.index"); + Route::get("/contact-infos/create", "create")->name("contactInfo.create"); + Route::post("/contact-infos", "store")->name("contactInfo.store"); + Route::get("/contact-infos/{contact_info}/edit", "edit")->name("contactInfo.edit"); + Route::patch("/contact-infos/{contact_info}", "update")->name("contactInfo.update"); + Route::delete("/contact-infos/{contact_info}", "destroy")->name("contactInfo.destroy"); + }); Route::controller(StudentController::class)->group(function (): void { Route::get("/students", "index")->name("students.index"); Route::get("/students/create", "create")->name("students.create"); From dcb6bcc27448895ca6a73b3d42a10e22d7231698 Mon Sep 17 00:00:00 2001 From: KarolZygadlo Date: Tue, 26 Sep 2023 20:16:29 +0200 Subject: [PATCH 3/8] #13 - wip, refactor --- .../js/Pages/Dashboard/ContactInfo/Create.vue | 11 -- resources/js/Pages/Public/Login.vue | 8 +- resources/js/Shared/Forms/ImageUploader.vue | 118 ------------------ 3 files changed, 4 insertions(+), 133 deletions(-) delete mode 100644 resources/js/Shared/Forms/ImageUploader.vue diff --git a/resources/js/Pages/Dashboard/ContactInfo/Create.vue b/resources/js/Pages/Dashboard/ContactInfo/Create.vue index d6d9edc..7df5020 100644 --- a/resources/js/Pages/Dashboard/ContactInfo/Create.vue +++ b/resources/js/Pages/Dashboard/ContactInfo/Create.vue @@ -5,7 +5,6 @@ import SubmitButton from '@/Shared/Components/Buttons/SubmitButton.vue' import FormGroup from '@/Shared/Forms/FormGroup.vue' import FormLabel from '@/Shared/Forms/FormLabel.vue' import TextInput from '@/Shared/Forms/TextInput.vue' -import ImageUploader from '@/Shared/Forms/ImageUploader.vue' import SecondaryButton from '@/Shared/Components/Buttons/SecondaryButton.vue' import { useForm } from '@inertiajs/inertia-vue3' import FormError from '@/Shared/Forms/FormError.vue' @@ -42,16 +41,6 @@ function createContactInfo() { - - - Ikona - - - -
diff --git a/resources/js/Pages/Public/Login.vue b/resources/js/Pages/Public/Login.vue index 1365194..b3fa5d2 100644 --- a/resources/js/Pages/Public/Login.vue +++ b/resources/js/Pages/Public/Login.vue @@ -22,14 +22,14 @@ function attemptLogin() {
- +
Email
@@ -52,7 +52,7 @@ function attemptLogin() {
diff --git a/resources/js/Shared/Forms/ImageUploader.vue b/resources/js/Shared/Forms/ImageUploader.vue deleted file mode 100644 index d547d54..0000000 --- a/resources/js/Shared/Forms/ImageUploader.vue +++ /dev/null @@ -1,118 +0,0 @@ - - - From 922fae344a25da5bb4edc8b698da7c0eb561cca3 Mon Sep 17 00:00:00 2001 From: KarolZygadlo Date: Wed, 27 Sep 2023 17:25:03 +0200 Subject: [PATCH 4/8] #13 - wip, working on icons --- .../2023_09_23_135710_create_contact_infos_table.php | 1 + resources/js/Shared/Icons/At-symbol.vue | 6 ++++++ resources/js/Shared/Icons/Envelope.vue | 5 +++++ resources/js/Shared/Icons/Exclamation.vue | 5 +++++ resources/js/Shared/Icons/Github.vue | 7 +++++++ resources/js/Shared/Icons/Information.vue | 5 +++++ resources/js/Shared/Icons/Linkedin.vue | 8 ++++++++ resources/js/Shared/Icons/Slack.vue | 5 +++++ 8 files changed, 42 insertions(+) create mode 100644 resources/js/Shared/Icons/At-symbol.vue create mode 100644 resources/js/Shared/Icons/Envelope.vue create mode 100644 resources/js/Shared/Icons/Exclamation.vue create mode 100644 resources/js/Shared/Icons/Github.vue create mode 100644 resources/js/Shared/Icons/Information.vue create mode 100644 resources/js/Shared/Icons/Linkedin.vue create mode 100644 resources/js/Shared/Icons/Slack.vue diff --git a/database/migrations/2023_09_23_135710_create_contact_infos_table.php b/database/migrations/2023_09_23_135710_create_contact_infos_table.php index d49def4..a75a8c8 100644 --- a/database/migrations/2023_09_23_135710_create_contact_infos_table.php +++ b/database/migrations/2023_09_23_135710_create_contact_infos_table.php @@ -13,6 +13,7 @@ public function up(): void $table->ulid("id")->primary(); $table->string("label"); $table->string("link"); + $table->string("icon"); $table->timestamps(); }); } diff --git a/resources/js/Shared/Icons/At-symbol.vue b/resources/js/Shared/Icons/At-symbol.vue new file mode 100644 index 0000000..524f646 --- /dev/null +++ b/resources/js/Shared/Icons/At-symbol.vue @@ -0,0 +1,6 @@ + + diff --git a/resources/js/Shared/Icons/Envelope.vue b/resources/js/Shared/Icons/Envelope.vue new file mode 100644 index 0000000..da206cc --- /dev/null +++ b/resources/js/Shared/Icons/Envelope.vue @@ -0,0 +1,5 @@ + diff --git a/resources/js/Shared/Icons/Exclamation.vue b/resources/js/Shared/Icons/Exclamation.vue new file mode 100644 index 0000000..102480c --- /dev/null +++ b/resources/js/Shared/Icons/Exclamation.vue @@ -0,0 +1,5 @@ + diff --git a/resources/js/Shared/Icons/Github.vue b/resources/js/Shared/Icons/Github.vue new file mode 100644 index 0000000..97b6304 --- /dev/null +++ b/resources/js/Shared/Icons/Github.vue @@ -0,0 +1,7 @@ + diff --git a/resources/js/Shared/Icons/Information.vue b/resources/js/Shared/Icons/Information.vue new file mode 100644 index 0000000..1668a34 --- /dev/null +++ b/resources/js/Shared/Icons/Information.vue @@ -0,0 +1,5 @@ + diff --git a/resources/js/Shared/Icons/Linkedin.vue b/resources/js/Shared/Icons/Linkedin.vue new file mode 100644 index 0000000..e54fd63 --- /dev/null +++ b/resources/js/Shared/Icons/Linkedin.vue @@ -0,0 +1,8 @@ + diff --git a/resources/js/Shared/Icons/Slack.vue b/resources/js/Shared/Icons/Slack.vue new file mode 100644 index 0000000..77ca2e0 --- /dev/null +++ b/resources/js/Shared/Icons/Slack.vue @@ -0,0 +1,5 @@ + From c7931c01246223c8d450dcb1a26f255fba384bfe Mon Sep 17 00:00:00 2001 From: KarolZygadlo Date: Wed, 27 Sep 2023 21:34:35 +0200 Subject: [PATCH 5/8] #13 - wip, refactored views to match new changes in forms --- app/Enums/Icons.php | 16 +++ .../Dashboard/ContactInfoController.php | 11 +- app/Http/Requests/ContactInfoRequest.php | 2 +- ...9_23_135710_create_contact_infos_table.php | 4 +- .../js/Pages/Dashboard/ContactInfo/Create.vue | 82 ++++++----- .../js/Pages/Dashboard/ContactInfo/Edit.vue | 81 ++++++----- .../js/Pages/Dashboard/ContactInfo/Index.vue | 133 ++++++++---------- 7 files changed, 175 insertions(+), 154 deletions(-) create mode 100644 app/Enums/Icons.php diff --git a/app/Enums/Icons.php b/app/Enums/Icons.php new file mode 100644 index 0000000..cc6d376 --- /dev/null +++ b/app/Enums/Icons.php @@ -0,0 +1,16 @@ +query("search"); $contactInfos = ContactInfo::query() - ->when( - $searchText !== null, - fn(Builder $query): Builder => $query - ->where("label", "ILIKE", "%$searchText%") - ->orWhere("link", "ILIKE", "%$searchText%") - ) - ->paginate() - ->withQueryString(); + ->orderByDesc("created_at") + ->get(); return inertia("Dashboard/ContactInfo/Index", [ "contactInfos" => $contactInfos, diff --git a/app/Http/Requests/ContactInfoRequest.php b/app/Http/Requests/ContactInfoRequest.php index 8fd9286..6dd0cb8 100644 --- a/app/Http/Requests/ContactInfoRequest.php +++ b/app/Http/Requests/ContactInfoRequest.php @@ -12,7 +12,7 @@ public function rules(): array { return [ "label" => ["required", "string", "max:255"], - "link" => ["required", "url", "max:255"], + "identifier" => ["required", "string", "max:255"], ]; } } diff --git a/database/migrations/2023_09_23_135710_create_contact_infos_table.php b/database/migrations/2023_09_23_135710_create_contact_infos_table.php index a75a8c8..69e3d38 100644 --- a/database/migrations/2023_09_23_135710_create_contact_infos_table.php +++ b/database/migrations/2023_09_23_135710_create_contact_infos_table.php @@ -12,8 +12,8 @@ public function up(): void Schema::create("contact_infos", function (Blueprint $table): void { $table->ulid("id")->primary(); $table->string("label"); - $table->string("link"); - $table->string("icon"); + $table->string("identifier"); + $table->string("icon")->nullable(); $table->timestamps(); }); } diff --git a/resources/js/Pages/Dashboard/ContactInfo/Create.vue b/resources/js/Pages/Dashboard/ContactInfo/Create.vue index 7df5020..5481fe3 100644 --- a/resources/js/Pages/Dashboard/ContactInfo/Create.vue +++ b/resources/js/Pages/Dashboard/ContactInfo/Create.vue @@ -5,13 +5,15 @@ import SubmitButton from '@/Shared/Components/Buttons/SubmitButton.vue' import FormGroup from '@/Shared/Forms/FormGroup.vue' import FormLabel from '@/Shared/Forms/FormLabel.vue' import TextInput from '@/Shared/Forms/TextInput.vue' -import SecondaryButton from '@/Shared/Components/Buttons/SecondaryButton.vue' import { useForm } from '@inertiajs/inertia-vue3' import FormError from '@/Shared/Forms/FormError.vue' +import ManagementHeader from '@/Shared/Components/ManagementHeader.vue' +import ManagementHeaderItem from '@/Shared/Components/ManagementHeaderItem.vue' const form = useForm({ label: '', - link: '', + identifier: '', + icon: '' }) function createContactInfo() { @@ -21,36 +23,50 @@ function createContactInfo() { + diff --git a/resources/js/Pages/Dashboard/ContactInfo/Edit.vue b/resources/js/Pages/Dashboard/ContactInfo/Edit.vue index b6d233f..79d08ff 100644 --- a/resources/js/Pages/Dashboard/ContactInfo/Edit.vue +++ b/resources/js/Pages/Dashboard/ContactInfo/Edit.vue @@ -5,9 +5,10 @@ import SubmitButton from '@/Shared/Components/Buttons/SubmitButton.vue' import FormGroup from '@/Shared/Forms/FormGroup.vue' import FormLabel from '@/Shared/Forms/FormLabel.vue' import TextInput from '@/Shared/Forms/TextInput.vue' -import SecondaryButton from '@/Shared/Components/Buttons/SecondaryButton.vue' import { useForm } from '@inertiajs/inertia-vue3' import FormError from '@/Shared/Forms/FormError.vue' +import ManagementHeader from '@/Shared/Components/ManagementHeader.vue' +import ManagementHeaderItem from '@/Shared/Components/ManagementHeaderItem.vue' const props = defineProps({ contactInfo: Object, @@ -15,7 +16,7 @@ const props = defineProps({ const form = useForm({ label: props.contactInfo.label, - link: props.contactInfo.link, + identifier: props.contactInfo.identifier, }) function updateContactInfo() { @@ -25,36 +26,50 @@ function updateContactInfo() { + diff --git a/resources/js/Pages/Dashboard/ContactInfo/Index.vue b/resources/js/Pages/Dashboard/ContactInfo/Index.vue index d1ace9f..f222f3f 100644 --- a/resources/js/Pages/Dashboard/ContactInfo/Index.vue +++ b/resources/js/Pages/Dashboard/ContactInfo/Index.vue @@ -8,104 +8,85 @@ import Pagination from '@/Shared/Components/Pagination.vue' import Button from '@/Shared/Components/Buttons/Button.vue' import EmptyState from '@/Shared/Components/EmptyState.vue' import RemoveModal from '@/Shared/Modals/RemoveModal.vue' -import { ref, watch } from 'vue' -import { Inertia } from '@inertiajs/inertia' -import { debounce } from 'lodash' -import TextInput from '@/Shared/Forms/TextInput.vue' -import { useForm } from '@inertiajs/inertia-vue3' +import { ref } from 'vue' import { Cog6ToothIcon, XCircleIcon } from '@heroicons/vue/24/outline' -import ManagementHeader from '../../../Shared/Components/ManagementHeader.vue' - -const props = defineProps({ +import ManagementHeader from '@/Shared/Components/ManagementHeader.vue' +import ManagementHeaderItem from '@/Shared/Components/ManagementHeaderItem.vue' +defineProps({ contactInfos: Object, - search: String, total: Number, lastUpdate: String, }) const showModal = ref(false) const contactInfoToDeleteId = ref(0) -const form = useForm({ - search: props.search, -}) -watch(form, debounce(() => { - Inertia.get('/dashboard/contact-infos', { - search: form.search, - }, { - preserveState: true, - replace: true, - }) -}, 300), { deep: true }) From a59113f8457a91d81464ce388b0a04088deea65e Mon Sep 17 00:00:00 2001 From: KarolZygadlo Date: Tue, 3 Oct 2023 20:00:26 +0200 Subject: [PATCH 6/8] #15 - wip --- .../Dashboard/ContactInfoController.php | 8 +- app/Http/Requests/ContactInfoRequest.php | 3 + composer.json | 3 +- composer.lock | 136 +++++++++++++++++- database/factories/ContactInfoFactory.php | 2 + .../js/Pages/Dashboard/ContactInfo/Create.vue | 12 ++ .../js/Pages/Dashboard/ContactInfo/Edit.vue | 10 ++ resources/js/Shared/Forms/Select.vue | 51 +++++++ tests/Feature/ContactInfoTest.php | 13 +- 9 files changed, 227 insertions(+), 11 deletions(-) create mode 100644 resources/js/Shared/Forms/Select.vue diff --git a/app/Http/Controllers/Dashboard/ContactInfoController.php b/app/Http/Controllers/Dashboard/ContactInfoController.php index 1830697..2400331 100644 --- a/app/Http/Controllers/Dashboard/ContactInfoController.php +++ b/app/Http/Controllers/Dashboard/ContactInfoController.php @@ -4,9 +4,12 @@ namespace App\Http\Controllers\Dashboard; +use App\Enums\Icons; use App\Http\Controllers\Controller; use App\Http\Requests\ContactInfoRequest; use App\Models\ContactInfo; +use Exception; +use Spatie\LaravelOptions\Options; use Illuminate\Database\Eloquent\Builder; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; @@ -29,7 +32,9 @@ public function index(Request $request): Response public function create(): Response { - return inertia("Dashboard/ContactInfo/Create"); + return inertia("Dashboard/ContactInfo/Create", [ + "icons" => Options::forEnum(Icons::class)->toArray(), + ]); } public function store(ContactInfoRequest $request): RedirectResponse @@ -45,6 +50,7 @@ public function edit(ContactInfo $contactInfo): Response { return inertia("Dashboard/ContactInfo/Edit", [ "contactInfo" => $contactInfo, + "icons" => Options::forEnum(Icons::class)->toArray(), ]); } diff --git a/app/Http/Requests/ContactInfoRequest.php b/app/Http/Requests/ContactInfoRequest.php index 6dd0cb8..ea5cff5 100644 --- a/app/Http/Requests/ContactInfoRequest.php +++ b/app/Http/Requests/ContactInfoRequest.php @@ -4,7 +4,9 @@ namespace App\Http\Requests; +use App\Enums\Icons; use Illuminate\Foundation\Http\FormRequest; +use Illuminate\Validation\Rules\Enum; class ContactInfoRequest extends FormRequest { @@ -13,6 +15,7 @@ public function rules(): array return [ "label" => ["required", "string", "max:255"], "identifier" => ["required", "string", "max:255"], + "icon" => ["nullable", new Enum(Icons::class)] ]; } } diff --git a/composer.json b/composer.json index 172f3b6..2c417b3 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,8 @@ "inertiajs/inertia-laravel": "^0.6.9", "laravel/framework": "^10.13.0", "laravel/sanctum": "^3.2.5", - "laravel/tinker": "^2.8.1" + "laravel/tinker": "^2.8.1", + "spatie/laravel-options": "^1.1" }, "require-dev": { "blumilksoftware/codestyle": "^2.3.0", diff --git a/composer.lock b/composer.lock index cf9cfa9..e4f848d 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "b865a4a16c1ed8b4f4b34305e93cdb23", + "content-hash": "2d7fd92cd49323f7916e1e844c468a90", "packages": [ { "name": "brick/math", @@ -3165,6 +3165,138 @@ ], "time": "2023-04-15T23:01:58+00:00" }, + { + "name": "spatie/laravel-options", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/spatie/laravel-options.git", + "reference": "5bed29084853dd97355ea055c017c27614900b2c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/laravel-options/zipball/5bed29084853dd97355ea055c017c27614900b2c", + "reference": "5bed29084853dd97355ea055c017c27614900b2c", + "shasum": "" + }, + "require": { + "illuminate/contracts": "^8.81|^9.0|^10.0", + "php": "^8.1", + "spatie/laravel-package-tools": "^1.9.2" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.8", + "myclabs/php-enum": "^1.6", + "nunomaduro/collision": "^6.0|^5.0", + "nunomaduro/larastan": "^2.0.1|^1.0.3", + "orchestra/testbench": "^7.0|^v6.24.1|^8.0", + "pestphp/pest": "^v1.21.3", + "pestphp/pest-plugin-laravel": "^1.1", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan-deprecation-rules": "^1.0", + "phpstan/phpstan-phpunit": "^1.0", + "phpunit/phpunit": "^9.5", + "spatie/enum": "^3.13", + "spatie/laravel-model-states": "^2.0", + "spatie/laravel-ray": "^1.26" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Spatie\\LaravelOptions\\OptionsServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Spatie\\LaravelOptions\\": "src", + "Spatie\\LaravelOptions\\Database\\Factories\\": "database/factories" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ruben Van Assche", + "email": "ruben@spatie.be", + "role": "Developer" + } + ], + "description": "Create arrays of options from different sources", + "homepage": "https://github.com/spatie/laravel-options", + "keywords": [ + "laravel", + "options", + "spatie" + ], + "support": { + "source": "https://github.com/spatie/laravel-options/tree/1.1.0" + }, + "time": "2023-02-09T15:07:29+00:00" + }, + { + "name": "spatie/laravel-package-tools", + "version": "1.16.1", + "source": { + "type": "git", + "url": "https://github.com/spatie/laravel-package-tools.git", + "reference": "cc7c991555a37f9fa6b814aa03af73f88026a83d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/laravel-package-tools/zipball/cc7c991555a37f9fa6b814aa03af73f88026a83d", + "reference": "cc7c991555a37f9fa6b814aa03af73f88026a83d", + "shasum": "" + }, + "require": { + "illuminate/contracts": "^9.28|^10.0", + "php": "^8.0" + }, + "require-dev": { + "mockery/mockery": "^1.5", + "orchestra/testbench": "^7.7|^8.0", + "pestphp/pest": "^1.22", + "phpunit/phpunit": "^9.5.24", + "spatie/pest-plugin-test-time": "^1.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "Spatie\\LaravelPackageTools\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "role": "Developer" + } + ], + "description": "Tools for creating Laravel packages", + "homepage": "https://github.com/spatie/laravel-package-tools", + "keywords": [ + "laravel-package-tools", + "spatie" + ], + "support": { + "issues": "https://github.com/spatie/laravel-package-tools/issues", + "source": "https://github.com/spatie/laravel-package-tools/tree/1.16.1" + }, + "funding": [ + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2023-08-23T09:04:39+00:00" + }, { "name": "symfony/console", "version": "v6.3.4", @@ -8610,5 +8742,5 @@ "ext-pdo": "*" }, "platform-dev": [], - "plugin-api-version": "2.3.0" + "plugin-api-version": "2.6.0" } diff --git a/database/factories/ContactInfoFactory.php b/database/factories/ContactInfoFactory.php index 5a904f7..aaa1995 100644 --- a/database/factories/ContactInfoFactory.php +++ b/database/factories/ContactInfoFactory.php @@ -4,6 +4,7 @@ namespace Database\Factories; +use App\Enums\Icons; use App\Models\ContactInfo; use Illuminate\Database\Eloquent\Factories\Factory; @@ -17,6 +18,7 @@ public function definition(): array return [ "label" => fake()->domainWord(), "link" => fake()->url(), + "icon" => fake()->randomElement(Icons::class), ]; } } diff --git a/resources/js/Pages/Dashboard/ContactInfo/Create.vue b/resources/js/Pages/Dashboard/ContactInfo/Create.vue index 5481fe3..c5afc1f 100644 --- a/resources/js/Pages/Dashboard/ContactInfo/Create.vue +++ b/resources/js/Pages/Dashboard/ContactInfo/Create.vue @@ -5,11 +5,16 @@ import SubmitButton from '@/Shared/Components/Buttons/SubmitButton.vue' import FormGroup from '@/Shared/Forms/FormGroup.vue' import FormLabel from '@/Shared/Forms/FormLabel.vue' import TextInput from '@/Shared/Forms/TextInput.vue' +import Select from '@/Shared/Forms/Select.vue' import { useForm } from '@inertiajs/inertia-vue3' import FormError from '@/Shared/Forms/FormError.vue' import ManagementHeader from '@/Shared/Components/ManagementHeader.vue' import ManagementHeaderItem from '@/Shared/Components/ManagementHeaderItem.vue' +defineProps({ + icons: Array, +}) + const form = useForm({ label: '', identifier: '', @@ -58,6 +63,13 @@ function createContactInfo() { + + + Ikona + + + +
Zapisz diff --git a/resources/js/Shared/Forms/Select.vue b/resources/js/Shared/Forms/Select.vue new file mode 100644 index 0000000..7ab0ac8 --- /dev/null +++ b/resources/js/Shared/Forms/Select.vue @@ -0,0 +1,51 @@ + + + diff --git a/tests/Feature/ContactInfoTest.php b/tests/Feature/ContactInfoTest.php index 48cc495..19c73dc 100644 --- a/tests/Feature/ContactInfoTest.php +++ b/tests/Feature/ContactInfoTest.php @@ -2,6 +2,7 @@ namespace Tests\Feature; +use App\Enums\Icons; use App\Models\ContactInfo; use App\Models\User; use Illuminate\Foundation\Testing\RefreshDatabase; @@ -19,18 +20,16 @@ protected function setUp(): void parent::setUp(); $this->user = User::factory()->create(); - $this->contactInfo = ContactInfo::factory()->create([ - "github_handle" => null, - "alternative_channel" => null - ]); + $this->contactInfo = ContactInfo::factory()->create(); + $this->actingAs($this->user); } public function testContactInfoCanBeUpdated(): void { $this->assertDatabaseMissing("contact_infos", [ - "email" => "user@collegiumwitelona.pl", - "github_handle" => "https://test@test.pl", - "alternative_channel" => "https://test@test.pl", + "label" => "user@collegiumwitelona.pl", + "link" => "https://test@test.pl", + "icon" => Icons::Envelope->value, ]); $this->actingAs($this->user)->patch("/dashboard/contact-info", [ From 36e95c021c5e58f2817ef983ff7f97c4164aa41f Mon Sep 17 00:00:00 2001 From: KarolZygadlo Date: Tue, 3 Oct 2023 20:59:32 +0200 Subject: [PATCH 7/8] #13 - finished working on basic version, added test --- .../Dashboard/ContactInfoController.php | 4 +- app/Http/Requests/ContactInfoRequest.php | 2 +- database/factories/ContactInfoFactory.php | 2 +- .../js/Pages/Dashboard/ContactInfo/Create.vue | 2 +- resources/js/Pages/Public/Login.vue | 6 +- resources/js/Shared/Icons/At-symbol.vue | 2 +- resources/js/Shared/Icons/Envelope.vue | 2 +- resources/js/Shared/Icons/Exclamation.vue | 2 +- resources/js/Shared/Icons/Github.vue | 8 +- resources/js/Shared/Icons/Information.vue | 2 +- resources/js/Shared/Icons/Linkedin.vue | 8 +- resources/js/Shared/Icons/Slack.vue | 2 +- tests/Feature/ContactInfoTest.php | 86 ++++++++++++------- 13 files changed, 77 insertions(+), 51 deletions(-) diff --git a/app/Http/Controllers/Dashboard/ContactInfoController.php b/app/Http/Controllers/Dashboard/ContactInfoController.php index 2400331..83b3e6c 100644 --- a/app/Http/Controllers/Dashboard/ContactInfoController.php +++ b/app/Http/Controllers/Dashboard/ContactInfoController.php @@ -8,12 +8,10 @@ use App\Http\Controllers\Controller; use App\Http\Requests\ContactInfoRequest; use App\Models\ContactInfo; -use Exception; -use Spatie\LaravelOptions\Options; -use Illuminate\Database\Eloquent\Builder; use Illuminate\Http\RedirectResponse; use Illuminate\Http\Request; use Inertia\Response; +use Spatie\LaravelOptions\Options; class ContactInfoController extends Controller { diff --git a/app/Http/Requests/ContactInfoRequest.php b/app/Http/Requests/ContactInfoRequest.php index ea5cff5..3313316 100644 --- a/app/Http/Requests/ContactInfoRequest.php +++ b/app/Http/Requests/ContactInfoRequest.php @@ -15,7 +15,7 @@ public function rules(): array return [ "label" => ["required", "string", "max:255"], "identifier" => ["required", "string", "max:255"], - "icon" => ["nullable", new Enum(Icons::class)] + "icon" => ["required", new Enum(Icons::class)], ]; } } diff --git a/database/factories/ContactInfoFactory.php b/database/factories/ContactInfoFactory.php index aaa1995..f981096 100644 --- a/database/factories/ContactInfoFactory.php +++ b/database/factories/ContactInfoFactory.php @@ -17,7 +17,7 @@ public function definition(): array { return [ "label" => fake()->domainWord(), - "link" => fake()->url(), + "identifier" => fake()->url(), "icon" => fake()->randomElement(Icons::class), ]; } diff --git a/resources/js/Pages/Dashboard/ContactInfo/Create.vue b/resources/js/Pages/Dashboard/ContactInfo/Create.vue index c5afc1f..4440422 100644 --- a/resources/js/Pages/Dashboard/ContactInfo/Create.vue +++ b/resources/js/Pages/Dashboard/ContactInfo/Create.vue @@ -18,7 +18,7 @@ defineProps({ const form = useForm({ label: '', identifier: '', - icon: '' + icon: '', }) function createContactInfo() { diff --git a/resources/js/Pages/Public/Login.vue b/resources/js/Pages/Public/Login.vue index b3fa5d2..eb831e0 100644 --- a/resources/js/Pages/Public/Login.vue +++ b/resources/js/Pages/Public/Login.vue @@ -29,7 +29,7 @@ function attemptLogin() {
Email
@@ -52,7 +52,7 @@ function attemptLogin() {
diff --git a/resources/js/Shared/Icons/At-symbol.vue b/resources/js/Shared/Icons/At-symbol.vue index 524f646..818a60f 100644 --- a/resources/js/Shared/Icons/At-symbol.vue +++ b/resources/js/Shared/Icons/At-symbol.vue @@ -1,5 +1,5 @@ diff --git a/resources/js/Shared/Icons/Envelope.vue b/resources/js/Shared/Icons/Envelope.vue index da206cc..30f404d 100644 --- a/resources/js/Shared/Icons/Envelope.vue +++ b/resources/js/Shared/Icons/Envelope.vue @@ -1,5 +1,5 @@ diff --git a/resources/js/Shared/Icons/Exclamation.vue b/resources/js/Shared/Icons/Exclamation.vue index 102480c..558a4df 100644 --- a/resources/js/Shared/Icons/Exclamation.vue +++ b/resources/js/Shared/Icons/Exclamation.vue @@ -1,5 +1,5 @@ diff --git a/resources/js/Shared/Icons/Github.vue b/resources/js/Shared/Icons/Github.vue index 97b6304..7770f22 100644 --- a/resources/js/Shared/Icons/Github.vue +++ b/resources/js/Shared/Icons/Github.vue @@ -1,7 +1,7 @@ diff --git a/resources/js/Shared/Icons/Information.vue b/resources/js/Shared/Icons/Information.vue index 1668a34..45abc38 100644 --- a/resources/js/Shared/Icons/Information.vue +++ b/resources/js/Shared/Icons/Information.vue @@ -1,5 +1,5 @@ diff --git a/resources/js/Shared/Icons/Linkedin.vue b/resources/js/Shared/Icons/Linkedin.vue index e54fd63..0e261c5 100644 --- a/resources/js/Shared/Icons/Linkedin.vue +++ b/resources/js/Shared/Icons/Linkedin.vue @@ -1,8 +1,8 @@ diff --git a/resources/js/Shared/Icons/Slack.vue b/resources/js/Shared/Icons/Slack.vue index 77ca2e0..69009df 100644 --- a/resources/js/Shared/Icons/Slack.vue +++ b/resources/js/Shared/Icons/Slack.vue @@ -1,5 +1,5 @@ diff --git a/tests/Feature/ContactInfoTest.php b/tests/Feature/ContactInfoTest.php index 19c73dc..96127d0 100644 --- a/tests/Feature/ContactInfoTest.php +++ b/tests/Feature/ContactInfoTest.php @@ -1,70 +1,98 @@ user = User::factory()->create(); - $this->contactInfo = ContactInfo::factory()->create(); $this->actingAs($this->user); } + public function testContactInfoCanBeCreated(): void + { + $this->assertDatabaseCount("contact_infos", 0); + + $this->post("/dashboard/contact-infos", [ + "label" => "karol.zygadlo@collegiumwitelona.pl", + "identifier" => "mailto:karol.zygadlo@collegiumwitelona.pl", + "icon" => Icons::AtSymbol->value, + ])->assertSessionHasNoErrors(); + + $this->assertDatabaseCount("contact_infos", 1); + } + public function testContactInfoCanBeUpdated(): void { + $contactInfo = ContactInfo::factory()->create(); + $this->assertDatabaseMissing("contact_infos", [ - "label" => "user@collegiumwitelona.pl", - "link" => "https://test@test.pl", - "icon" => Icons::Envelope->value, + "label" => "karol.zygadlo@collegiumwitelona.pl", + "identifier" => "mailto:karol.zygadlo@collegiumwitelona.pl", + "icon" => Icons::AtSymbol->value, ]); - $this->actingAs($this->user)->patch("/dashboard/contact-info", [ - "email" => "user@collegiumwitelona.pl", - "github_handle" => "https://test@test.pl", - "alternative_channel" => "https://test@test.pl", + $this->patch("/dashboard/contact-infos/{$contactInfo->id}", [ + "label" => "karol.zygadlo@collegiumwitelona.pl", + "identifier" => "mailto:karol.zygadlo@collegiumwitelona.pl", + "icon" => Icons::AtSymbol->value, ])->assertSessionHasNoErrors(); $this->assertDatabaseHas("contact_infos", [ - "email" => "user@collegiumwitelona.pl", - "github_handle" => "https://test@test.pl", - "alternative_channel" => "https://test@test.pl", + "label" => "karol.zygadlo@collegiumwitelona.pl", + "identifier" => "mailto:karol.zygadlo@collegiumwitelona.pl", + "icon" => "at-symbol", ]); } - public function testContactInfoCanBeUpdatedWithOnlyEmail(): void + public function testContactInfoCannotBeCreatedWithInvalidData(): void { - $this->actingAs($this->user)->patch("/dashboard/contact-info", [ - "email" => "user@collegiumwitelona.pl", - ])->assertSessionHasNoErrors(); - - $this->assertDatabaseHas("contact_infos", [ - "email" => "user@collegiumwitelona.pl", - "github_handle" => null, - "alternative_channel" => null, + $this->post("/dashboard/contact-infos", [ + "label" => Str::random(256), + "identifier" => Str::random(256), + "icon" => "test", + ])->assertSessionHasErrors([ + "label", + "identifier", + "icon", ]); + + $this->assertDatabaseCount("contact_infos", 0); } - public function testContactInfoCannotBeUpdatedWithoutEmail(): void + public function testContactInfoCannotBeCreatedWithoutData(): void { - $this->actingAs($this->user)->patch("/dashboard/contact-info", [ - "email" => null, - "github_handle" => "https://test@test.pl", - "alternative_channel" => "https://test@test.pl", - ])->assertSessionHasErrors("email"); + $this->post("/dashboard/contact-infos", [ + ])->assertSessionHasErrors([ + "label", + "identifier", + "icon", + ]); + + $this->assertDatabaseCount("contact_infos", 0); } + public function testContactInfoCanBeDeleted(): void + { + $contactInfo = ContactInfo::factory()->create(); + $this->assertDatabaseCount("contact_infos", 1); + + $this->delete("/dashboard/contact-infos/$contactInfo->id"); + + $this->assertDatabaseCount("contact_infos", 0); + } } From c227efe5e99331f87e566f4e1d2a24901450fa48 Mon Sep 17 00:00:00 2001 From: KarolZygadlo Date: Tue, 3 Oct 2023 21:09:52 +0200 Subject: [PATCH 8/8] #13 - added spatie/laravel-options --- composer.json | 1 + composer.lock | 134 +++++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 134 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 42b536f..036cc2d 100644 --- a/composer.json +++ b/composer.json @@ -12,6 +12,7 @@ "laravel/framework": "^10.13.0", "laravel/sanctum": "^3.2.5", "laravel/tinker": "^2.8.1", + "spatie/laravel-options": "^1.1", "stevebauman/purify": "^6.0" }, "require-dev": { diff --git a/composer.lock b/composer.lock index e668603..1cabccc 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "fcf62ce422bb2cb212a713e68f7df8f8", + "content-hash": "78a9206548f38467774be801ed237211", "packages": [ { "name": "brick/math", @@ -3238,6 +3238,138 @@ ], "time": "2023-04-15T23:01:58+00:00" }, + { + "name": "spatie/laravel-options", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/spatie/laravel-options.git", + "reference": "5bed29084853dd97355ea055c017c27614900b2c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/laravel-options/zipball/5bed29084853dd97355ea055c017c27614900b2c", + "reference": "5bed29084853dd97355ea055c017c27614900b2c", + "shasum": "" + }, + "require": { + "illuminate/contracts": "^8.81|^9.0|^10.0", + "php": "^8.1", + "spatie/laravel-package-tools": "^1.9.2" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.8", + "myclabs/php-enum": "^1.6", + "nunomaduro/collision": "^6.0|^5.0", + "nunomaduro/larastan": "^2.0.1|^1.0.3", + "orchestra/testbench": "^7.0|^v6.24.1|^8.0", + "pestphp/pest": "^v1.21.3", + "pestphp/pest-plugin-laravel": "^1.1", + "phpstan/extension-installer": "^1.1", + "phpstan/phpstan-deprecation-rules": "^1.0", + "phpstan/phpstan-phpunit": "^1.0", + "phpunit/phpunit": "^9.5", + "spatie/enum": "^3.13", + "spatie/laravel-model-states": "^2.0", + "spatie/laravel-ray": "^1.26" + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Spatie\\LaravelOptions\\OptionsServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Spatie\\LaravelOptions\\": "src", + "Spatie\\LaravelOptions\\Database\\Factories\\": "database/factories" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ruben Van Assche", + "email": "ruben@spatie.be", + "role": "Developer" + } + ], + "description": "Create arrays of options from different sources", + "homepage": "https://github.com/spatie/laravel-options", + "keywords": [ + "laravel", + "options", + "spatie" + ], + "support": { + "source": "https://github.com/spatie/laravel-options/tree/1.1.0" + }, + "time": "2023-02-09T15:07:29+00:00" + }, + { + "name": "spatie/laravel-package-tools", + "version": "1.16.1", + "source": { + "type": "git", + "url": "https://github.com/spatie/laravel-package-tools.git", + "reference": "cc7c991555a37f9fa6b814aa03af73f88026a83d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/spatie/laravel-package-tools/zipball/cc7c991555a37f9fa6b814aa03af73f88026a83d", + "reference": "cc7c991555a37f9fa6b814aa03af73f88026a83d", + "shasum": "" + }, + "require": { + "illuminate/contracts": "^9.28|^10.0", + "php": "^8.0" + }, + "require-dev": { + "mockery/mockery": "^1.5", + "orchestra/testbench": "^7.7|^8.0", + "pestphp/pest": "^1.22", + "phpunit/phpunit": "^9.5.24", + "spatie/pest-plugin-test-time": "^1.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "Spatie\\LaravelPackageTools\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Freek Van der Herten", + "email": "freek@spatie.be", + "role": "Developer" + } + ], + "description": "Tools for creating Laravel packages", + "homepage": "https://github.com/spatie/laravel-package-tools", + "keywords": [ + "laravel-package-tools", + "spatie" + ], + "support": { + "issues": "https://github.com/spatie/laravel-package-tools/issues", + "source": "https://github.com/spatie/laravel-package-tools/tree/1.16.1" + }, + "funding": [ + { + "url": "https://github.com/spatie", + "type": "github" + } + ], + "time": "2023-08-23T09:04:39+00:00" + }, { "name": "stevebauman/purify", "version": "v6.0.2",