#4 - users CRUD (#24)

* #2 - wip

* #2 - wip

* #2 - ui fixes to login page

* #2 - fix

* #2 - fix

* #4- wip

* #4 - wip

* #4 - wip

* #4 - wip

* #4- wip

* #4 - wip

* #4 - wip

* #4 - tests

* #4 - ecs fix

* #4 - fix

* #4 - wip

* #4 - fix

* #4 - fix

* #4 - fix composer

* #4 - cr fix

Co-authored-by: EwelinaLasowy <ewelina.lasowy@blumilk.pl>
This commit is contained in:
Adrian Hopek 2022-01-19 10:55:10 +01:00 committed by GitHub
parent 91bd46cc36
commit 9aa2d5ec0f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 1977 additions and 63 deletions

View File

@ -54,3 +54,5 @@ DOCKER_INSTALL_XDEBUG=false
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=
GOOGLE_REDIRECT=
LOCAL_EMAIL_FOR_LOGIN_VIA_GOOGLE=

View File

@ -12,5 +12,6 @@ module.exports = {
indent: ['error', 4],
'vue/html-indent': ['error', 4],
'vue/multi-word-component-names': 'off',
}
'comma-dangle': ['error', 'always-multiline'],
},
};

View File

@ -0,0 +1,26 @@
<?php
declare(strict_types=1);
namespace Toby\Console\Commands;
use Illuminate\Console\Command;
use Toby\Models\User;
class CreateUserCommand extends Command
{
protected $signature = "user:create
{email : an email for the user}";
protected $description = "Creates a user";
public function handle(): void
{
$email = $this->argument("email");
User::factory([
"email" => $email,
])->create();
$this->info("The user has been created");
}
}

View File

@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace Toby\Enums;
enum EmploymentForm: string
{
case EMPLOYMENT_CONTRACT = "employment_contract";
case COMMISSION_CONTRACT = "commission_contract";
case B2B_CONTRACT = "b2b_contract";
case BOARD_MEMBER_CONTRACT = "board_member_contract";
public function label(): string
{
return __($this->value);
}
public static function casesToSelect(): array
{
$cases = collect(EmploymentForm::cases());
return $cases->map(
fn(EmploymentForm $enum) => [
"label" => $enum->label(),
"value" => $enum->value,
],
)->toArray();
}
}

View File

@ -0,0 +1,50 @@
<?php
declare(strict_types=1);
namespace Toby\Helpers;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Str;
use LasseRafn\InitialAvatarGenerator\InitialAvatar;
use SVG\SVG;
use Toby\Models\User;
class UserAvatarGenerator
{
public function __construct(
protected InitialAvatar $generator,
) {
}
public function generateFor(User $user): string
{
$path = "avatars/{$this->generateUuid()}.svg";
Storage::put($path, $this->generate($user));
return $path;
}
protected function generate(User $user): SVG
{
return $this->generator->rounded()
->background($this->getColor($user->name))
->color("#F4F8FD")
->smooth()
->fontSize(0.33)
->generateSvg($user->name);
}
protected function getColor(string $name): string
{
$colors = config("colors");
return $colors[strlen($name) % count($colors)];
}
protected function generateUuid(): string
{
return Str::uuid()->toString();
}
}

View File

@ -0,0 +1,83 @@
<?php
declare(strict_types=1);
namespace Toby\Http\Controllers;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Inertia\Response;
use Toby\Enums\EmploymentForm;
use Toby\Http\Requests\UserRequest;
use Toby\Http\Resources\UserFormDataResource;
use Toby\Http\Resources\UserResource;
use Toby\Models\User;
class UserController extends Controller
{
public function index(Request $request): Response
{
$users = User::query()
->withTrashed()
->search($request->query("search"))
->latest()
->paginate()
->withQueryString();
return inertia("Users/Index", [
"users" => UserResource::collection($users),
"filters" => $request->only("search"),
]);
}
public function create(): Response
{
return inertia("Users/Create", [
"employmentForms" => EmploymentForm::casesToSelect(),
]);
}
public function store(UserRequest $request): RedirectResponse
{
User::query()->create($request->data());
return redirect()
->route("users.index")
->with("success", __("User has been created"));
}
public function edit(User $user): Response
{
return inertia("Users/Edit", [
"user" => new UserFormDataResource($user),
"employmentForms" => EmploymentForm::casesToSelect(),
]);
}
public function update(UserRequest $request, User $user): RedirectResponse
{
$user->update($request->data());
return redirect()
->route("users.index")
->with("success", __("User has been updated"));
}
public function destroy(User $user): RedirectResponse
{
$user->delete();
return redirect()
->route("users.index")
->with("success", __("User has been deleted"));
}
public function restore(User $user): RedirectResponse
{
$user->restore();
return redirect()
->route("users.index")
->with("success", __("User has been restored"));
}
}

View File

@ -0,0 +1,33 @@
<?php
declare(strict_types=1);
namespace Toby\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
use Illuminate\Validation\Rules\Enum;
use Toby\Enums\EmploymentForm;
class UserRequest extends FormRequest
{
public function rules(): array
{
return [
"name" => ["required", "min:3", "max: 150"],
"email" => ["required", "email", Rule::unique("users", "email")->ignore($this->user)],
"employmentForm" => ["required", new Enum(EmploymentForm::class)],
"employmentDate" => ["required", "date"],
];
}
public function data(): array
{
return [
"name" => $this->get("name"),
"email" => $this->get("email"),
"employment_form" => $this->get("employmentForm"),
"employment_date" => $this->get("employmentDate"),
];
}
}

View File

@ -0,0 +1,23 @@
<?php
declare(strict_types=1);
namespace Toby\Http\Resources;
use Illuminate\Http\Resources\Json\JsonResource;
class UserFormDataResource extends JsonResource
{
public static $wrap = false;
public function toArray($request): array
{
return [
"id" => $this->id,
"name" => $this->name,
"email" => $this->email,
"employmentForm" => $this->employment_form,
"employmentDate" => $this->employment_date,
];
}
}

View File

@ -8,6 +8,8 @@ use Illuminate\Http\Resources\Json\JsonResource;
class UserResource extends JsonResource
{
public static $wrap = false;
public function toArray($request): array
{
return [
@ -15,7 +17,10 @@ class UserResource extends JsonResource
"name" => $this->name,
"email" => $this->email,
"role" => "Human Resources Manager",
"avatar" => "https://images.unsplash.com/photo-1550525811-e5869dd03032?ixlib=rb-1.2.1&ixid=eyJhcHBfaWQiOjEyMDd9&auto=format&fit=facearea&facepad=2&w=256&h=256&q=80",
"avatar" => asset($this->avatar),
"deleted" => $this->trashed(),
"employmentForm" => $this->employment_form->label(),
"employmentDate" => $this->employment_date->toDisplayString(),
];
}
}

View File

@ -4,26 +4,53 @@ declare(strict_types=1);
namespace Toby\Models;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Carbon;
use Toby\Enums\EmploymentForm;
/**
* @property int $id
* @property string $name
* @property string $email
* @property string $avatar
* @property EmploymentForm $employment_form
* @property Carbon $employment_date
*/
class User extends Authenticatable
{
use HasFactory;
use Notifiable;
use SoftDeletes;
protected $fillable = [
"name",
"email",
"avatar",
"employment_form",
"employment_date",
];
protected $casts = [
"employment_form" => EmploymentForm::class,
"employment_date" => "datetime",
];
protected $hidden = [
"remember_token",
];
public function scopeSearch(Builder $query, ?string $text): Builder
{
if ($text === null) {
return $query;
}
return $query
->where("name", "LIKE", "%{$text}%")
->orWhere("email", "LIKE", "%{$text}%");
}
}

View File

@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
namespace Toby\Observers;
use Illuminate\Support\Facades\Storage;
use Toby\Helpers\UserAvatarGenerator;
use Toby\Models\User;
class UserObserver
{
public function __construct(
protected UserAvatarGenerator $generator,
) {
}
public function created(User $user): void
{
$user->avatar = $this->generator->generateFor($user);
$user->save();
}
public function updating(User $user): void
{
if ($user->isDirty("name")) {
Storage::delete($user->avatar);
$user->avatar = $this->generator->generateFor($user);
}
}
public function forceDeleted(User $user): void
{
Storage::delete($user->avatar);
}
}

View File

@ -4,8 +4,17 @@ declare(strict_types=1);
namespace Toby\Providers;
use Illuminate\Support\Carbon;
use Illuminate\Support\ServiceProvider;
use Toby\Models\User;
use Toby\Observers\UserObserver;
class AppServiceProvider extends ServiceProvider
{
public function boot(): void
{
User::observe(UserObserver::class);
Carbon::macro("toDisplayString", fn() => $this->translatedFormat("j F Y"));
}
}

View File

