From 7575fa08ec13c8eaef0084d03c1ad0dcd6ec6923 Mon Sep 17 00:00:00 2001 From: Artyom Savchenko Date: Fri, 18 Apr 2025 13:09:08 +0700 Subject: [PATCH] UBERF-10248: Fix local time (#8623) Signed-off-by: Artem Savchenko --- plugins/contact-assets/lang/cs.json | 3 +- plugins/contact-assets/lang/de.json | 3 +- plugins/contact-assets/lang/en.json | 3 +- plugins/contact-assets/lang/es.json | 3 +- plugins/contact-assets/lang/fr.json | 3 +- plugins/contact-assets/lang/it.json | 3 +- plugins/contact-assets/lang/pt.json | 3 +- plugins/contact-assets/lang/ru.json | 3 +- plugins/contact-assets/lang/zh.json | 3 +- .../person/EmployeePreviewPopup.svelte | 21 ++++++------- .../components/person/TimePresenter.svelte | 21 +++---------- .../src/components/person/utils.ts | 31 ++++++++++++++++++- plugins/contact/src/index.ts | 3 +- server/account/src/utils.ts | 7 ++++- 14 files changed, 59 insertions(+), 51 deletions(-) diff --git a/plugins/contact-assets/lang/cs.json b/plugins/contact-assets/lang/cs.json index bfd7f03191..81d61626aa 100644 --- a/plugins/contact-assets/lang/cs.json +++ b/plugins/contact-assets/lang/cs.json @@ -111,7 +111,6 @@ "ViberPlaceholder": "Viber", "UserProfile": "Uživatelský profil", "DeactivatedAccount": "Deaktivovaný účet", - "LocalTime": "místní čas", - "LocalTimeNotSet": "Místní čas není nastaven" + "LocalTime": "místní čas" } } diff --git a/plugins/contact-assets/lang/de.json b/plugins/contact-assets/lang/de.json index ea68d5114b..5a38c4773d 100644 --- a/plugins/contact-assets/lang/de.json +++ b/plugins/contact-assets/lang/de.json @@ -111,7 +111,6 @@ "ViberPlaceholder": "Viber", "UserProfile": "Benutzerprofil", "DeactivatedAccount": "Deaktivierter Account", - "LocalTime": "Ortszeit", - "LocalTimeNotSet": "Ortszeit nicht festgelegt" + "LocalTime": "Ortszeit" } } diff --git a/plugins/contact-assets/lang/en.json b/plugins/contact-assets/lang/en.json index 71991aa27f..c5d25e8618 100644 --- a/plugins/contact-assets/lang/en.json +++ b/plugins/contact-assets/lang/en.json @@ -115,7 +115,6 @@ "Confirmed": "Confirmed", "UserProfile": "User profile", "DeactivatedAccount": "Deactivated account", - "LocalTime": "local time", - "LocalTimeNotSet": "Local time not set" + "LocalTime": "local time" } } diff --git a/plugins/contact-assets/lang/es.json b/plugins/contact-assets/lang/es.json index 88724a7754..9ee90c6ba6 100644 --- a/plugins/contact-assets/lang/es.json +++ b/plugins/contact-assets/lang/es.json @@ -115,7 +115,6 @@ "Confirmed": "Confirmado", "UserProfile": "Perfil de usuario", "DeactivatedAccount": "Cuenta desactivada", - "LocalTime": "hora local", - "LocalTimeNotSet": "Hora local no establecida" + "LocalTime": "hora local" } } diff --git a/plugins/contact-assets/lang/fr.json b/plugins/contact-assets/lang/fr.json index 61b1b598d3..ee5f2962c8 100644 --- a/plugins/contact-assets/lang/fr.json +++ b/plugins/contact-assets/lang/fr.json @@ -115,7 +115,6 @@ "Confirmed": "Confirmé", "UserProfile": "Profil utilisateur", "DeactivatedAccount": "Compte désactivé", - "LocalTime": "heure locale", - "LocalTimeNotSet": "Heure locale non définie" + "LocalTime": "heure locale" } } diff --git a/plugins/contact-assets/lang/it.json b/plugins/contact-assets/lang/it.json index bdfc11ffbc..254716e877 100644 --- a/plugins/contact-assets/lang/it.json +++ b/plugins/contact-assets/lang/it.json @@ -115,7 +115,6 @@ "Confirmed": "Confermato", "UserProfile": "Profilo utente", "DeactivatedAccount": "Account disattivato", - "LocalTime": "ora locale", - "LocalTimeNotSet": "Ora locale non impostata" + "LocalTime": "ora locale" } } diff --git a/plugins/contact-assets/lang/pt.json b/plugins/contact-assets/lang/pt.json index a2ac28ce92..51423a2acd 100644 --- a/plugins/contact-assets/lang/pt.json +++ b/plugins/contact-assets/lang/pt.json @@ -115,7 +115,6 @@ "Confirmed": "Confirmado", "UserProfile": "Perfil do usuário", "DeactivatedAccount": "Conta desativada", - "LocalTime": "hora local", - "LocalTimeNotSet": "Hora local não definida" + "LocalTime": "hora local" } } diff --git a/plugins/contact-assets/lang/ru.json b/plugins/contact-assets/lang/ru.json index e2f10d034c..b7abf0a27d 100644 --- a/plugins/contact-assets/lang/ru.json +++ b/plugins/contact-assets/lang/ru.json @@ -115,7 +115,6 @@ "Confirmed": "Подтвержден", "UserProfile": "Профиль пользователя", "DeactivatedAccount": "Деактивированный аккаунт", - "LocalTime": "местного времени", - "LocalTimeNotSet": "Местное время не задано" + "LocalTime": "местного времени" } } diff --git a/plugins/contact-assets/lang/zh.json b/plugins/contact-assets/lang/zh.json index d62416c381..5039114a37 100644 --- a/plugins/contact-assets/lang/zh.json +++ b/plugins/contact-assets/lang/zh.json @@ -115,7 +115,6 @@ "Confirmed": "已确认", "UserProfile": "用户资料", "DeactivatedAccount": "已停用账户", - "LocalTime": "当地时间", - "LocalTimeNotSet": "未设置当地时间" + "LocalTime": "当地时间" } } diff --git a/plugins/contact-resources/src/components/person/EmployeePreviewPopup.svelte b/plugins/contact-resources/src/components/person/EmployeePreviewPopup.svelte index f12e8ec199..8fc1c3ca47 100644 --- a/plugins/contact-resources/src/components/person/EmployeePreviewPopup.svelte +++ b/plugins/contact-resources/src/components/person/EmployeePreviewPopup.svelte @@ -23,7 +23,8 @@ import ModernProfilePopup from './ModernProfilePopup.svelte' import contact from '../../plugin' import Avatar from '../Avatar.svelte' - import { employeeByIdStore, getAccountClient } from '../../utils' + import { employeeByIdStore } from '../../utils' + import { getPersonTimezone } from './utils' import { EmployeePresenter } from '../../index' import TimePresenter from './TimePresenter.svelte' import DeactivatedHeader from './DeactivatedHeader.svelte' @@ -36,7 +37,6 @@ let employee: Employee | undefined = undefined let timezone: string | undefined = undefined - let isTimezoneLoading = true $: employee = $employeeByIdStore.get(_id) $: void loadPersonTimezone(employee?.personUuid) @@ -50,15 +50,7 @@ } async function loadPersonTimezone (personId: AccountUuid | undefined): Promise { - if (personId === undefined) return - isTimezoneLoading = true - try { - const accountInfo = await getAccountClient().getAccountInfo(personId) - timezone = accountInfo.timezone - } catch (error) { - console.error(error) - } - isTimezoneLoading = false + timezone = await getPersonTimezone(personId) } @@ -95,9 +87,10 @@ on:click={viewProfile} />
+
- +
@@ -151,4 +144,8 @@ display: flex; background-color: var(--theme-button-container-color); } + .status-container { + display: flex; + min-height: 1rem; + } diff --git a/plugins/contact-resources/src/components/person/TimePresenter.svelte b/plugins/contact-resources/src/components/person/TimePresenter.svelte index 657de761b7..201a7f22e9 100644 --- a/plugins/contact-resources/src/components/person/TimePresenter.svelte +++ b/plugins/contact-resources/src/components/person/TimePresenter.svelte @@ -13,13 +13,11 @@ // limitations under the License. -->
-
- -
-
- {#if isTimezoneLoading} - - {:else if timezone != null} +
+ {#if timezone != null} {displayTimeInTimezone(timezone)} - {:else} - {/if}
diff --git a/plugins/contact-resources/src/components/person/utils.ts b/plugins/contact-resources/src/components/person/utils.ts index 00d00eb032..df39202122 100644 --- a/plugins/contact-resources/src/components/person/utils.ts +++ b/plugins/contact-resources/src/components/person/utils.ts @@ -10,12 +10,16 @@ // // See the License for the specific language governing permissions and // limitations under the License. +import { get, writable } from 'svelte/store' + +import type { AccountUuid, Class, Ref } from '@hcengineering/core' import type { Person } from '@hcengineering/contact' import { getClient } from '@hcengineering/presentation' import type { LabelAndProps } from '@hcengineering/ui' + import contact from '../../plugin' import EmployeePreviewPopup from './EmployeePreviewPopup.svelte' -import type { Class, Ref } from '@hcengineering/core' +import { getAccountClient } from '../../utils' const client = getClient() const h = client.getHierarchy() @@ -35,3 +39,28 @@ export function getPreviewPopup ( noArrow: true } } + +export const timezoneByAccountStore = writable>(new Map()) + +export async function getPersonTimezone (personId: AccountUuid | undefined): Promise { + if (personId === undefined) return undefined + + const storedTimezone = get(timezoneByAccountStore).get(personId) + if (storedTimezone !== undefined) return storedTimezone + + try { + const accountInfo = await getAccountClient().getAccountInfo(personId) + if (accountInfo.timezone !== undefined) { + timezoneByAccountStore.update((store: Map) => { + if (accountInfo.timezone !== undefined) { + store.set(personId, accountInfo.timezone) + } + return store + }) + } + return accountInfo.timezone + } catch (error) { + console.error(error) + return undefined + } +} diff --git a/plugins/contact/src/index.ts b/plugins/contact/src/index.ts index 0473c750b1..83f8e77a3a 100644 --- a/plugins/contact/src/index.ts +++ b/plugins/contact/src/index.ts @@ -336,8 +336,7 @@ export const contactPlugin = plugin(contactId, { Confirmed: '' as IntlString, UserProfile: '' as IntlString, DeactivatedAccount: '' as IntlString, - LocalTime: '' as IntlString, - LocalTimeNotSet: '' as IntlString + LocalTime: '' as IntlString }, viewlet: { TableMember: '' as Ref, diff --git a/server/account/src/utils.ts b/server/account/src/utils.ts index 1a2fede24d..5e3e42ec74 100644 --- a/server/account/src/utils.ts +++ b/server/account/src/utils.ts @@ -527,7 +527,8 @@ export async function selectWorkspace ( workspaceUrl: string kind: 'external' | 'internal' | 'byregion' externalRegions?: string[] - } + }, + meta?: Meta ): Promise { const { workspaceUrl, kind, externalRegions = [] } = params const { account: accountUuid, workspace: tokenWorkspaceUuid, extra } = decodeTokenVerbose(ctx, token ?? '') @@ -581,6 +582,10 @@ export async function selectWorkspace ( throw new PlatformError(new Status(Severity.ERROR, platform.status.WorkspaceNotFound, { workspaceUrl })) } + if (accountUuid !== systemAccountUuid) { + void setTimezoneIfNotDefined(ctx, db, accountUuid, account, meta) + } + if (accountUuid === systemAccountUuid || extra?.admin === 'true') { return { account: accountUuid,