From 30ed91f52314d7d86d36426306dbf7a3b5fac7a5 Mon Sep 17 00:00:00 2001 From: Kamil Date: Tue, 27 Aug 2024 13:34:26 +0200 Subject: [PATCH 1/3] #28 - feat: added contact page --- app/DTOs/ContactInfoData.php | 23 +++++++ .../Controllers/Public/ContactController.php | 30 +++++++++ app/Models/ContactInfo.php | 7 ++- resources/js/Pages/Public/Contact.vue | 61 +++++++++++++++++++ .../js/Shared/Components/ContactItem.vue | 29 +++++++++ routes/web.php | 2 + 6 files changed, 149 insertions(+), 3 deletions(-) create mode 100644 app/DTOs/ContactInfoData.php create mode 100644 app/Http/Controllers/Public/ContactController.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 00000000..4b2ba111 --- /dev/null +++ b/app/DTOs/ContactInfoData.php @@ -0,0 +1,23 @@ +label, + identifier: $contactInfo->identifier, + ); + } +} diff --git a/app/Http/Controllers/Public/ContactController.php b/app/Http/Controllers/Public/ContactController.php new file mode 100644 index 00000000..61835275 --- /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/Models/ContactInfo.php b/app/Models/ContactInfo.php index 0796508a..165c3228 100644 --- a/app/Models/ContactInfo.php +++ b/app/Models/ContactInfo.php @@ -8,12 +8,13 @@ use Illuminate\Database\Eloquent\Concerns\HasUlids; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Keating\Enums\Icons; /** * @property string $id - * @property string $email - * @property string $github_handle - * @property string $alternative_channel + * @property string $label + * @property string $identifier + * @property Icons $icon * @property Carbon $created_at * @property Carbon $updated_at */ diff --git a/resources/js/Pages/Public/Contact.vue b/resources/js/Pages/Public/Contact.vue new file mode 100644 index 00000000..cf04fe9c --- /dev/null +++ b/resources/js/Pages/Public/Contact.vue @@ -0,0 +1,61 @@ + + + diff --git a/resources/js/Shared/Components/ContactItem.vue b/resources/js/Shared/Components/ContactItem.vue new file mode 100644 index 00000000..caccc0b4 --- /dev/null +++ b/resources/js/Shared/Components/ContactItem.vue @@ -0,0 +1,29 @@ + + + diff --git a/routes/web.php b/routes/web.php index e1672477..736d15ed 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"); From d1c7b96df9af8f8e037b3c4b1640bb0809c8d05e Mon Sep 17 00:00:00 2001 From: Kamil Date: Tue, 27 Aug 2024 13:41:58 +0200 Subject: [PATCH 2/3] #28 - feat: added empty state --- resources/js/Pages/Public/Contact.vue | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/resources/js/Pages/Public/Contact.vue b/resources/js/Pages/Public/Contact.vue index cf04fe9c..762ba99d 100644 --- a/resources/js/Pages/Public/Contact.vue +++ b/resources/js/Pages/Public/Contact.vue @@ -4,6 +4,7 @@ import BackgroundGrid from '@/Components/BackgroundGrid.vue' import SectionHeader from '@/Components/SectionHeader.vue' import { Head } from '@inertiajs/inertia-vue3' import ContactItem from '@/Shared/Components/ContactItem.vue' +import { NoSymbolIcon } from '@heroicons/vue/24/outline' defineProps({ title: String, @@ -52,6 +53,13 @@ defineProps({
+ +
+ +

+ Brak danych kontaktowych +

+
From 987be28c905b1f4d3f3c83c842bc12b6306e4146 Mon Sep 17 00:00:00 2001 From: Kamil Date: Wed, 28 Aug 2024 07:47:55 +0200 Subject: [PATCH 3/3] #28 - fix: code review fixes --- app/Enums/Icons.php | 16 ------------- .../Dashboard/ContactInfoController.php | 7 +----- app/Http/Requests/ContactInfoRequest.php | 3 --- app/Models/ContactInfo.php | 2 -- 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 ------- tests/Feature/ContactInfoTest.php | 8 ------- 9 files changed, 24 insertions(+), 53 deletions(-) delete mode 100644 app/Enums/Icons.php create mode 100644 database/migrations/2024_08_28_073139_remove_icon_field_from_contact_infos_table.php diff --git a/app/Enums/Icons.php b/app/Enums/Icons.php deleted file mode 100644 index feb856c2..00000000 --- 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/Requests/ContactInfoRequest.php b/app/Http/Requests/ContactInfoRequest.php index d70963f0..f59510bc 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 165c3228..3e9147cb 100644 --- a/app/Models/ContactInfo.php +++ b/app/Models/ContactInfo.php @@ -8,13 +8,11 @@ use Illuminate\Database\Eloquent\Concerns\HasUlids; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; -use Keating\Enums\Icons; /** * @property string $id * @property string $label * @property string $identifier - * @property Icons $icon * @property Carbon $created_at * @property Carbon $updated_at */ diff --git a/database/factories/ContactInfoFactory.php b/database/factories/ContactInfoFactory.php index 6b8cf6a7..2cdd47c6 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 00000000..4b76fe2a --- /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 4440422a..39550a1f 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/tests/Feature/ContactInfoTest.php b/tests/Feature/ContactInfoTest.php index a1b81080..50282365 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);