mirror of
https://github.com/usememos/memos.git
synced 2024-12-24 20:01:48 +03:00
chore: update telegram bot related section (#1750)
* chore: update telegram bot related section * chore: update
This commit is contained in:
parent
8628d1e4b2
commit
dbe8aa1d3a
@ -1,13 +1,13 @@
|
|||||||
import { Input, Button, Divider, Switch, Option, Select } from "@mui/joy";
|
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 { toast } from "react-hot-toast";
|
||||||
import { getMyselfUser } from "@/helpers/api";
|
|
||||||
import React from "react";
|
import React from "react";
|
||||||
import { useTranslation } from "react-i18next";
|
import { useTranslation } from "react-i18next";
|
||||||
import { useGlobalStore, useUserStore } from "@/store/module";
|
import { useGlobalStore, useUserStore } from "@/store/module";
|
||||||
import { VISIBILITY_SELECTOR_ITEMS } from "@/helpers/consts";
|
import { VISIBILITY_SELECTOR_ITEMS } from "@/helpers/consts";
|
||||||
import AppearanceSelect from "../AppearanceSelect";
|
import AppearanceSelect from "../AppearanceSelect";
|
||||||
import LocaleSelect from "../LocaleSelect";
|
import LocaleSelect from "../LocaleSelect";
|
||||||
|
import HelpButton from "../kit/HelpButton";
|
||||||
import "@/less/settings/preferences-section.less";
|
import "@/less/settings/preferences-section.less";
|
||||||
|
|
||||||
const PreferencesSection = () => {
|
const PreferencesSection = () => {
|
||||||
@ -16,7 +16,7 @@ const PreferencesSection = () => {
|
|||||||
const userStore = useUserStore();
|
const userStore = useUserStore();
|
||||||
const { appearance, locale } = globalStore.state;
|
const { appearance, locale } = globalStore.state;
|
||||||
const { setting, localSetting } = userStore.state.user as User;
|
const { setting, localSetting } = userStore.state.user as User;
|
||||||
const [telegramUserId, setTelegramUserId] = useState<string>("");
|
const [telegramUserId, setTelegramUserId] = useState<string>(setting.telegramUserId);
|
||||||
const visibilitySelectorItems = VISIBILITY_SELECTOR_ITEMS.map((item) => {
|
const visibilitySelectorItems = VISIBILITY_SELECTOR_ITEMS.map((item) => {
|
||||||
return {
|
return {
|
||||||
value: item.value,
|
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 dailyReviewTimeOffsetOptions: number[] = [...Array(24).keys()];
|
||||||
|
|
||||||
const handleLocaleSelectChange = async (locale: Locale) => {
|
const handleLocaleSelectChange = async (locale: Locale) => {
|
||||||
@ -63,7 +48,6 @@ const PreferencesSection = () => {
|
|||||||
userStore.upsertLocalSetting({ ...localSetting, dailyReviewTimeOffset: value });
|
userStore.upsertLocalSetting({ ...localSetting, dailyReviewTimeOffset: value });
|
||||||
};
|
};
|
||||||
|
|
||||||
//enableAutoCollapse
|
|
||||||
const handleAutoCollapseChanged = (event: React.ChangeEvent<HTMLInputElement>) => {
|
const handleAutoCollapseChanged = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
userStore.upsertLocalSetting({ ...localSetting, enableAutoCollapse: event.target.checked });
|
userStore.upsertLocalSetting({ ...localSetting, enableAutoCollapse: event.target.checked });
|
||||||
};
|
};
|
||||||
@ -75,7 +59,6 @@ const PreferencesSection = () => {
|
|||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
toast.error(error.response.data.message);
|
toast.error(error.response.data.message);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -155,9 +138,10 @@ const PreferencesSection = () => {
|
|||||||
|
|
||||||
<Divider className="!mt-3 !my-4" />
|
<Divider className="!mt-3 !my-4" />
|
||||||
|
|
||||||
<div className="form-label">
|
<div className="mb-2 w-full flex flex-row justify-between items-center">
|
||||||
<div className="flex flex-row items-center">
|
<div className="w-auto flex items-center">
|
||||||
<span className="text-sm mr-1">{t("setting.preference-section.telegram-user-id")}</span>
|
<span className="text-sm mr-1">{t("setting.preference-section.telegram-user-id")}</span>
|
||||||
|
<HelpButton icon="help" url="https://usememos.com/docs/integration/telegram-bot" />
|
||||||
</div>
|
</div>
|
||||||
<Button onClick={handleSaveTelegramUserId}>{t("common.save")}</Button>
|
<Button onClick={handleSaveTelegramUserId}>{t("common.save")}</Button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -272,11 +272,10 @@ const SystemSection = () => {
|
|||||||
<Divider className="!mt-3 !my-4" />
|
<Divider className="!mt-3 !my-4" />
|
||||||
<div className="form-label">
|
<div className="form-label">
|
||||||
<div className="flex flex-row items-center">
|
<div className="flex flex-row items-center">
|
||||||
|
<div className="w-auto flex items-center">
|
||||||
<span className="text-sm mr-1">{t("setting.system-section.telegram-robot-token")}</span>
|
<span className="text-sm mr-1">{t("setting.system-section.telegram-robot-token")}</span>
|
||||||
<HelpButton
|
<HelpButton icon="help" url="https://usememos.com/docs/integration/telegram-bot" />
|
||||||
hint={t("setting.system-section.telegram-robot-token-description")}
|
</div>
|
||||||
url="https://core.telegram.org/bots#how-do-i-create-a-bot"
|
|
||||||
/>
|
|
||||||
</div>
|
</div>
|
||||||
<Button onClick={handleSaveTelegramRobotToken}>{t("common.save")}</Button>
|
<Button onClick={handleSaveTelegramRobotToken}>{t("common.save")}</Button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -333,7 +333,7 @@
|
|||||||
"theme": "主题",
|
"theme": "主题",
|
||||||
"updated_ts": "更新时间"
|
"updated_ts": "更新时间"
|
||||||
},
|
},
|
||||||
"sso": "单点登陆(SSO)",
|
"sso": "SSO",
|
||||||
"sso-section": {
|
"sso-section": {
|
||||||
"authorization-endpoint": "授权端点(Authorization Endpoint)",
|
"authorization-endpoint": "授权端点(Authorization Endpoint)",
|
||||||
"client-id": "客户端ID(Client ID)",
|
"client-id": "客户端ID(Client ID)",
|
||||||
|
@ -11,6 +11,7 @@ const defaultSetting: Setting = {
|
|||||||
locale: "en",
|
locale: "en",
|
||||||
appearance: getSystemColorScheme(),
|
appearance: getSystemColorScheme(),
|
||||||
memoVisibility: "PRIVATE",
|
memoVisibility: "PRIVATE",
|
||||||
|
telegramUserId: "",
|
||||||
};
|
};
|
||||||
|
|
||||||
const defaultLocalSetting: LocalSetting = {
|
const defaultLocalSetting: LocalSetting = {
|
||||||
|
8
web/src/types/modules/setting.d.ts
vendored
8
web/src/types/modules/setting.d.ts
vendored
@ -4,6 +4,7 @@ interface Setting {
|
|||||||
locale: Locale;
|
locale: Locale;
|
||||||
appearance: Appearance;
|
appearance: Appearance;
|
||||||
memoVisibility: Visibility;
|
memoVisibility: Visibility;
|
||||||
|
telegramUserId: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface LocalSetting {
|
interface LocalSetting {
|
||||||
@ -27,7 +28,12 @@ interface UserMemoVisibilitySetting {
|
|||||||
value: Visibility;
|
value: Visibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
type UserSetting = UserLocaleSetting | UserAppearanceSetting | UserMemoVisibilitySetting;
|
interface UserTelegramUserIdSetting {
|
||||||
|
key: "telegram-user-id";
|
||||||
|
value: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
type UserSetting = UserLocaleSetting | UserAppearanceSetting | UserMemoVisibilitySetting | UserTelegramUserIdSetting;
|
||||||
|
|
||||||
interface UserSettingUpsert {
|
interface UserSettingUpsert {
|
||||||
key: keyof Setting;
|
key: keyof Setting;
|
||||||
|
Loading…
Reference in New Issue
Block a user