Skip to content

Commit

Permalink
#13 - wip
Browse files Browse the repository at this point in the history
  • Loading branch information
KarolZygadlo committed Sep 24, 2023
1 parent ddbb902 commit f96fe2e
Show file tree
Hide file tree
Showing 13 changed files with 289 additions and 32 deletions.
28 changes: 28 additions & 0 deletions app/Http/Controllers/ContactInfoController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

declare(strict_types=1);

namespace App\Http\Controllers;

use App\Http\Requests\UpdateContactInfoRequest;
use App\Models\ContactInfo;
use Illuminate\Http\RedirectResponse;
use Inertia\Response;

class ContactInfoController extends Controller
{
public function edit(): Response
{
return inertia("Dashboard/ContactInfo", [
"contactInfo" => ContactInfo::query()->first(),
]);
}

public function update(UpdateContactInfoRequest $request): RedirectResponse
{
ContactInfo::query()->first()->update($request->validated());

return redirect()->back()
->with("success", "Zaktualizowano formy kontaktu");
}
}
19 changes: 19 additions & 0 deletions app/Http/Requests/UpdateContactInfoRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

declare(strict_types=1);

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UpdateContactInfoRequest extends FormRequest
{
public function rules(): array
{
return [
"email" => ["required", "email", "max:255"],
"github_handle" => ["nullable", "url"],
"alternative_channel" => ["nullable", "url"],
];
}
}
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 = [];
}
21 changes: 12 additions & 9 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,31 @@

namespace App\Models;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

/**
* @property string $id
* @property string $name
* @property string $email
* @property string $password
* @property Carbon $created_at
* @property Carbon $updated_at
*/
class User extends Authenticatable
{
use HasApiTokens;
use HasFactory;
use Notifiable;
use HasUlids;

protected $fillable = [
"name",
"email",
"password",
];
protected $guarded = [];
protected $hidden = [
"password",
"remember_token",
];
protected $casts = [
"email_verified_at" => "datetime",
"password" => "hashed",
];
}
23 changes: 23 additions & 0 deletions database/factories/ContactInfoFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

declare(strict_types=1);

namespace Database\Factories;

use App\Models\ContactInfo;
use Illuminate\Database\Eloquent\Factories\Factory;

/**
* @extends Factory<ContactInfo>
*/
class ContactInfoFactory extends Factory
{
public function definition(): array
{
return [
"email" => fake()->unique()->email(),
"github_handle" => fake()->optional()->url(),
"alternative_channel" => fake()->optional()->url(),
];
}
}
21 changes: 5 additions & 16 deletions database/factories/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<User>
*/
class UserFactory extends Factory
{
Expand All @@ -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,
]);
}
}
4 changes: 1 addition & 3 deletions database/migrations/2014_10_12_000000_create_users_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
}
Expand Down
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("email");
$table->string("github_handle")->nullable();
$table->string("alternative_channel")->nullable();
$table->timestamps();
});
}

public function down(): void
{
Schema::dropIfExists("contact_infos");
}
};
10 changes: 7 additions & 3 deletions database/seeders/DatabaseSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
2 changes: 1 addition & 1 deletion resources/js/Layouts/DashboardLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
],
},
{
Expand Down
68 changes: 68 additions & 0 deletions resources/js/Pages/Dashboard/ContactInfo.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<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 SecondaryButton from '@/Shared/Components/Buttons/SecondaryButton.vue'
import { useForm } from '@inertiajs/inertia-vue3'
import FormError from '@/Shared/Forms/FormError.vue'
const props = defineProps({
contactInfo: Object,
})
const form = useForm({
email: props.contactInfo.email,
github_handle: props.contactInfo.github_handle,
alternative_channel: props.contactInfo.alternative_channel,
})
function updateContact() {
form.patch(`/dashboard/contact-info`)
}
</script>

<template>
<DashboardLayout>
<h3 class="text-base font-semibold leading-6 text-gray-900">
Edycja form kontaktu
</h3>
<form @submit.prevent="updateContact">
<Section class="mt-3">
<div class="flex justify-between">
<FormGroup>
<FormLabel for="email">
E-mail uczelniany
</FormLabel>
<TextInput id="email" v-model="form.email" :error="form.errors.email" type="email" />
<FormError :error="form.errors.email" class="mt-2" />
</FormGroup>
<FormGroup>
<FormLabel for="github_handle">
Github link
</FormLabel>
<TextInput id="github_handle" v-model="form.github_handle" :error="form.errors.github_handle" />
<FormError :error="form.errors.github_handle" class="mt-2" />
</FormGroup>
<FormGroup>
<FormLabel for="alternative_channel">
Alternatywny kontakt
</FormLabel>
<TextInput id="alternative_channel" v-model="form.alternative_channel" :error="form.errors.alternative_channel" />
<FormError :error="form.errors.alternative_channel" class="mt-2" />
</FormGroup>
</div>
<div class="flex justify-end space-x-3 py-3">
<SecondaryButton href="/dashboard">
Cofnij
</SecondaryButton>
<SubmitButton>
Zapisz
</SubmitButton>
</div>
</Section>
</form>
</DashboardLayout>
</template>
3 changes: 3 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down
Loading

0 comments on commit f96fe2e

Please sign in to comment.