From 492b11e2ca3eb28e8024172f0a3e203ead71ee2a Mon Sep 17 00:00:00 2001 From: korridor <26689068+korridor@users.noreply.github.com> Date: Tue, 19 Mar 2024 18:14:26 +0100 Subject: [PATCH] Added timezone to registration --- app/Actions/Fortify/CreateNewUser.php | 9 ++++++++- app/Service/TimezoneService.php | 5 +++++ .../2014_10_12_000000_create_users_table.php | 2 +- playwright.config.ts | 2 +- resources/js/Pages/Auth/Register.vue | 1 + .../Partials/UpdateProfileInformationForm.vue | 13 +++++++++++-- 6 files changed, 27 insertions(+), 5 deletions(-) diff --git a/app/Actions/Fortify/CreateNewUser.php b/app/Actions/Fortify/CreateNewUser.php index 3702cf5a..05b5f06f 100644 --- a/app/Actions/Fortify/CreateNewUser.php +++ b/app/Actions/Fortify/CreateNewUser.php @@ -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; @@ -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'])) { + $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); }); diff --git a/app/Service/TimezoneService.php b/app/Service/TimezoneService.php index 27a43d56..d3a62509 100644 --- a/app/Service/TimezoneService.php +++ b/app/Service/TimezoneService.php @@ -32,4 +32,9 @@ public function getSelectOptions(): array return $options; } + + public function isValid(string $timezone): bool + { + return in_array($timezone, $this->getTimezones(), true); + } } diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index 3d08b16c..f6cd3bc7 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -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') diff --git a/playwright.config.ts b/playwright.config.ts index 507e1c49..0eddd35c 100644 --- a/playwright.config.ts +++ b/playwright.config.ts @@ -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. */ diff --git a/resources/js/Pages/Auth/Register.vue b/resources/js/Pages/Auth/Register.vue index 31fc664d..095d8369 100644 --- a/resources/js/Pages/Auth/Register.vue +++ b/resources/js/Pages/Auth/Register.vue @@ -15,6 +15,7 @@ const form = useForm({ password: '', password_confirmation: '', terms: false, + timezone: Intl.DateTimeFormat().resolvedOptions().timeZone ?? null, }); const submit = () => { diff --git a/resources/js/Pages/Profile/Partials/UpdateProfileInformationForm.vue b/resources/js/Pages/Profile/Partials/UpdateProfileInformationForm.vue index 5defcf93..aad47e4c 100644 --- a/resources/js/Pages/Profile/Partials/UpdateProfileInformationForm.vue +++ b/resources/js/Pages/Profile/Partials/UpdateProfileInformationForm.vue @@ -203,8 +203,17 @@ const page = usePage<{
- + +