@ -13,7 +13,8 @@
"laravel/framework": "^8.75",
"laravel/socialite": "^5.2",
"laravel/telescope": "^4.6",
"laravel/tinker": "^2.5"
"laravel/tinker": "^2.5",
"lasserafn/php-initial-avatar-generator": "^4.2"
},
"require-dev": {
"blumilksoftware/codestyle": "^0.9.0",

424
composer.lock generated
View File

@ -4,35 +4,35 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "f5d5c19c36f856c3d336c36a43aa23e4",
"content-hash": "3412dd2a403927b829237ae4db36351a",
"packages": [
{
"name": "asm89/stack-cors",
"version": "v2.0.5",
"version": "v2.1.1",
"source": {
"type": "git",
"url": "https://github.com/asm89/stack-cors.git",
"reference": "7a198ec737e926eab15d29368fc6fff66772b0e2"
"reference": "73e5b88775c64ccc0b84fb60836b30dc9d92ac4a"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/asm89/stack-cors/zipball/7a198ec737e926eab15d29368fc6fff66772b0e2",
"reference": "7a198ec737e926eab15d29368fc6fff66772b0e2",
"url": "https://api.github.com/repos/asm89/stack-cors/zipball/73e5b88775c64ccc0b84fb60836b30dc9d92ac4a",
"reference": "73e5b88775c64ccc0b84fb60836b30dc9d92ac4a",
"shasum": ""
},
"require": {
"php": "^7.0|^8.0",
"symfony/http-foundation": "~2.7|~3.0|~4.0|~5.0|~6.0",
"symfony/http-kernel": "~2.7|~3.0|~4.0|~5.0|~6.0"
"php": "^7.2|^8.0",
"symfony/http-foundation": "^4|^5|^6",
"symfony/http-kernel": "^4|^5|^6"
},
"require-dev": {
"phpunit/phpunit": "^6|^7|^8|^9",
"phpunit/phpunit": "^7|^9",
"squizlabs/php_codesniffer": "^3.5"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.0-dev"
"dev-master": "2.1-dev"
}
},
"autoload": {
@ -58,9 +58,9 @@
],
"support": {
"issues": "https://github.com/asm89/stack-cors/issues",
"source": "https://github.com/asm89/stack-cors/tree/v2.0.5"
"source": "https://github.com/asm89/stack-cors/tree/v2.1.1"
},
"time": "2022-01-03T15:27:13+00:00"
"time": "2022-01-18T09:12:03+00:00"
},
{
"name": "brick/math",
@ -366,29 +366,29 @@
},
{
"name": "dragonmantank/cron-expression",
"version": "v3.2.4",
"version": "v3.3.0",
"source": {
"type": "git",
"url": "https://github.com/dragonmantank/cron-expression.git",
"reference": "9545dea2a1d92b60c8b3d06f02025c83e999bde0"
"reference": "63f2a76a045bac6ec93cc2daf2b534b412aa0313"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/dragonmantank/cron-expression/zipball/9545dea2a1d92b60c8b3d06f02025c83e999bde0",
"reference": "9545dea2a1d92b60c8b3d06f02025c83e999bde0",
"url": "https://api.github.com/repos/dragonmantank/cron-expression/zipball/63f2a76a045bac6ec93cc2daf2b534b412aa0313",
"reference": "63f2a76a045bac6ec93cc2daf2b534b412aa0313",
"shasum": ""
},
"require": {
"php": "^7.2|^8.0",
"webmozart/assert": "^1.7.0"
"webmozart/assert": "^1.0"
},
"replace": {
"mtdowling/cron-expression": "^1.0"
},
"require-dev": {
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12",
"phpstan/phpstan-webmozart-assert": "^0.12.7",
"phpstan/phpstan": "^1.0",
"phpstan/phpstan-webmozart-assert": "^1.0",
"phpunit/phpunit": "^7.0|^8.0|^9.0"
},
"type": "library",
@ -415,7 +415,7 @@
],
"support": {
"issues": "https://github.com/dragonmantank/cron-expression/issues",
"source": "https://github.com/dragonmantank/cron-expression/tree/v3.2.4"
"source": "https://github.com/dragonmantank/cron-expression/tree/v3.3.0"
},
"funding": [
{
@ -423,7 +423,7 @@
"type": "github"
}
],
"time": "2022-01-13T04:09:37+00:00"
"time": "2022-01-14T16:02:05+00:00"
},
{
"name": "egulias/email-validator",
@ -961,16 +961,16 @@
},
{
"name": "inertiajs/inertia-laravel",
"version": "v0.5.2",
"version": "v0.5.4",
"source": {
"type": "git",
"url": "https://github.com/inertiajs/inertia-laravel.git",
"reference": "9c8c4201435aa0c11cb832242cf4c1b01bd8ef32"
"reference": "6a050ce04a710ac4809161558ac09fe49f13075e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/inertiajs/inertia-laravel/zipball/9c8c4201435aa0c11cb832242cf4c1b01bd8ef32",
"reference": "9c8c4201435aa0c11cb832242cf4c1b01bd8ef32",
"url": "https://api.github.com/repos/inertiajs/inertia-laravel/zipball/6a050ce04a710ac4809161558ac09fe49f13075e",
"reference": "6a050ce04a710ac4809161558ac09fe49f13075e",
"shasum": ""
},
"require": {
@ -1018,7 +1018,7 @@
],
"support": {
"issues": "https://github.com/inertiajs/inertia-laravel/issues",
"source": "https://github.com/inertiajs/inertia-laravel/tree/v0.5.2"
"source": "https://github.com/inertiajs/inertia-laravel/tree/v0.5.4"
},
"funding": [
{
@ -1026,7 +1026,91 @@
"type": "github"
}
],
"time": "2022-01-12T16:18:26+00:00"
"time": "2022-01-18T10:59:08+00:00"
},
{
"name": "intervention/image",
"version": "2.7.1",
"source": {
"type": "git",
"url": "https://github.com/Intervention/image.git",
"reference": "744ebba495319501b873a4e48787759c72e3fb8c"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/Intervention/image/zipball/744ebba495319501b873a4e48787759c72e3fb8c",
"reference": "744ebba495319501b873a4e48787759c72e3fb8c",
"shasum": ""
},
"require": {
"ext-fileinfo": "*",
"guzzlehttp/psr7": "~1.1 || ^2.0",
"php": ">=5.4.0"
},
"require-dev": {
"mockery/mockery": "~0.9.2",
"phpunit/phpunit": "^4.8 || ^5.7 || ^7.5.15"
},
"suggest": {
"ext-gd": "to use GD library based image processing.",
"ext-imagick": "to use Imagick based image processing.",
"intervention/imagecache": "Caching extension for the Intervention Image library"
},
"type": "library",
"extra": {
"branch-alias": {
"dev-master": "2.4-dev"
},
"laravel": {
"providers": [
"Intervention\\Image\\ImageServiceProvider"
],
"aliases": {
"Image": "Intervention\\Image\\Facades\\Image"
}
}
},
"autoload": {
"psr-4": {
"Intervention\\Image\\": "src/Intervention/Image"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Oliver Vogel",
"email": "oliver@olivervogel.com",
"homepage": "http://olivervogel.com/"
}
],
"description": "Image handling and manipulation library with support for Laravel integration",
"homepage": "http://image.intervention.io/",
"keywords": [
"gd",
"image",
"imagick",
"laravel",
"thumbnail",
"watermark"
],
"support": {
"issues": "https://github.com/Intervention/image/issues",
"source": "https://github.com/Intervention/image/tree/2.7.1"
},
"funding": [
{
"url": "https://www.paypal.me/interventionphp",
"type": "custom"
},
{
"url": "https://github.com/Intervention",
"type": "github"
}
],
"time": "2021-12-16T16:49:26+00:00"
},
{
"name": "laravel/framework",
@ -1464,6 +1548,169 @@
},
"time": "2022-01-10T08:52:49+00:00"
},
{
"name": "lasserafn/php-initial-avatar-generator",
"version": "4.2.1",
"source": {
"type": "git",
"url": "https://github.com/LasseRafn/php-initial-avatar-generator.git",
"reference": "49d0b10cc8819af831e0f6fb1056a7d5ed9512d0"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/LasseRafn/php-initial-avatar-generator/zipball/49d0b10cc8819af831e0f6fb1056a7d5ed9512d0",
"reference": "49d0b10cc8819af831e0f6fb1056a7d5ed9512d0",
"shasum": ""
},
"require": {
"ext-json": "*",
"intervention/image": "^2.3",
"lasserafn/php-initials": "^3.0",
"lasserafn/php-string-script-language": "^0.3.0",
"meyfa/php-svg": "^0.9.0",
"overtrue/pinyin": "^4.0",
"php": "^7.0|^7.1|^7.2|^7.3|^7.4|^8.0"
},
"require-dev": {
"doctrine/instantiator": "1.0.*",
"phpunit/phpunit": "^6.5",
"satooshi/php-coveralls": "^1.0"
},
"type": "library",
"autoload": {
"psr-4": {
"LasseRafn\\InitialAvatarGenerator\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Lasse Rafn",
"email": "lasserafn@gmail.com"
}
],
"description": "A package to generate avatars with initials for PHP",
"keywords": [
"Initials",
"avatar",
"image",
"svg"
],
"support": {
"issues": "https://github.com/LasseRafn/php-initial-avatar-generator/issues",
"source": "https://github.com/LasseRafn/php-initial-avatar-generator/tree/4.2.1"
},
"funding": [
{
"url": "https://opencollective.com/ui-avatars",
"type": "open_collective"
}
],
"time": "2020-12-24T13:12:12+00:00"
},
{
"name": "lasserafn/php-initials",
"version": "3.1",
"source": {
"type": "git",
"url": "https://github.com/LasseRafn/php-initials.git",
"reference": "d287e1542687390eb68de779949bc0adc49e2d52"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/LasseRafn/php-initials/zipball/d287e1542687390eb68de779949bc0adc49e2d52",
"reference": "d287e1542687390eb68de779949bc0adc49e2d52",
"shasum": ""
},
"require": {
"php": "^5.6|^7.0|^7.1|^8.0"
},
"require-dev": {
"phpunit/phpunit": "^5.7",
"satooshi/php-coveralls": "^1.0"
},
"type": "library",
"autoload": {
"psr-4": {
"LasseRafn\\Initials\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Lasse Rafn",
"email": "lasserafn@gmail.com"
}
],
"description": "A package to generate initials in PHP",
"keywords": [
"Initials",
"php"
],
"support": {
"issues": "https://github.com/LasseRafn/php-initials/issues",
"source": "https://github.com/LasseRafn/php-initials/tree/3.1"
},
"time": "2020-12-24T12:25:51+00:00"
},
{
"name": "lasserafn/php-string-script-language",
"version": "0.3",
"source": {
"type": "git",
"url": "https://github.com/LasseRafn/php-string-script-language.git",
"reference": "49a09d4a5e38c1e59a2656ac05b601d615c7cddb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/LasseRafn/php-string-script-language/zipball/49a09d4a5e38c1e59a2656ac05b601d615c7cddb",
"reference": "49a09d4a5e38c1e59a2656ac05b601d615c7cddb",
"shasum": ""
},
"require": {
"php": "^5.6|^7.0|^7.1|^8.0"
},
"require-dev": {
"doctrine/instantiator": "1.0.5",
"phpunit/phpunit": "^5.6",
"phpunit/phpunit-mock-objects": "3.2.4",
"satooshi/php-coveralls": "^1.0",
"sebastian/exporter": "^1.2"
},
"type": "library",
"autoload": {
"psr-4": {
"LasseRafn\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Lasse Rafn",
"email": "lasserafn@gmail.com"
}
],
"description": "Detect language/encoding of a string in PHP",
"keywords": [
"language",
"php",
"string"
],
"support": {
"issues": "https://github.com/LasseRafn/php-string-script-language/issues",
"source": "https://github.com/LasseRafn/php-string-script-language/tree/0.3"
},
"time": "2020-12-24T12:43:59+00:00"
},
{
"name": "league/commonmark",
"version": "2.1.1",
@ -1875,6 +2122,56 @@
},
"time": "2021-08-15T23:05:49+00:00"
},
{
"name": "meyfa/php-svg",
"version": "v0.9.1",
"source": {
"type": "git",
"url": "https://github.com/meyfa/php-svg.git",
"reference": "34401edef1f724898f468f71b85505fbcc8351bb"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/meyfa/php-svg/zipball/34401edef1f724898f468f71b85505fbcc8351bb",
"reference": "34401edef1f724898f468f71b85505fbcc8351bb",
"shasum": ""
},
"require": {
"ext-gd": "*",
"ext-simplexml": "*",
"php": ">=5.3.3"
},
"require-dev": {
"meyfa/phpunit-assert-gd": "^1.1",
"phpunit/phpunit": "^4.8"
},
"type": "library",
"autoload": {
"psr-4": {
"SVG\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabian Meyer",
"homepage": "http://meyfa.net"
}
],
"description": "Read, edit, write, and render SVG files with PHP",
"homepage": "https://github.com/meyfa/php-svg",
"keywords": [
"svg"
],
"support": {
"issues": "https://github.com/meyfa/php-svg/issues",
"source": "https://github.com/meyfa/php-svg/tree/v0.9.1"
},
"time": "2019-07-30T18:41:25+00:00"
},
{
"name": "monolog/monolog",
"version": "2.3.5",
@ -2338,6 +2635,79 @@
},
"time": "2021-04-09T13:42:10+00:00"
},
{
"name": "overtrue/pinyin",
"version": "4.0.8",
"source": {
"type": "git",
"url": "https://github.com/overtrue/pinyin.git",
"reference": "04bdb4d33d50e8fb1aa5a824064c5151c4b15dc2"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/overtrue/pinyin/zipball/04bdb4d33d50e8fb1aa5a824064c5151c4b15dc2",
"reference": "04bdb4d33d50e8fb1aa5a824064c5151c4b15dc2",
"shasum": ""
},
"require": {
"php": ">=7.1"
},
"require-dev": {
"brainmaestro/composer-git-hooks": "^2.7",
"friendsofphp/php-cs-fixer": "^2.16",
"phpunit/phpunit": "~8.0"
},
"type": "library",
"extra": {
"hooks": {
"pre-commit": [
"composer test",
"composer fix-style"
],
"pre-push": [
"composer test",
"composer check-style"
]
}
},
"autoload": {
"psr-4": {
"Overtrue\\Pinyin\\": "src/"
},
"files": [
"src/const.php"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "overtrue",
"email": "anzhengchao@gmail.com",
"homepage": "http://github.com/overtrue"
}
],
"description": "Chinese to pinyin translator.",
"homepage": "https://github.com/overtrue/pinyin",
"keywords": [
"Chinese",
"Pinyin",
"cn2pinyin"
],
"support": {
"issues": "https://github.com/overtrue/pinyin/issues",
"source": "https://github.com/overtrue/pinyin/tree/4.0.8"
},
"funding": [
{
"url": "https://www.patreon.com/overtrue",
"type": "patreon"
}
],
"time": "2021-07-19T03:43:32+00:00"
},
{
"name": "phpoption/phpoption",
"version": "1.8.1",

21
config/colors.php Normal file
View File

@ -0,0 +1,21 @@
<?php
declare(strict_types=1);
return [
"#475569",
"#EA580C",
"#EAB308",
"#CA8A04",
"#84CC16",
"#4D7C0F",
"#10B981",
"#06B6D4",
"#4338CA",
"#A855F7",
"#86198F",
"#FB7185",
"#EC4899",
"#9D174D",
"#F43F5E",
];

View File

@ -18,5 +18,6 @@ return [
],
"links" => [
public_path("storage") => storage_path("app/public"),
public_path("avatars") => storage_path("app/avatars"),
],
];

