Skip to content

Commit

Permalink
Added timezone to registration
Browse files Browse the repository at this point in the history
  • Loading branch information
korridor committed Mar 19, 2024
1 parent b76da91 commit 492b11e
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 5 deletions.
9 changes: 8 additions & 1 deletion app/Actions/Fortify/CreateNewUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use App\Models\Organization;
use App\Models\User;
use App\Service\TimezoneService;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Hash;
Expand Down Expand Up @@ -48,11 +49,17 @@ public function create(array $input): User
'terms' => Jetstream::hasTermsAndPrivacyPolicyFeature() ? ['accepted', 'required'] : '',
])->validate();

return DB::transaction(function () use ($input) {
$timezone = 'UTC';
if (isset($input['timezone']) && is_string($input['timezone']) && app(TimezoneService::class)->isValid($input['timezone'])) {

Check failure on line 53 in app/Actions/Fortify/CreateNewUser.php

View workflow job for this annotation

GitHub Actions / phpstan

Right side of && is always true.
$timezone = $input['timezone'];
}

return DB::transaction(function () use ($input, $timezone) {
return tap(User::create([
'name' => $input['name'],
'email' => $input['email'],
'password' => Hash::make($input['password']),
'timezone' => $timezone,
]), function (User $user) {
$this->createTeam($user);
});
Expand Down
5 changes: 5 additions & 0 deletions app/Service/TimezoneService.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,9 @@ public function getSelectOptions(): array

return $options;
}

public function isValid(string $timezone): bool
{
return in_array($timezone, $this->getTimezones(), true);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function up(): void
$table->boolean('is_placeholder')->default(false);
$table->foreignUuid('current_team_id')->nullable();
$table->string('profile_photo_path', 2048)->nullable();
$table->string('timezone')->nullable();
$table->string('timezone');
$table->timestamps();

$table->uniqueIndex('email')
Expand Down
2 changes: 1 addition & 1 deletion playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export default defineConfig({
/* Retry on CI only */
retries: process.env.CI ? 1 : 0,
/* Opt out of parallel tests on CI. */
workers: process.env.CI ? 1 : undefined,
workers: process.env.CI ? 1 : 1,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: process.env.CI ? 'line' : 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
Expand Down
1 change: 1 addition & 0 deletions resources/js/Pages/Auth/Register.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ const form = useForm({
password: '',
password_confirmation: '',
terms: false,
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone ?? null,
});
const submit = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,8 +203,17 @@ const page = usePage<{
<!-- Timezone -->
<div class="col-span-6 sm:col-span-4">
<InputLabel for="timezone" value="Timezone" />
<select name="timezone" id="timezone" v-model="form.timezone" class="mt-1 block w-full border-input-border bg-input-background text-white focus:border-input-border-active rounded-md shadow-sm">
<option v-for="timezone in $page.props.timezones" :value="timezone">
<select
name="timezone"
id="timezone"
v-model="form.timezone"
required
class="mt-1 block w-full border-input-border bg-input-background text-white focus:border-input-border-active rounded-md shadow-sm">
<option value="" disabled>Select a Timezone</option>
<option
v-for="timezone in $page.props.timezones"
:key="timezone"
:value="timezone">
{{ timezone }}
</option>
</select>
Expand Down

0 comments on commit 492b11e

Please sign in to comment.