Skip to content

Commit 246ad7e

Browse files
committed
feat: implement inline form handler for profile editing and enhance empty state component
1 parent de6687a commit 246ad7e

4 files changed

Lines changed: 700 additions & 19 deletions

File tree

app/Console/Commands/EditProfileCommand.php

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@
77
use App\Actions\UpdateUser;
88
use App\Models\User;
99
use App\Rules\UserUsername;
10+
use App\Support\InlineFormHandler;
1011
use Illuminate\Console\Command;
1112
use Illuminate\Container\Attributes\CurrentUser;
13+
use Illuminate\Support\Facades\Validator;
1214

1315
use function Laravel\Prompts\info;
14-
use function Laravel\Prompts\text;
15-
use function Laravel\Prompts\textarea;
1616

1717
final class EditProfileCommand extends Command
1818
{
@@ -23,24 +23,46 @@ final class EditProfileCommand extends Command
2323

2424
public function handle(#[CurrentUser] User $user, UpdateUser $action): void
2525
{
26-
info('Edit your profile');
26+
$form = new InlineFormHandler;
2727

28-
$username = text(
28+
$form->addTextField(
29+
name: 'username',
2930
label: 'Username',
30-
placeholder: 'Enter your username',
3131
default: $user->username,
32-
required: true,
33-
validate: ['required', 'string', 'max:255', new UserUsername($user)],
32+
placeholder: 'Enter your username',
33+
maxLength: 255
3434
);
3535

36-
$bio = textarea(
36+
$form->addTextareaField(
37+
name: 'bio',
3738
label: 'Bio',
38-
placeholder: 'Tell us about yourself...',
3939
default: $user->bio ?? '',
40-
validate: ['nullable', 'string', 'max:500'],
40+
placeholder: 'Tell us about yourself...',
41+
maxLength: 500
4142
);
4243

43-
$action->handle($user, $username, $bio);
44+
$values = $form->run('Edit your profile');
45+
46+
if ($values === null) {
47+
info('Profile editing cancelled.');
48+
49+
return;
50+
}
51+
52+
// Validate the input
53+
$validator = Validator::make($values, [
54+
'username' => ['required', 'string', 'max:255', new UserUsername($user)],
55+
'bio' => ['nullable', 'string', 'max:500'],
56+
]);
57+
58+
if ($validator->fails()) {
59+
$errors = $validator->errors()->all();
60+
info('Validation failed: '.implode(', ', $errors));
61+
62+
return;
63+
}
64+
65+
$action->handle($user, $values['username'], $values['bio']);
4466

4567
info('Profile updated successfully!');
4668
}

0 commit comments

Comments
 (0)