View File

@ -6,14 +6,17 @@ namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
use Toby\Enums\EmploymentForm;
class UserFactory extends Factory
{
public function definition(): array
{
return [
"name" => $this->faker->name(),
"name" => "{$this->faker->firstName} {$this->faker->lastName}",
"email" => $this->faker->unique()->safeEmail(),
"employment_form" => $this->faker->randomElement(EmploymentForm::cases()),
"employment_date" => $this->faker->dateTimeBetween("2020-10-27"),
"remember_token" => Str::random(10),
];
}

View File

@ -13,7 +13,11 @@ return new class() extends Migration {
$table->id();
$table->string("name");
$table->string("email")->unique();
$table->string("avatar")->nullable();
$table->string("employment_form");
$table->dateTime("employment_date");
$table->rememberToken();
$table->softDeletes();
$table->timestamps();
});
}

View File

@ -11,6 +11,9 @@ class DatabaseSeeder extends Seeder
{
public function run(): void
{
User::factory(10)->create();
User::factory(35)->create();
User::factory([
"email" => env("LOCAL_EMAIL_FOR_LOGIN_VIA_GOOGLE"),
])->create();
}
}

35
package-lock.json generated
View File

@ -15,10 +15,13 @@
"@tailwindcss/typography": "^0.5.0",
"@vue/compiler-sfc": "^3.2.26",
"autoprefixer": "^10.4.2",
"flatpickr": "^4.6.9",
"laravel-mix": "^6.0.6",
"lodash": "^4.17.21",
"postcss": "^8.4.5",
"tailwindcss": "^3.0.13",
"vue": "^3.2.26",
"vue-flatpickr-component": "^9.0.5",
"vue-loader": "^17.0.0"
},
"devDependencies": {
@ -4722,6 +4725,11 @@
"node": "^10.12.0 || >=12.0.0"
}
},
"node_modules/flatpickr": {
"version": "4.6.9",
"resolved": "https://registry.npmjs.org/flatpickr/-/flatpickr-4.6.9.tgz",
"integrity": "sha512-F0azNNi8foVWKSF+8X+ZJzz8r9sE1G4hl06RyceIaLvyltKvDl6vqk9Lm/6AUUCi5HWaIjiUbk7UpeE/fOXOpw=="
},
"node_modules/flatted": {
"version": "3.2.4",
"resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.4.tgz",
@ -8892,6 +8900,20 @@
"node": ">=4.0"
}
},
"node_modules/vue-flatpickr-component": {
"version": "9.0.5",
"resolved": "https://registry.npmjs.org/vue-flatpickr-component/-/vue-flatpickr-component-9.0.5.tgz",
"integrity": "sha512-fKuz/D4ePQKi+jPo4xjYRgBCLTWrTsCoKbx8nam63x4kTDtSqvFOjNwLvy0QgwC0lC+aFpUWa1dNYTH0hgUcCA==",
"dependencies": {
"flatpickr": "^4.6.9"
},
"engines": {
"node": ">=10.13.0"
},
"peerDependencies": {
"vue": "^3.0.0"
}
},
"node_modules/vue-loader": {
"version": "17.0.0",
"resolved": "https://registry.npmjs.org/vue-loader/-/vue-loader-17.0.0.tgz",
@ -12982,6 +13004,11 @@
"rimraf": "^3.0.2"
}
},
"flatpickr": {
"version": "4.6.9",
"resolved": "https://registry.npmjs.org/flatpickr/-/flatpickr-4.6.9.tgz",
"integrity": "sha512-F0azNNi8foVWKSF+8X+ZJzz8r9sE1G4hl06RyceIaLvyltKvDl6vqk9Lm/6AUUCi5HWaIjiUbk7UpeE/fOXOpw=="
},
"flatted": {
"version": "3.2.4",
"resolved": "https://registry.npmjs.org/flatted/-/flatted-3.2.4.tgz",
@ -15970,6 +15997,14 @@
}
}
},
"vue-flatpickr-component": {
"version": "9.0.5",
"resolved": "https://registry.npmjs.org/vue-flatpickr-component/-/vue-flatpickr-component-9.0.5.tgz",
"integrity": "sha512-fKuz/D4ePQKi+jPo4xjYRgBCLTWrTsCoKbx8nam63x4kTDtSqvFOjNwLvy0QgwC0lC+aFpUWa1dNYTH0hgUcCA==",
"requires": {
"flatpickr": "^4.6.9"
}
},
"vue-loader": {
"version": "17.0.0",
"resolved": "https://registry.npmjs.org/vue-loader/-/vue-loader-17.0.0.tgz",

View File

@ -22,10 +22,13 @@
"@tailwindcss/typography": "^0.5.0",
"@vue/compiler-sfc": "^3.2.26",
"autoprefixer": "^10.4.2",
"flatpickr": "^4.6.9",
"laravel-mix": "^6.0.6",
"lodash": "^4.17.21",
"postcss": "^8.4.5",
"tailwindcss": "^3.0.13",
"vue": "^3.2.26",
"vue-flatpickr-component": "^9.0.5",
"vue-loader": "^17.0.0"
},
"devDependencies": {

1
public/avatars Symbolic link
View File

@ -0,0 +1 @@
/application/storage/app/avatars

View File

@ -1,3 +1,49 @@
@import 'flatpickr/dist/themes/light.css';
@tailwind base;
@tailwind components;
@tailwind utilities;
.flatpickr-months .flatpickr-prev-month:hover svg,
.flatpickr-months .flatpickr-next-month:hover svg {
fill: #4F46E5;
}
.flatpickr-day.selected,
.flatpickr-day.startRange,
.flatpickr-day.endRange,
.flatpickr-day.selected.inRange,
.flatpickr-day.startRange.inRange,
.flatpickr-day.endRange.inRange,
.flatpickr-day.selected:focus,
.flatpickr-day.startRange:focus,
.flatpickr-day.endRange:focus,
.flatpickr-day.selected:hover,
.flatpickr-day.startRange:hover,
.flatpickr-day.endRange:hover,
.flatpickr-day.selected.prevMonthDay,
.flatpickr-day.startRange.prevMonthDay,
.flatpickr-day.endRange.prevMonthDay,
.flatpickr-day.selected.nextMonthDay,
.flatpickr-day.startRange.nextMonthDay,
.flatpickr-day.endRange.nextMonthDay {
background: #527ABA;
-webkit-box-shadow: none;
box-shadow: none;
color: #fff;
border-color: #527ABA;
}
.flatpickr-day.selected.startRange + .endRange:not(:nth-child(7n+1)),
.flatpickr-day.startRange.startRange + .endRange:not(:nth-child(7n+1)),
.flatpickr-day.endRange.startRange + .endRange:not(:nth-child(7n+1)) {
-webkit-box-shadow: -10px 0 0 #527ABA;
box-shadow: -10px 0 0 #527ABA;
}
.flatpickr-day.week.selected {
border-radius: 0;
-webkit-box-shadow: -5px 0 0 #527ABA, 5px 0 0 #527ABA;
box-shadow: -5px 0 0 #527ABA, 5px 0 0 #527ABA;
}

View File

@ -291,7 +291,7 @@ export default {
name: 'Payroll',
href: '#',
iconForeground: 'text-yellow-700',
iconBackground: 'bg-yellow-50'
iconBackground: 'bg-yellow-50',
},
{
icon: ReceiptRefundIcon,

View File

@ -80,7 +80,7 @@ export default {
errors: {
type: Object,
default: () => ({oauth: null}),
}
},
},
};
</script>

