Skip to content

Commit

Permalink
Merge branch 'main' into #10-courses-crud
Browse files Browse the repository at this point in the history
# Conflicts:
#	resources/js/Shared/Forms/Select.vue
#	routes/web.php
  • Loading branch information
kamilpiech97 committed Oct 4, 2023
2 parents f3844d6 + e926d78 commit b669630
Show file tree
Hide file tree
Showing 21 changed files with 609 additions and 17 deletions.
16 changes: 16 additions & 0 deletions app/Enums/Icons.php
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";
}
71 changes: 71 additions & 0 deletions app/Http/Controllers/Dashboard/ContactInfoController.php
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");
}
}
21 changes: 21 additions & 0 deletions app/Http/Requests/ContactInfoRequest.php
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)],
];
}
}
26 changes: 26 additions & 0 deletions app/Models/ContactInfo.php
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 = [];
}
22 changes: 11 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions database/factories/ContactInfoFactory.php
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),
];
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class() extends Migration {
public function up(): void
{
Schema::create("contact_infos", function (Blueprint $table): void {
$table->ulid("id")->primary();
$table->string("label");
$table->string("identifier");
$table->string("icon")->nullable();
$table->timestamps();
});
}

public function down(): void
{
Schema::dropIfExists("contact_infos");
}
};
2 changes: 1 addition & 1 deletion resources/js/Layouts/DashboardLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,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: '/dashboard/faqs', icon: QuestionMarkCircleIcon, current: false },
{ name: 'Formy kontaktu', href: '#', icon: AtSymbolIcon, current: false },
{ name: 'Formy kontaktu', href: '/dashboard/contact-infos', icon: AtSymbolIcon, current: false },
],
},
{
Expand Down
84 changes: 84 additions & 0 deletions resources/js/Pages/Dashboard/ContactInfo/Create.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<script setup>
import DashboardLayout from '@/Layouts/DashboardLayout.vue'
import Section from '@/Shared/Components/Section.vue'
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: '',
icon: '',
})
function createContactInfo() {
form.post('/dashboard/contact-infos')
}
</script>

<template>
<DashboardLayout>
<div class="flex flex-col gap-8">
<ManagementHeader>
<template #header>
Zarządzanie formami kontaktu
</template>
<template #statistics>
<ManagementHeaderItem>
Formularz dodawania nowej formy kontaktu
</ManagementHeaderItem>
</template>
</ManagementHeader>

<form class="grid grid-cols-2" @submit.prevent="createContactInfo">
<Section>
<div class="flex flex-col justify-between gap-4">
<FormGroup>
<FormLabel for="id">
Id
</FormLabel>
<TextInput class="opacity-75" placeholder="autogenerowany ulid" autocomplete="off" disabled />
</FormGroup>
<FormGroup>
<FormLabel for="label">
Etykieta
</FormLabel>
<TextInput id="label" v-model="form.label" :error="form.errors.label" autocomplete="off" />
<FormError :error="form.errors.label" />
</FormGroup>
<FormGroup>
<FormLabel for="identifier">
Email / link do kontaktu
</FormLabel>
<TextInput id="identifier" v-model="form.identifier" :error="form.errors.identifier" autocomplete="off" />
<FormError :error="form.errors.identifier" />
</FormGroup>
<FormGroup>
<FormLabel for="icon">
Ikona
</FormLabel>
<Select id="icon" v-model="form.icon" :error="form.errors.icon" :options="icons" label="label" item-value="value" />
<FormError :error="form.errors.icon" />
</FormGroup>
<div class="mt-4 flex justify-end">
<SubmitButton>
Utwórz
</SubmitButton>
</div>
</div>
</Section>
</form>
</div>
</DashboardLayout>
</template>

Loading

0 comments on commit b669630

Please sign in to comment.