diff --git a/web/src/components/Settings/PreferencesSection.tsx b/web/src/components/Settings/PreferencesSection.tsx index 68dad14e..0136f9f7 100644 --- a/web/src/components/Settings/PreferencesSection.tsx +++ b/web/src/components/Settings/PreferencesSection.tsx @@ -1,13 +1,13 @@ import { Input, Button, Divider, Switch, Option, Select } from "@mui/joy"; -import { useEffect, useState } from "react"; +import { useState } from "react"; import { toast } from "react-hot-toast"; -import { getMyselfUser } from "@/helpers/api"; import React from "react"; import { useTranslation } from "react-i18next"; import { useGlobalStore, useUserStore } from "@/store/module"; import { VISIBILITY_SELECTOR_ITEMS } from "@/helpers/consts"; import AppearanceSelect from "../AppearanceSelect"; import LocaleSelect from "../LocaleSelect"; +import HelpButton from "../kit/HelpButton"; import "@/less/settings/preferences-section.less"; const PreferencesSection = () => { @@ -16,7 +16,7 @@ const PreferencesSection = () => { const userStore = useUserStore(); const { appearance, locale } = globalStore.state; const { setting, localSetting } = userStore.state.user as User; - const [telegramUserId, setTelegramUserId] = useState(""); + const [telegramUserId, setTelegramUserId] = useState(setting.telegramUserId); const visibilitySelectorItems = VISIBILITY_SELECTOR_ITEMS.map((item) => { return { value: item.value, @@ -24,21 +24,6 @@ const PreferencesSection = () => { }; }); - useEffect(() => { - getMyselfUser().then( - ({ - data: { - data: { userSettingList: userSettingList }, - }, - }) => { - const telegramUserIdSetting = userSettingList.find((setting: any) => setting.key === "telegram-user-id"); - if (telegramUserIdSetting) { - setTelegramUserId(JSON.parse(telegramUserIdSetting.value)); - } - } - ); - }, []); - const dailyReviewTimeOffsetOptions: number[] = [...Array(24).keys()]; const handleLocaleSelectChange = async (locale: Locale) => { @@ -63,7 +48,6 @@ const PreferencesSection = () => { userStore.upsertLocalSetting({ ...localSetting, dailyReviewTimeOffset: value }); }; - //enableAutoCollapse const handleAutoCollapseChanged = (event: React.ChangeEvent) => { userStore.upsertLocalSetting({ ...localSetting, enableAutoCollapse: event.target.checked }); }; @@ -75,7 +59,6 @@ const PreferencesSection = () => { } catch (error: any) { console.error(error); toast.error(error.response.data.message); - return; } }; @@ -155,9 +138,10 @@ const PreferencesSection = () => { -
-
+
+
{t("setting.preference-section.telegram-user-id")} +
diff --git a/web/src/components/Settings/SystemSection.tsx b/web/src/components/Settings/SystemSection.tsx index 421d0ab1..9b29421b 100644 --- a/web/src/components/Settings/SystemSection.tsx +++ b/web/src/components/Settings/SystemSection.tsx @@ -272,11 +272,10 @@ const SystemSection = () => {
- {t("setting.system-section.telegram-robot-token")} - +
+ {t("setting.system-section.telegram-robot-token")} + +
diff --git a/web/src/locales/zh-Hans.json b/web/src/locales/zh-Hans.json index ffab21d9..5432495a 100644 --- a/web/src/locales/zh-Hans.json +++ b/web/src/locales/zh-Hans.json @@ -333,7 +333,7 @@ "theme": "主题", "updated_ts": "更新时间" }, - "sso": "单点登陆(SSO)", + "sso": "SSO", "sso-section": { "authorization-endpoint": "授权端点(Authorization Endpoint)", "client-id": "客户端ID(Client ID)", diff --git a/web/src/store/module/user.ts b/web/src/store/module/user.ts index 468d5c08..29e39282 100644 --- a/web/src/store/module/user.ts +++ b/web/src/store/module/user.ts @@ -11,6 +11,7 @@ const defaultSetting: Setting = { locale: "en", appearance: getSystemColorScheme(), memoVisibility: "PRIVATE", + telegramUserId: "", }; const defaultLocalSetting: LocalSetting = { diff --git a/web/src/types/modules/setting.d.ts b/web/src/types/modules/setting.d.ts index 59c0b4ed..7a50662a 100644 --- a/web/src/types/modules/setting.d.ts +++ b/web/src/types/modules/setting.d.ts @@ -4,6 +4,7 @@ interface Setting { locale: Locale; appearance: Appearance; memoVisibility: Visibility; + telegramUserId: string; } interface LocalSetting { @@ -27,7 +28,12 @@ interface UserMemoVisibilitySetting { value: Visibility; } -type UserSetting = UserLocaleSetting | UserAppearanceSetting | UserMemoVisibilitySetting; +interface UserTelegramUserIdSetting { + key: "telegram-user-id"; + value: string; +} + +type UserSetting = UserLocaleSetting | UserAppearanceSetting | UserMemoVisibilitySetting | UserTelegramUserIdSetting; interface UserSettingUpsert { key: keyof Setting;