View File

@ -0,0 +1,206 @@
<template>
<InertiaHead title="Dodawanie użytkownika" />
<div class="bg-white sm:rounded-lg shadow-md">
<div class="p-4 sm:px-6">
<h2 class="text-lg leading-6 font-medium text-gray-900">
Dodaj użytkownika
</h2>
<p class="mt-1 text-sm text-gray-500">
Tylko dodani użytkownicy będą mogli zalogować się do aplikacji.
</p>
</div>
<form
class="border-t border-gray-200 px-6"
@submit.prevent="createUser"
>
<div class="sm:grid sm:grid-cols-3 py-4 items-center">
<label
for="name"
class="block text-sm font-medium text-gray-700 sm:mt-px"
>
Imię i nazwisko
</label>
<div class="mt-1 sm:mt-0 sm:col-span-2">
<input
id="name"
v-model="form.name"
type="text"
class="block w-full max-w-lg shadow-sm rounded-md sm:text-sm"
:class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.name, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.name }"
>
<p
v-if="form.errors.name"
class="mt-2 text-sm text-red-600"
>
{{ form.errors.name }}
</p>
</div>
</div>
<div class="sm:grid sm:grid-cols-3 py-4 items-center">
<label
for="email"
class="block text-sm font-medium text-gray-700 sm:mt-px"
>
Adres e-mail
</label>
<div class="mt-1 sm:mt-0 sm:col-span-2">
<input
id="email"
v-model="form.email"
type="email"
class="block w-full max-w-lg shadow-sm rounded-md sm:text-sm"
:class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.email, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.email }"
>
<p
v-if="form.errors.email"
class="mt-2 text-sm text-red-600"
>
{{ form.errors.email }}
</p>
</div>
</div>
<Listbox
v-model="form.employmentForm"
as="div"
class="sm:grid sm:grid-cols-3 py-4 items-center"
>
<ListboxLabel class="block text-sm font-medium text-gray-700">
Forma zatrudnienia
</ListboxLabel>
<div class="mt-1 relative sm:mt-0 sm:col-span-2">
<ListboxButton
class="bg-white relative w-full max-w-lg border rounded-md shadow-sm pl-3 pr-10 py-2 text-left cursor-default sm:text-sm focus:ring-1"
:class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.employmentForm, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.employmentForm }"
>
<span class="block truncate">{{ form.employmentForm.label }}</span>
<span class="absolute inset-y-0 right-0 flex items-center pr-2 pointer-events-none">
<SelectorIcon class="h-5 w-5 text-gray-400" />
</span>
</ListboxButton>
<transition
leave-active-class="transition ease-in duration-100"
leave-from-class="opacity-100"
leave-to-class="opacity-0"
>
<ListboxOptions class="absolute z-10 mt-1 w-full max-w-lg bg-white shadow-lg max-h-60 rounded-md py-1 text-base ring-1 ring-black ring-opacity-5 overflow-auto focus:outline-none sm:text-sm">
<ListboxOption
v-for="employmentForm in employmentForms"
:key="employmentForm.value"
v-slot="{ active, selected }"
as="template"
:value="employmentForm"
>
<li :class="[active ? 'text-white bg-blumilk-600' : 'text-gray-900', 'cursor-default select-none relative py-2 pl-3 pr-9']">
<span :class="[selected ? 'font-semibold' : 'font-normal', 'block truncate']">
{{ employmentForm.label }}
</span>
<span
v-if="selected"
:class="[active ? 'text-white' : 'text-blumilk-600', 'absolute inset-y-0 right-0 flex items-center pr-4']"
>
<CheckIcon class="h-5 w-5" />
</span>
</li>
</ListboxOption>
</ListboxOptions>
</transition>
<p
v-if="form.errors.employmentForm"
class="mt-2 text-sm text-red-600"
>
{{ form.errors.employmentForm }}
</p>
</div>
</Listbox>
<div class="sm:grid sm:grid-cols-3 py-4 items-center">
<label
for="employment_date"
class="block text-sm font-medium text-gray-700 sm:mt-px"
>
Data zatrudnienia
</label>
<div class="mt-1 sm:mt-0 sm:col-span-2">
<FlatPickr
id="employment_date"
v-model="form.employmentDate"
placeholder="Wybierz datę"
class="block w-full max-w-lg shadow-sm rounded-md sm:text-sm"
:class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.employmentDate, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.employmentDate }"
/>
<p
v-if="form.errors.employmentDate"
class="mt-2 text-sm text-red-600"
>
{{ form.errors.employmentDate }}
</p>
</div>
</div>
<div class="flex justify-end py-3">
<div class="space-x-3">
<InertiaLink
href="/users"
class="bg-white py-2 px-4 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blumilk-500"
>
Anuluj
</InertiaLink>
<button
type="submit"
:disabled="form.processing"
class="inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-blumilk-600 hover:bg-blumilk-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blumilk-500"
>
Zapisz
</button>
</div>
</div>
</form>
</div>
</template>
<script>
import { useForm } from '@inertiajs/inertia-vue3';
import FlatPickr from 'vue-flatpickr-component';
import { Listbox, ListboxButton, ListboxLabel, ListboxOption, ListboxOptions } from '@headlessui/vue';
import { CheckIcon, SelectorIcon } from '@heroicons/vue/solid';
export default {
employmentDate: 'UserCreate',
components: {
FlatPickr,
Listbox,
ListboxButton,
ListboxLabel,
ListboxOption,
ListboxOptions,
CheckIcon,
SelectorIcon,
},
props: {
employmentForms: {
type: Object,
default: () => null,
},
},
setup(props) {
const form = useForm({
name: null,
email: null,
employmentForm: props.employmentForms[0],
employmentDate: new Date(),
});
return { form };
},
methods: {
createUser() {
this.form
.transform(data => ({
...data,
employmentForm: data.employmentForm.value,
}))
.post('/users');
},
},
};
</script>

