Skip to content

Commit

Permalink
add timezone edit to profile (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
saeedvaziry authored Sep 30, 2023
1 parent 38e23a1 commit 8282d39
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
6 changes: 6 additions & 0 deletions app/Actions/User/UpdateUserProfileInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ public function update(User $user, array $input): void
Validator::make($input, [
'name' => ['required', 'string', 'max:255'],
'email' => ['required', 'email', 'max:255', Rule::unique('users')->ignore($user->id)],
'timezone' => [
'required',
Rule::in(timezone_identifiers_list()),
],
])->validateWithBag('updateProfileInformation');

if ($input['email'] !== $user->email) {
Expand All @@ -27,6 +31,7 @@ public function update(User $user, array $input): void
$user->forceFill([
'name' => $input['name'],
'email' => $input['email'],
'timezone' => $input['timezone'],
])->save();
}
}
Expand All @@ -39,6 +44,7 @@ protected function updateVerifiedUser(User $user, array $input): void
$user->forceFill([
'name' => $input['name'],
'email' => $input['email'],
'timezone' => $input['timezone'],
])->save();
}
}
3 changes: 3 additions & 0 deletions app/Http/Livewire/Profile/UpdateProfileInformation.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@ class UpdateProfileInformation extends Component

public string $email;

public string $timezone;

public function mount(): void
{
$this->name = auth()->user()->name;
$this->email = auth()->user()->email;
$this->timezone = auth()->user()->timezone;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@
</div>
@endif
</div>

<div>
<x-input-label for="timezone" :value="__('Timezone')" />
<x-select-input wire:model.defer="timezone" id="timezone" name="timezone" class="mt-1 block w-full" required>
@foreach(timezone_identifiers_list() as $timezone)
<option value="{{ $timezone }}">{{ $timezone }}</option>
@endforeach
</x-select-input>
@error('timezone')
<x-input-error class="mt-2" :messages="$message" />
@enderror
</div>
</form>

<x-slot name="actions">
Expand Down
2 changes: 2 additions & 0 deletions tests/Feature/Http/ProfileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ public function test_profile_information_can_be_updated(): void
Livewire::test(UpdateProfileInformation::class)
->set('name', 'Test')
->set('email', '[email protected]')
->set('timezone', 'Europe/Berlin')
->call('submit')
->assertSuccessful();

$this->user->refresh();

$this->assertSame('Test', $this->user->name);
$this->assertSame('[email protected]', $this->user->email);
$this->assertSame('Europe/Berlin', $this->user->timezone);
}
}

0 comments on commit 8282d39

Please sign in to comment.