From 85d18b8cc8be217312eb227e9cbfa7737127f729 Mon Sep 17 00:00:00 2001 From: Philip Okugbe <16838612+Philipinho@users.noreply.github.com> Date: Thu, 30 Jan 2025 13:25:10 +0000 Subject: [PATCH] Set default language on invitation signup (#691) * Default language selection to en-US if locale is undefined (Client) --- .../user/components/account-language.tsx | 2 +- .../services/workspace-invitation.service.ts | 20 +++++++++---------- .../src/database/repos/user/user.repo.ts | 5 +++-- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/apps/client/src/features/user/components/account-language.tsx b/apps/client/src/features/user/components/account-language.tsx index e2e0f36d..ed940254 100644 --- a/apps/client/src/features/user/components/account-language.tsx +++ b/apps/client/src/features/user/components/account-language.tsx @@ -47,7 +47,7 @@ function LanguageSwitcher() { { value: "pt-BR", label: "Português (Brazilian)" }, { value: "zh-CN", label: "中文 (简体)" }, ]} - value={language} + value={language || 'en-US'} onChange={handleChange} allowDeselect={false} checkIconPosition="right" diff --git a/apps/server/src/core/workspace/services/workspace-invitation.service.ts b/apps/server/src/core/workspace/services/workspace-invitation.service.ts index 35a7d217..c6c0d2ff 100644 --- a/apps/server/src/core/workspace/services/workspace-invitation.service.ts +++ b/apps/server/src/core/workspace/services/workspace-invitation.service.ts @@ -168,20 +168,18 @@ export class WorkspaceInvitationService { try { await executeTx(this.db, async (trx) => { - newUser = await trx - .insertInto('users') - .values({ + newUser = await this.userRepo.insertUser( + { name: dto.name, email: invitation.email, - password: password, - workspaceId: workspaceId, - role: invitation.role, - lastLoginAt: new Date(), - invitedById: invitation.invitedById, emailVerifiedAt: new Date(), - }) - .returningAll() - .executeTakeFirst(); + password: password, + role: invitation.role, + invitedById: invitation.invitedById, + workspaceId: workspaceId, + }, + trx, + ); // add user to default group await this.groupUserRepo.addUserToDefaultGroup( diff --git a/apps/server/src/database/repos/user/user.repo.ts b/apps/server/src/database/repos/user/user.repo.ts index 8342e0af..7c77f2aa 100644 --- a/apps/server/src/database/repos/user/user.repo.ts +++ b/apps/server/src/database/repos/user/user.repo.ts @@ -99,7 +99,8 @@ export class UserRepo { trx?: KyselyTransaction, ): Promise { const user: InsertableUser = { - name: insertableUser.name || insertableUser.email.toLowerCase(), + name: + insertableUser.name || insertableUser.email.split('@')[1].toLowerCase(), email: insertableUser.email.toLowerCase(), password: await hashPassword(insertableUser.password), locale: 'en-US', @@ -110,7 +111,7 @@ export class UserRepo { const db = dbOrTx(this.db, trx); return db .insertInto('users') - .values(user) + .values({ ...insertableUser, ...user }) .returningAll() .executeTakeFirst(); }