From 2f34f5054b603b92577368792f6e78ac6b46e492 Mon Sep 17 00:00:00 2001 From: Kamil Piech Date: Wed, 28 Aug 2024 08:57:57 +0200 Subject: [PATCH] #28 - contact page (#136) * #28 - feat: added contact page * #28 - feat: added empty state * #28 - fix: code review fixes --- app/DTOs/ContactInfoData.php | 23 +++++++ app/Enums/Icons.php | 16 ----- .../Dashboard/ContactInfoController.php | 7 +- .../Controllers/Public/ContactController.php | 30 ++++++++ app/Http/Requests/ContactInfoRequest.php | 3 - app/Models/ContactInfo.php | 5 +- database/factories/ContactInfoFactory.php | 2 - ...ve_icon_field_from_contact_infos_table.php | 23 +++++++ .../js/Pages/Dashboard/ContactInfo/Create.vue | 8 --- .../js/Pages/Dashboard/ContactInfo/Edit.vue | 8 --- resources/js/Pages/Public/Contact.vue | 69 +++++++++++++++++++ .../js/Shared/Components/ContactItem.vue | 29 ++++++++ routes/web.php | 2 + tests/Feature/ContactInfoTest.php | 8 --- 14 files changed, 179 insertions(+), 54 deletions(-) create mode 100644 app/DTOs/ContactInfoData.php delete mode 100644 app/Enums/Icons.php create mode 100644 app/Http/Controllers/Public/ContactController.php create mode 100644 database/migrations/2024_08_28_073139_remove_icon_field_from_contact_infos_table.php create mode 100644 resources/js/Pages/Public/Contact.vue create mode 100644 resources/js/Shared/Components/ContactItem.vue diff --git a/app/DTOs/ContactInfoData.php b/app/DTOs/ContactInfoData.php new file mode 100644 index 0000000..4b2ba11 --- /dev/null +++ b/app/DTOs/ContactInfoData.php @@ -0,0 +1,23 @@ +label, + identifier: $contactInfo->identifier, + ); + } +} diff --git a/app/Enums/Icons.php b/app/Enums/Icons.php deleted file mode 100644 index feb856c..0000000 --- a/app/Enums/Icons.php +++ /dev/null @@ -1,16 +0,0 @@ - Options::forEnum(Icons::class)->toArray(), - ]); + return inertia("Dashboard/ContactInfo/Create"); } public function store(ContactInfoRequest $request): RedirectResponse @@ -47,7 +43,6 @@ public function edit(ContactInfo $contactInfo): Response { return inertia("Dashboard/ContactInfo/Edit", [ "contactInfo" => $contactInfo, - "icons" => Options::forEnum(Icons::class)->toArray(), ]); } diff --git a/app/Http/Controllers/Public/ContactController.php b/app/Http/Controllers/Public/ContactController.php new file mode 100644 index 0000000..6183527 --- /dev/null +++ b/app/Http/Controllers/Public/ContactController.php @@ -0,0 +1,30 @@ +first(); + $contactInfos = ContactInfo::query()->get(); + + return inertia("Public/Contact", [ + "title" => $settings->teacher_titles, + "name" => $settings->teacher_name, + "email" => $settings->teacher_email, + "department" => $settings->department_name, + "university" => $settings->university_name, + "universityLogo" => asset("cwup-full.png"), + "contactInfos" => $contactInfos->map(fn(ContactInfo $contactInfo): ContactInfoData => ContactInfoData::fromModel($contactInfo)), + ]); + } +} diff --git a/app/Http/Requests/ContactInfoRequest.php b/app/Http/Requests/ContactInfoRequest.php index d70963f..f59510b 100644 --- a/app/Http/Requests/ContactInfoRequest.php +++ b/app/Http/Requests/ContactInfoRequest.php @@ -5,8 +5,6 @@ namespace Keating\Http\Requests; use Illuminate\Foundation\Http\FormRequest; -use Illuminate\Validation\Rules\Enum; -use Keating\Enums\Icons; class ContactInfoRequest extends FormRequest { @@ -15,7 +13,6 @@ public function rules(): array return [ "label" => ["required", "string", "max:255"], "identifier" => ["required", "string", "max:255"], - "icon" => ["required", new Enum(Icons::class)], ]; } } diff --git a/app/Models/ContactInfo.php b/app/Models/ContactInfo.php index 0796508..3e9147c 100644 --- a/app/Models/ContactInfo.php +++ b/app/Models/ContactInfo.php @@ -11,9 +11,8 @@ /** * @property string $id - * @property string $email - * @property string $github_handle - * @property string $alternative_channel + * @property string $label + * @property string $identifier * @property Carbon $created_at * @property Carbon $updated_at */ diff --git a/database/factories/ContactInfoFactory.php b/database/factories/ContactInfoFactory.php index 6b8cf6a..2cdd47c 100644 --- a/database/factories/ContactInfoFactory.php +++ b/database/factories/ContactInfoFactory.php @@ -5,7 +5,6 @@ namespace Database\Factories; use Illuminate\Database\Eloquent\Factories\Factory; -use Keating\Enums\Icons; use Keating\Models\ContactInfo; /** @@ -18,7 +17,6 @@ public function definition(): array return [ "label" => fake()->domainWord(), "identifier" => fake()->url(), - "icon" => fake()->randomElement(Icons::class), ]; } } diff --git a/database/migrations/2024_08_28_073139_remove_icon_field_from_contact_infos_table.php b/database/migrations/2024_08_28_073139_remove_icon_field_from_contact_infos_table.php new file mode 100644 index 0000000..4b76fe2 --- /dev/null +++ b/database/migrations/2024_08_28_073139_remove_icon_field_from_contact_infos_table.php @@ -0,0 +1,23 @@ +dropColumn("icon"); + }); + } + + public function down(): void + { + Schema::table("contact_infos", function (Blueprint $table): void { + $table->string("icon")->nullable(); + }); + } +}; diff --git a/resources/js/Pages/Dashboard/ContactInfo/Create.vue b/resources/js/Pages/Dashboard/ContactInfo/Create.vue index 4440422..39550a1 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 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' @@ -63,13 +62,6 @@ function createContactInfo() { - - - Ikona - - - -
Zapisz diff --git a/resources/js/Pages/Public/Contact.vue b/resources/js/Pages/Public/Contact.vue new file mode 100644 index 0000000..762ba99 --- /dev/null +++ b/resources/js/Pages/Public/Contact.vue @@ -0,0 +1,69 @@ + + + diff --git a/resources/js/Shared/Components/ContactItem.vue b/resources/js/Shared/Components/ContactItem.vue new file mode 100644 index 0000000..caccc0b --- /dev/null +++ b/resources/js/Shared/Components/ContactItem.vue @@ -0,0 +1,29 @@ + + + diff --git a/routes/web.php b/routes/web.php index e167247..736d15e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -20,6 +20,7 @@ use Keating\Http\Controllers\Dashboard\SemesterController; use Keating\Http\Controllers\Dashboard\SettingController; use Keating\Http\Controllers\Dashboard\StudentController; +use Keating\Http\Controllers\Public\ContactController; use Keating\Http\Controllers\Public\CourseController as PublicCourseController; use Keating\Http\Controllers\Public\GradeController as PublicGradeController; use Keating\Http\Controllers\Public\HomeController; @@ -32,6 +33,7 @@ Route::get("/oceny/{semester?}/{course?}/{group?}/{index?}", PublicGradeController::class); Route::get("/kursy", [PublicCourseController::class, "index"]); Route::get("/kursy/{slug}", [PublicCourseController::class, "get"]); +Route::get("/kontakt", ContactController::class); Route::middleware("guest")->group(function (): void { Route::get("/login", [LoginController::class, "create"])->name("login"); diff --git a/tests/Feature/ContactInfoTest.php b/tests/Feature/ContactInfoTest.php index a1b8108..5028236 100644 --- a/tests/Feature/ContactInfoTest.php +++ b/tests/Feature/ContactInfoTest.php @@ -6,7 +6,6 @@ use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Str; -use Keating\Enums\Icons; use Keating\Models\ContactInfo; use Keating\Models\User; use Tests\TestCase; @@ -30,7 +29,6 @@ public function testContactInfoCanBeCreated(): void $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); @@ -43,19 +41,16 @@ public function testContactInfoCanBeUpdated(): void $this->assertDatabaseMissing("contact_infos", [ "label" => "karol.zygadlo@collegiumwitelona.pl", "identifier" => "mailto:karol.zygadlo@collegiumwitelona.pl", - "icon" => Icons::AtSymbol->value, ]); $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", [ "label" => "karol.zygadlo@collegiumwitelona.pl", "identifier" => "mailto:karol.zygadlo@collegiumwitelona.pl", - "icon" => "at-symbol", ]); } @@ -64,11 +59,9 @@ public function testContactInfoCannotBeCreatedWithInvalidData(): void $this->post("/dashboard/contact-infos", [ "label" => Str::random(256), "identifier" => Str::random(256), - "icon" => "test", ])->assertSessionHasErrors([ "label", "identifier", - "icon", ]); $this->assertDatabaseCount("contact_infos", 0); @@ -79,7 +72,6 @@ public function testContactInfoCannotBeCreatedWithoutData(): void $this->post("/dashboard/contact-infos", [])->assertSessionHasErrors([ "label", "identifier", - "icon", ]); $this->assertDatabaseCount("contact_infos", 0);