View File

@ -0,0 +1,210 @@
<template>
<InertiaHead title="Edycja użytkownika" />
<div class="bg-white sm:rounded-lg shadow-md">
<div class="p-4 sm:px-6">
<h2 class="text-lg leading-6 font-medium text-gray-900">
Edytuj użytkownika
</h2>
<p class="mt-1 text-sm text-gray-500">
Edytuj dane użytkownika, takie jak e-mail czy formę zatrudnienia.
</p>
</div>
<form
class="border-t border-gray-200 px-6"
@submit.prevent="editUser"
>
<div class="sm:grid sm:grid-cols-3 py-4 items-center">
<label
for="name"
class="block text-sm font-medium text-gray-700 sm:mt-px"
>
Imię i nazwisko
</label>
<div class="mt-1 sm:mt-0 sm:col-span-2">
<input
id="name"
v-model="form.name"
type="text"
class="block w-full max-w-lg shadow-sm rounded-md sm:text-sm"
:class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.name, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.name }"
>
<p
v-if="form.errors.name"
class="mt-2 text-sm text-red-600"
>
{{ form.errors.name }}
</p>
</div>
</div>
<div class="sm:grid sm:grid-cols-3 py-4 items-center">
<label
for="email"
class="block text-sm font-medium text-gray-700 sm:mt-px"
>
Adres e-mail
</label>
<div class="mt-1 sm:mt-0 sm:col-span-2">
<input
id="email"
v-model="form.email"
type="email"
class="block w-full max-w-lg shadow-sm rounded-md sm:text-sm"
:class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.email, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.email }"
>
<p
v-if="form.errors.email"
class="mt-2 text-sm text-red-600"
>
{{ form.errors.email }}
</p>
</div>
</div>
<Listbox
v-model="form.employmentForm"
as="div"
class="sm:grid sm:grid-cols-3 py-4 items-center"
>
<ListboxLabel class="block text-sm font-medium text-gray-700">
Forma zatrudnienia
</ListboxLabel>
<div class="mt-1 relative sm:mt-0 sm:col-span-2">
<ListboxButton
class="bg-white relative w-full max-w-lg border rounded-md shadow-sm pl-3 pr-10 py-2 text-left cursor-default sm:text-sm focus:ring-1"
:class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.employmentForm, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.employmentForm }"
>
<span class="block truncate">{{ form.employmentForm.label }}</span>
<span class="absolute inset-y-0 right-0 flex items-center pr-2 pointer-events-none">
<SelectorIcon class="h-5 w-5 text-gray-400" />
</span>
</ListboxButton>
<transition
leave-active-class="transition ease-in duration-100"
leave-from-class="opacity-100"
leave-to-class="opacity-0"
>
<ListboxOptions class="absolute z-10 mt-1 w-full max-w-lg bg-white shadow-lg max-h-60 rounded-md py-1 text-base ring-1 ring-black ring-opacity-5 overflow-auto focus:outline-none sm:text-sm">
<ListboxOption
v-for="employmentForm in employmentForms"
:key="employmentForm.value"
v-slot="{ active, selected }"
as="template"
:value="employmentForm"
>
<li :class="[active ? 'text-white bg-blumilk-600' : 'text-gray-900', 'cursor-default select-none relative py-2 pl-3 pr-9']">
<span :class="[selected ? 'font-semibold' : 'font-normal', 'block truncate']">
{{ employmentForm.label }}
</span>
<span
v-if="selected"
:class="[active ? 'text-white' : 'text-blumilk-600', 'absolute inset-y-0 right-0 flex items-center pr-4']"
>
<CheckIcon class="h-5 w-5" />
</span>
</li>
</ListboxOption>
</ListboxOptions>
</transition>
<p
v-if="form.errors.employmentForm"
class="mt-2 text-sm text-red-600"
>
{{ form.errors.employmentForm }}
</p>
</div>
</Listbox>
<div class="sm:grid sm:grid-cols-3 py-4 items-center">
<label
for="employment_date"
class="block text-sm font-medium text-gray-700 sm:mt-px"
>
Data zatrudnienia
</label>
<div class="mt-1 sm:mt-0 sm:col-span-2">
<FlatPickr
id="employment_date"
v-model="form.employmentDate"
placeholder="Wybierz datę"
class="block w-full max-w-lg shadow-sm rounded-md sm:text-sm"
:class="{ 'border-red-300 text-red-900 focus:outline-none focus:ring-red-500 focus:border-red-500': form.errors.employmentDate, 'focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm border-gray-300': !form.errors.employmentDate }"
/>
<p
v-if="form.errors.employmentDate"
class="mt-2 text-sm text-red-600"
>
{{ form.errors.employmentDate }}
</p>
</div>
</div>
<div class="flex justify-end py-3">
<div class="space-x-3">
<InertiaLink
href="/users"
class="bg-white py-2 px-4 border border-gray-300 rounded-md shadow-sm text-sm font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blumilk-500"
>
Anuluj
</InertiaLink>
<button
type="submit"
:disabled="form.processing"
class="inline-flex justify-center py-2 px-4 border border-transparent shadow-sm text-sm font-medium rounded-md text-white bg-blumilk-600 hover:bg-blumilk-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blumilk-500"
>
Zapisz
</button>
</div>
</div>
</form>
</div>
</template>
<script>
import {useForm} from '@inertiajs/inertia-vue3';
import FlatPickr from 'vue-flatpickr-component';
import {Listbox, ListboxButton, ListboxLabel, ListboxOption, ListboxOptions} from '@headlessui/vue';
import {CheckIcon, SelectorIcon} from '@heroicons/vue/solid';
export default {
employmentDate: 'UserEdit',
components: {
FlatPickr,
Listbox,
ListboxButton,
ListboxLabel,
ListboxOption,
ListboxOptions,
CheckIcon,
SelectorIcon,
},
props: {
employmentForms: {
type: Object,
default: () => null,
},
user: {
type: Object,
default: () => null,
},
},
setup(props) {
const form = useForm({
name: props.user.name,
email: props.user.email,
employmentForm: props.employmentForms.find(form => form.value === props.user.employmentForm),
employmentDate: new Date(props.user.employmentDate),
});
return { form };
},
methods: {
editUser() {
this.form
.transform(data => ({
...data,
employmentForm: data.employmentForm.value,
}))
.put(`/users/${this.user.id}`);
},
},
};
</script>

