-
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.
Merge branch 'main' into #10-courses-crud
# Conflicts: # resources/js/Shared/Forms/Select.vue # routes/web.php
- Loading branch information
Showing
21 changed files
with
609 additions
and
17 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 = []; | ||
} |
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), | ||
]; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
database/migrations/2023_09_23_135710_create_contact_infos_table.php
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,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"); | ||
} | ||
}; |
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
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,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> | ||
|
Oops, something went wrong.