View File

@ -0,0 +1,300 @@
<template>
<InertiaHead title="Użytkownicy" />
<div class="bg-white sm:rounded-lg shadow-md">
<div class="flex justify-between items-center p-4 sm:px-6">
<div>
<h2 class="text-lg leading-6 font-medium text-gray-900">
Użytkownicy w organizacji
</h2>
<p class="mt-1 text-sm text-gray-500">
Lista użytkowników w organizacji.
</p>
</div>
<div>
<InertiaLink
href="users/create"
class="inline-flex items-center px-4 py-3 border border-transparent text-sm leading-4 font-medium rounded-md shadow-sm text-white bg-blumilk-600 hover:bg-blumilk-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-blumilk-500"
>
Dodaj użytkownika
</InertiaLink>
</div>
</div>
<div class="border-t border-gray-200">
<div class="px-4 py-3">
<div class="relative max-w-md">
<div class="absolute inset-y-0 left-0 pl-3 flex items-center pointer-events-none">
<SearchIcon class="h-5 w-5 text-gray-400" />
</div>
<input
v-model.trim="search"
type="search"
class="block w-full bg-white border border-gray-300 rounded-md py-2 pl-10 pr-3 text-sm placeholder-gray-500 focus:outline-none focus:text-gray-900 focus:placeholder-gray-400 focus:ring-1 focus:ring-blumilk-500 focus:border-blumilk-500 sm:text-sm mt-1"
placeholder="Szukaj"
>
</div>
</div>
<div class="overflow-x-auto xl:overflow-x-visible overflow-y-auto xl:overflow-y-visible">
<table class="min-w-full divide-y divide-gray-200">
<thead class="bg-gray-50">
<tr>
<th
scope="col"
class="px-6 py-3 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider"
>
Imię i nazwisko
</th>
<th
scope="col"
class="px-6 py-3 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider"
>
Rola
</th>
<th
scope="col"
class="px-6 py-3 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider"
>
Forma zatrudnienia
</th>
<th
scope="col"
class="px-6 py-3 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider"
>
Data rozpoczęcia
</th>
<th
scope="col"
class="px-6 py-3 text-left text-xs font-semibold text-gray-500 uppercase tracking-wider"
/>
</tr>
</thead>
<tbody class="bg-white divide-y divide-gray-100">
<tr
v-for="user in users.data"
:key="user.id"
:class="{ 'bg-red-50': user.deleted, 'hover:bg-blumilk-25': !user.deleted }"
>
<td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500">
<div class="flex">
<span
class="inline-flex items-center justify-center h-10 w-10 rounded-full"
>
<img
class="h-10 w-10 rounded-full"
:src="user.avatar"
alt=""
>
</span>
<div class="ml-3">
<p class="text-sm font-medium break-all text-gray-900">
{{ user.name }}
</p>
<p class="text-sm break-all text-gray-500">
{{ user.email }}
</p>
</div>
</div>
</td>
<td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500">
{{ user.role }}
</td>
<td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500">
{{ user.employmentForm }}
</td>
<td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500">
{{ user.employmentDate }}
</td>
<td class="px-4 py-4 whitespace-nowrap text-sm text-gray-500 text-right">
<Menu
as="div"
class="relative inline-block text-left"
>
<MenuButton class="rounded-full flex items-center text-gray-400 hover:text-gray-600 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-offset-gray-100 focus:ring-blumilk-500">
<DotsVerticalIcon
class="h-5 w-5"
aria-hidden="true"
/>
</MenuButton>
<transition
enter-active-class="transition ease-out duration-100"
enter-from-class="transform opacity-0 scale-95"
enter-to-class="transform opacity-100 scale-100"
leave-active-class="transition ease-in duration-75"
leave-from-class="transform opacity-100 scale-100"
leave-to-class="transform opacity-0 scale-95"
>
<MenuItems class="origin-top-right absolute right-0 mt-2 w-56 z-10 rounded-md shadow-lg bg-white ring-1 ring-black ring-opacity-5 focus:outline-none">
<div
v-if="!user.deleted"
class="py-1"
>
<MenuItem
v-slot="{ active }"
class="flex"
>
<InertiaLink
:href="`/users/${user.id}/edit`"
:class="[active ? 'bg-gray-100 text-gray-900' : 'text-gray-700', 'font-medium block px-4 py-2 text-sm']"
>
<PencilIcon
class="mr-2 h-5 w-5 text-blue-500"
aria-hidden="true"
/> Edytuj
</InertiaLink>
</MenuItem>
<MenuItem
v-slot="{ active }"
class="flex"
>
<InertiaLink
as="button"
method="delete"
:preserve-scroll="true"
:href="`/users/${user.id}`"
:class="[active ? 'bg-gray-100 text-gray-900' : 'text-gray-700', 'block w-full text-left font-medium px-4 py-2 text-sm']"
>
<TrashIcon
class="mr-2 h-5 w-5 text-red-500"
aria-hidden="true"
/> Usuń
</InertiaLink>
</MenuItem>
</div>
<div
v-else
class="py-1"
>
<MenuItem
v-slot="{ active }"
class="flex"
>
<InertiaLink
as="button"
method="post"
:preserve-scroll="true"
:href="`/users/${user.id}/restore`"
:class="[active ? 'bg-gray-100 text-gray-900' : 'text-gray-700', 'block w-full text-left font-medium px-4 py-2 text-sm']"
>
<RefreshIcon
class="mr-2 h-5 w-5 text-green-500"
aria-hidden="true"
/> Przywróć
</InertiaLink>
</MenuItem>
</div>
</MenuItems>
</transition>
</Menu>
</td>
</tr>
<tr
v-if="! users.data.length"
>
<td
colspan="100%"
class="text-center py-4 text-xl leading-5 text-gray-700"
>
Brak danych
</td>
</tr>
</tbody>
</table>
<div
v-if="users.data.length"
class="bg-white px-4 py-3 flex items-center justify-between border-t border-gray-200 sm:px-6 rounded-b-lg"
>
<div class="flex-1 flex justify-between sm:hidden">
<InertiaLink
:is="users.links.prev ? 'InertiaLink': 'span'"
:href="users.links.prev"
class="relative inline-flex items-center px-4 py-2 border border-gray-300 text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50"
>
Poprzednia
</InertiaLink>
<Component
:is="users.links.next ? 'InertiaLink': 'span'"
:href="users.links.next"
class="ml-3 relative inline-flex items-center px-4 py-2 border border-gray-300 text-sm font-medium rounded-md text-gray-700 bg-white hover:bg-gray-50"
>
Następna
</Component>
</div>
<div class="hidden sm:flex-1 sm:flex sm:items-center sm:justify-between">
<div class="text-sm text-gray-700">
Wyświetlanie
<span class="font-medium">{{ users.meta.from }}</span>
od
<span class="font-medium">{{ users.meta.to }}</span>
do
<span class="font-medium">{{ users.meta.total }}</span>
wyników
</div>
<nav class="relative z-0 inline-flex space-x-1">
<template
v-for="(link, index) in users.meta.links"
:key="index"
>
<Component
:is="link.url ? 'InertiaLink' : 'span'"
:href="link.url"
:preserve-scroll="true"
class="relative inline-flex items-center px-4 py-2 border rounded-md text-sm font-medium"
:class="{ 'z-10 bg-blumilk-25 border-blumilk-500 text-blumilk-600': link.active, 'bg-white border-gray-300 text-gray-500': !link.active, 'hover:bg-blumilk-25': link.url, 'border-none': !link.url}"
v-text="link.label"
/>
</template>
</nav>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import { ref, watch } from 'vue';
import { Inertia } from '@inertiajs/inertia';
import { debounce } from 'lodash';
import { SearchIcon } from '@heroicons/vue/outline';
import { DotsVerticalIcon, PencilIcon, TrashIcon, RefreshIcon } from '@heroicons/vue/solid';
import { Menu, MenuButton, MenuItem, MenuItems } from '@headlessui/vue';
export default {
name: 'UserIndex',
components: {
SearchIcon,
DotsVerticalIcon,
PencilIcon,
TrashIcon,
RefreshIcon,
Menu,
MenuButton,
MenuItem,
MenuItems,
},
props: {
users: {
type: Object,
default: () => null,
},
filters: {
type: Object,
default: () => null,
},
},
setup(props) {
let search = ref(props.filters.search);
watch(search, debounce(value => {
Inertia.get('/users', value ? { search: value} : {}, {
preserveState: true,
replace: true,
});
}, 300));
return {
search,
};
},
};
</script>

View File

@ -37,10 +37,10 @@
>
<div>
<MenuButton
class="bg-white rounded-full flex text-sm ring-2 ring-white ring-opacity-20 focus:outline-none focus:ring-opacity-100"
class="rounded-full flex text-sm ring-2 ring-white ring-opacity-20 focus:outline-none focus:ring-opacity-100"
dusk="user-menu"
>
<span class="sr-only">Open user menu</span>
<span class="sr-only">{{ user.avatar }}</span>
<img
class="h-8 w-8 rounded-full"
:src="user.avatar"
@ -154,7 +154,7 @@
<div>
<img
class="h-8 w-auto"
src="https://tailwindui.com/img/logos/workflow-mark-cyan-600.svg"
src="/img/logo-white.png"
alt="Workflow"
>
</div>
@ -186,7 +186,7 @@
<div class="flex-shrink-0">
<img
class="h-10 w-10 rounded-full"
:src="user.imageUrl"
:src="user.avatar"
alt=""
>
</div>
@ -241,7 +241,7 @@ import {
PopoverOverlay,
PopoverPanel,
TransitionChild,
TransitionRoot
TransitionRoot,
} from '@headlessui/vue';
import {BellIcon, MenuIcon, XIcon} from '@heroicons/vue/outline';
import {computed} from 'vue';
@ -267,8 +267,8 @@ export default {
setup() {
const user = computed(() => usePage().props.value.auth.user);
const navigation = [
{name: 'Home', href: '/', current: true},
{name: 'Profile', href: '#', current: false},
{name: 'Strona główna', href: '/', current: true},
{name: 'Użytkownicy', href: '/users', current: false},
{name: 'Resources', href: '#', current: false},
{name: 'Company Directory', href: '#', current: false},
{name: 'Openings', href: '#', current: false},
@ -276,7 +276,7 @@ export default {
const userNavigation = [
{name: 'Your Profile', href: '#'},
{name: 'Settings', href: '#'},
{name: 'Sign out', href: '/logout', method: 'post', as: 'button'},
{name: 'Wyloguj się', href: '/logout', method: 'post', as: 'button'},
];
return {
@ -284,7 +284,7 @@ export default {
navigation,
userNavigation,
};
}
},
};
</script>

View File

@ -2,6 +2,8 @@ import {createApp, h} from 'vue';
import {createInertiaApp, Head, Link} from '@inertiajs/inertia-vue3';
import {InertiaProgress} from '@inertiajs/progress';
import AppLayout from '@/Shared/Layout/AppLayout';
import Flatpickr from 'flatpickr';
import { Polish } from 'flatpickr/dist/l10n/pl.js';
createInertiaApp({
resolve: name => {
@ -21,4 +23,16 @@ createInertiaApp({
title: title => `${title} - Toby`,
});
InertiaProgress.init();
InertiaProgress.init({
delay: 0,
color: 'red',
});
Flatpickr.localize(Polish);
Flatpickr.setDefaults({
dateFormat: 'Y-m-d',
enableTime: false,
altFormat: 'j F Y',
altInput: true,
});

View File

@ -3,6 +3,6 @@
declare(strict_types=1);
return [
"previous" => "&laquo; Previous",
"next" => "Next &raquo;",
"previous" => "Previous",
"next" => "Next",
];

View File

@ -1,3 +1,7 @@
{
"User does not exist.": "Użytkownik nie istnieje."
"User does not exist.": "Użytkownik nie istnieje.",
"employment_contract": "Umowa o pracę",
"commission_contract": "Umowa zlecenie",
"b2b_contract": "Kontrakt B2B",
"board_member_contract": "Członek zarządu"
}

View File

@ -0,0 +1,9 @@
<?php
declare(strict_types=1);
return [
"failed" => "Błędny login lub hasło.",
"password" => "Podane hasło jest nieprawidłowe.",
"throttle" => "Za dużo nieudanych prób logowania. Proszę spróbować za :seconds sekund.",
];

View File

@ -0,0 +1,8 @@
<?php
declare(strict_types=1);
return [
"next" => "Następna",
"previous" => "Poprzednia",
];

View File

@ -0,0 +1,11 @@
<?php
declare(strict_types=1);
return [
"reset" => "Hasło zostało zresetowane!",
"sent" => "Przypomnienie hasła zostało wysłane!",
"throttled" => "Proszę zaczekać zanim spróbujesz ponownie.",
"token" => "Token resetowania hasła jest nieprawidłowy.",
"user" => "Nie znaleziono użytkownika z takim adresem e-mail.",
];

View File

@ -0,0 +1,117 @@
<?php
declare(strict_types=1);
return [
"accepted" => "Pole :attribute musi zostać zaakceptowane.",
"active_url" => "Pole :attribute jest nieprawidłowym adresem URL.",
"after" => "Pole :attribute musi być datą późniejszą od :date.",
"after_or_equal" => "Pole :attribute musi być datą nie wcześniejszą niż :date.",
"alpha" => "Pole :attribute może zawierać jedynie litery.",
"alpha_dash" => "Pole :attribute może zawierać jedynie litery, cyfry i myślniki.",
"alpha_num" => "Pole :attribute może zawierać jedynie litery i cyfry.",
"array" => "Pole :attribute musi być tablicą.",
"attached" => "Ten :attribute jest już dołączony.",
"before" => "Pole :attribute musi być datą wcześniejszą od :date.",
"before_or_equal" => "Pole :attribute musi być datą nie późniejszą niż :date.",
"between" => [
"array" => "Pole :attribute musi składać się z :min - :max elementów.",
"file" => "Pole :attribute musi zawierać się w granicach :min - :max kilobajtów.",
"numeric" => "Pole :attribute musi zawierać się w granicach :min - :max.",
"string" => "Pole :attribute musi zawierać się w granicach :min - :max znaków.",
],
"boolean" => "Pole :attribute musi mieć wartość logiczną prawda albo fałsz.",
"confirmed" => "Potwierdzenie pola :attribute nie zgadza się.",
"current_password" => "Hasło jest nieprawidłowe.",
"date" => "Pole :attribute nie jest prawidłową datą.",
"date_equals" => "Pole :attribute musi być datą równą :date.",
"date_format" => "Pole :attribute nie jest w formacie :format.",
"different" => "Pole :attribute oraz :other muszą się różnić.",
"digits" => "Pole :attribute musi składać się z :digits cyfr.",
"digits_between" => "Pole :attribute musi mieć od :min do :max cyfr.",
"dimensions" => "Pole :attribute ma niepoprawne wymiary.",
"distinct" => "Pole :attribute ma zduplikowane wartości.",
"email" => "Pole :attribute nie jest poprawnym adresem e-mail.",
"ends_with" => "Pole :attribute musi kończyć się jedną z następujących wartości: :values.",
"exists" => "Zaznaczone pole :attribute jest nieprawidłowe.",
"file" => "Pole :attribute musi być plikiem.",
"filled" => "Pole :attribute nie może być puste.",
"gt" => [
"array" => "Pole :attribute musi mieć więcej niż :value elementów.",
"file" => "Pole :attribute musi być większe niż :value kilobajtów.",
"numeric" => "Pole :attribute musi być większe niż :value.",
"string" => "Pole :attribute musi być dłuższe niż :value znaków.",
],
"gte" => [
"array" => "Pole :attribute musi mieć :value lub więcej elementów.",
"file" => "Pole :attribute musi być większe lub równe :value kilobajtów.",
"numeric" => "Pole :attribute musi być większe lub równe :value.",
"string" => "Pole :attribute musi być dłuższe lub równe :value znaków.",
],
"image" => "Pole :attribute musi być obrazkiem.",
"in" => "Zaznaczony element :attribute jest nieprawidłowy.",
"in_array" => "Pole :attribute nie znajduje się w :other.",
"integer" => "Pole :attribute musi być liczbą całkowitą.",
"ip" => "Pole :attribute musi być prawidłowym adresem IP.",
"ipv4" => "Pole :attribute musi być prawidłowym adresem IPv4.",
"ipv6" => "Pole :attribute musi być prawidłowym adresem IPv6.",
"json" => "Pole :attribute musi być poprawnym ciągiem znaków JSON.",
"lt" => [
"array" => "Pole :attribute musi mieć mniej niż :value elementów.",
"file" => "Pole :attribute musi być mniejsze niż :value kilobajtów.",
"numeric" => "Pole :attribute musi być mniejsze niż :value.",
"string" => "Pole :attribute musi być krótsze niż :value znaków.",
],
"lte" => [
"array" => "Pole :attribute musi mieć :value lub mniej elementów.",
"file" => "Pole :attribute musi być mniejsze lub równe :value kilobajtów.",
"numeric" => "Pole :attribute musi być mniejsze lub równe :value.",
"string" => "Pole :attribute musi być krótsze lub równe :value znaków.",
],
"max" => [
"array" => "Pole :attribute nie może mieć więcej niż :max elementów.",
"file" => "Pole :attribute nie może być większe niż :max kilobajtów.",
"numeric" => "Pole :attribute nie może być większe niż :max.",
"string" => "Pole :attribute nie może być dłuższe niż :max znaków.",
],
"mimes" => "Pole :attribute musi być plikiem typu :values.",
"mimetypes" => "Pole :attribute musi być plikiem typu :values.",
"min" => [
"array" => "Pole :attribute musi mieć przynajmniej :min elementów.",
"file" => "Pole :attribute musi mieć przynajmniej :min kilobajtów.",
"numeric" => "Pole :attribute musi być nie mniejsze od :min.",
"string" => "Pole :attribute musi mieć przynajmniej :min znaków.",
],
"multiple_of" => "Pole :attribute musi być wielokrotnością wartości :value",
"not_in" => "Zaznaczony :attribute jest nieprawidłowy.",
"not_regex" => "Format pola :attribute jest nieprawidłowy.",
"numeric" => "Pole :attribute musi być liczbą.",
"password" => "Hasło jest nieprawidłowe.",
"present" => "Pole :attribute musi być obecne.",
"prohibited" => "Pole :attribute jest zabronione.",
"prohibited_if" => "Pole :attribute jest zabronione, gdy :other to :value.",
"prohibited_unless" => "Pole :attribute jest zabronione, chyba że :other jest w :values.",
"regex" => "Format pola :attribute jest nieprawidłowy.",
"relatable" => "Ten :attribute może nie być powiązany z tym zasobem.",
"required" => "Pole :attribute jest wymagane.",
"required_if" => "Pole :attribute jest wymagane gdy :other ma wartość :value.",
"required_unless" => "Pole :attribute jest wymagane jeżeli :other nie znajduje się w :values.",
"required_with" => "Pole :attribute jest wymagane gdy :values jest obecny.",
"required_with_all" => "Pole :attribute jest wymagane gdy wszystkie :values są obecne.",
"required_without" => "Pole :attribute jest wymagane gdy :values nie jest obecny.",
"required_without_all" => "Pole :attribute jest wymagane gdy żadne z :values nie są obecne.",
"same" => "Pole :attribute i :other muszą być takie same.",
"size" => [
"array" => "Pole :attribute musi zawierać :size elementów.",
"file" => "Pole :attribute musi mieć :size kilobajtów.",
"numeric" => "Pole :attribute musi mieć :size.",
"string" => "Pole :attribute musi mieć :size znaków.",
],
"starts_with" => "Pole :attribute musi zaczynać się jedną z następujących wartości: :values.",
"string" => "Pole :attribute musi być ciągiem znaków.",
"timezone" => "Pole :attribute musi być prawidłową strefą czasową.",
"unique" => "Taki :attribute już występuje.",
"uploaded" => "Nie udało się wgrać pliku :attribute.",
"url" => "Format pola :attribute jest nieprawidłowy.",
"uuid" => "Pole :attribute musi być poprawnym identyfikatorem UUID.",
];

View File

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html class="h-full bg-gray-100">
<html class="h-full bg-blumilk-25">
<head>
<meta charset="utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0"/>

View File

@ -5,10 +5,14 @@ declare(strict_types=1);
use Illuminate\Support\Facades\Route;
use Toby\Http\Controllers\GoogleController;
use Toby\Http\Controllers\LogoutController;
use Toby\Http\Controllers\UserController;
Route::middleware("auth")->group(function (): void {
Route::get("/", fn() => inertia("Dashboard"))->name("dashboard");
Route::post("/logout", LogoutController::class);
Route::resource("users", UserController::class);
Route::post("users/{user}/restore", [UserController::class, "restore"])->withTrashed();
});
Route::middleware("guest")->group(function (): void {

163
tests/Feature/UserTest.php Normal file
View File

@ -0,0 +1,163 @@
<?php
declare(strict_types=1);
namespace Tests\Feature;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Storage;
use Inertia\Testing\AssertableInertia as Assert;
use Tests\TestCase;
use Toby\Enums\EmploymentForm;
use Toby\Models\User;
class UserTest extends TestCase
{
use DatabaseMigrations;
protected function setUp(): void
{
parent::setUp();
Storage::fake();
}
public function testAdminCanSeeUsersList(): void
{
User::factory()->count(10)->create();
$admin = User::factory()->create();
$this->assertDatabaseCount("users", 11);
$this->actingAs($admin)
->get("/users")
->assertInertia(
fn(Assert $page) => $page
->component("Users/Index")
->has("users.data", 11),
);
}
public function testAdminCanSearchUsersList(): void
{
User::factory([
"name" => "Test User1",
])->create();
User::factory([
"name" => "Test User2",
])->create();
User::factory([
"name" => "Test User3",
])->create();
$admin = User::factory([
"name" => "John Doe",
])->create();
$this->assertDatabaseCount("users", 4);
$this->actingAs($admin)
->get("/users?search=test")
->assertInertia(
fn(Assert $page) => $page
->component("Users/Index")
->has("users.data", 3),
);
}
public function testUserListIsPaginated(): void
{
User::factory()->count(15)->create();
$admin = User::factory()->create();
$this->assertDatabaseCount("users", 16);
$this->actingAs($admin)
->get("/users?page=2")
->assertInertia(
fn(Assert $page) => $page
->component("Users/Index")
->has("users.data", 1),
);
}
public function testAdminCanCreateUser(): void
{
$admin = User::factory()->create();
Carbon::setTestNow(Carbon::now());
$this->actingAs($admin)
->post("/users", [
"name" => "John Doe",
"email" => "john.doe@example.com",
"employmentForm" => EmploymentForm::B2B_CONTRACT->value,
"employmentDate" => Carbon::now()->toDateTimeString(),
])
->assertSessionHasNoErrors();
$this->assertDatabaseHas("users", [
"name" => "John Doe",
"email" => "john.doe@example.com",
"employment_form" => EmploymentForm::B2B_CONTRACT->value,
"employment_date" => Carbon::now()->toDateTimeString(),
]);
}
public function testAdminCanEditUser(): void
{
$admin = User::factory()->create();
$user = User::factory()->create();
Carbon::setTestNow();
$this->assertDatabaseHas("users", [
"name" => $user->name,
"email" => $user->email,
"employment_form" => $user->employment_form->value,
"employment_date" => $user->employment_date->toDateTimeString(),
]);
$this->actingAs($admin)
->put("/users/{$user->id}", [
"name" => "John Doe",
"email" => "john.doe@example.com",
"employmentForm" => EmploymentForm::B2B_CONTRACT->value,
"employmentDate" => Carbon::now()->toDateTimeString(),
])
->assertSessionHasNoErrors();
$this->assertDatabaseHas("users", [
"name" => "John Doe",
"email" => "john.doe@example.com",
"employment_form" => EmploymentForm::B2B_CONTRACT->value,
"employment_date" => Carbon::now()->toDateTimeString(),
]);
}
public function testAdminCanDeleteUser(): void
{
$admin = User::factory()->create();
$user = User::factory()->create();
$this->actingAs($admin)
->delete("/users/{$user->id}")
->assertSessionHasNoErrors();
$this->assertSoftDeleted($user);
}
public function testAdminCanRestoreUser(): void
{
$admin = User::factory()->create();
$user = User::factory()->create();
$user->delete();
$this->assertSoftDeleted($user);
$this->actingAs($admin)
->post("/users/{$user->id}/restore")
->assertSessionHasNoErrors();
$this->assertNotSoftDeleted($user);
}
}

69
tests/Unit/AvatarTest.php Normal file
View File

@ -0,0 +1,69 @@
<?php
declare(strict_types=1);
namespace Tests\Unit;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Support\Facades\Storage;
use Tests\TestCase;
use Toby\Models\User;
class AvatarTest extends TestCase
{
use DatabaseMigrations;
protected function setUp(): void
{
parent::setUp();
Storage::fake();
}
public function testAvatarIsGeneratedWhenUserIsCreated(): void
{
$user = User::factory()->create();
Storage::assertExists($user->avatar);
}
public function testAvatarIsDeletedWhenUserIsForceDeleted(): void
{
$user = User::factory()->create();
Storage::assertExists($user->avatar);
$user->forceDelete();
Storage::assertMissing($user->avatar);
}
public function testAvatarIsReplacedWhenUserChangedTheirName(): void
{
$user = User::factory()->create();
$oldAvatar = $user->avatar;
Storage::assertExists($oldAvatar);
$user->update([
"name" => "John Doe",
]);
Storage::assertMissing($oldAvatar);
Storage::assertExists($user->avatar);
}
public function testAvatarIsNotReplacedWhenUserChangedOtherData(): void
{
$user = User::factory()->create();
$avatar = $user->avatar;
Storage::assertExists($avatar);
$user->update([
"email" => "john.doe@example.com",
]);
Storage::assertExists($avatar);
}
}

View File

@ -1,15 +0,0 @@
<?php
declare(strict_types=1);
namespace Tests\Unit;
use PHPUnit\Framework\TestCase;
class ExampleTest extends TestCase
{
public function testExample(): void
{
$this->assertTrue(true);
}
}