From b12f4ef9d8f176828d998730ef4a9ce3676b4090 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Mon, 30 Sep 2024 17:44:15 +0800 Subject: [PATCH 1/2] feat: add login expiration notification Signed-off-by: Ryan Wang --- ui/src/locales/en.yaml | 2 ++ ui/src/locales/zh-CN.yaml | 2 ++ ui/src/locales/zh-TW.yaml | 2 ++ ui/src/setup/setupApiClient.ts | 21 +++++++++++++++++---- 4 files changed, 23 insertions(+), 4 deletions(-) diff --git a/ui/src/locales/en.yaml b/ui/src/locales/en.yaml index b56a699ba4..2ae7613718 100644 --- a/ui/src/locales/en.yaml +++ b/ui/src/locales/en.yaml @@ -1748,11 +1748,13 @@ core: titles: tip: Tip warning: Warning + login_expired: Login expired descriptions: cannot_be_recovered: This operation is irreversible. editor_not_found: >- No editor found that matches the {raw_type} format. Please check if the editor plugin has been installed. + login_expired: The current session has expired. Click Confirm to go to the login page. Please ensure that the current content is saved. You can click Cancel to manually copy any unsaved content. filters: results: keyword: "Keyword: {keyword}" diff --git a/ui/src/locales/zh-CN.yaml b/ui/src/locales/zh-CN.yaml index ab84cece98..4f228481be 100644 --- a/ui/src/locales/zh-CN.yaml +++ b/ui/src/locales/zh-CN.yaml @@ -1635,9 +1635,11 @@ core: titles: tip: 提示 warning: 警告 + login_expired: 登录已过期 descriptions: cannot_be_recovered: 该操作不可恢复。 editor_not_found: 未找到符合 {raw_type} 格式的编辑器,请检查是否已安装编辑器插件。 + login_expired: 当前登录已过期,点击确定跳转到登录页面,请确保当前内容已保存,你可以点击取消手动复制未保存的内容。 filters: results: keyword: 关键词:{keyword} diff --git a/ui/src/locales/zh-TW.yaml b/ui/src/locales/zh-TW.yaml index 45b8cafa9b..b479018acc 100644 --- a/ui/src/locales/zh-TW.yaml +++ b/ui/src/locales/zh-TW.yaml @@ -1616,9 +1616,11 @@ core: titles: tip: 提示 warning: 警告 + login_expired: 登入已過期 descriptions: cannot_be_recovered: 該操作不可恢復。 editor_not_found: 未找到符合 {raw_type} 格式的編輯器,請檢查是否已安裝編輯器插件。 + login_expired: 當前登入已過期,點擊確定跳轉到登入頁面,請確保當前內容已保存,你可以點擊取消手動複製未保存的內容。 filters: results: keyword: 關鍵字:{keyword} diff --git a/ui/src/setup/setupApiClient.ts b/ui/src/setup/setupApiClient.ts index b4525e8cb6..c14a5653e5 100644 --- a/ui/src/setup/setupApiClient.ts +++ b/ui/src/setup/setupApiClient.ts @@ -1,6 +1,6 @@ import { i18n } from "@/locales"; import { axiosInstance } from "@halo-dev/api-client"; -import { Toast } from "@halo-dev/components"; +import { Dialog, Toast } from "@halo-dev/components"; import type { AxiosError } from "axios"; export interface ProblemDetail { @@ -44,9 +44,22 @@ export function setupApiClient() { const { title, detail } = errorResponse.data; if (status === 401) { - Toast.warning(i18n.global.t("core.common.toast.login_expired")); - - // TODO: show dialog + Dialog.warning({ + title: i18n.global.t("core.common.dialog.titles.login_expired"), + description: i18n.global.t( + "core.common.dialog.descriptions.login_expired" + ), + confirmType: "secondary", + confirmText: i18n.global.t("core.common.buttons.confirm"), + cancelText: i18n.global.t("core.common.buttons.cancel"), + uniqueId: "login_expired", + onConfirm: () => { + const currentPath = `${location.pathname}${location.search}`; + location.href = `/login?redirect_uri=${encodeURIComponent( + currentPath + )}`; + }, + }); return Promise.reject(error); } From d351164d934475ecec6ef26f4e3c023203c78fe7 Mon Sep 17 00:00:00 2001 From: Ryan Wang Date: Mon, 30 Sep 2024 18:29:27 +0800 Subject: [PATCH 2/2] Update i18n --- ui/src/locales/zh-CN.yaml | 2 +- ui/src/locales/zh-TW.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ui/src/locales/zh-CN.yaml b/ui/src/locales/zh-CN.yaml index 4f228481be..92783f828f 100644 --- a/ui/src/locales/zh-CN.yaml +++ b/ui/src/locales/zh-CN.yaml @@ -1639,7 +1639,7 @@ core: descriptions: cannot_be_recovered: 该操作不可恢复。 editor_not_found: 未找到符合 {raw_type} 格式的编辑器,请检查是否已安装编辑器插件。 - login_expired: 当前登录已过期,点击确定跳转到登录页面,请确保当前内容已保存,你可以点击取消手动复制未保存的内容。 + login_expired: 当前登录已过期,点击确定跳转到登录页面,请确保当前内容已保存,你可以点击取消之后手动复制未保存的内容。 filters: results: keyword: 关键词:{keyword} diff --git a/ui/src/locales/zh-TW.yaml b/ui/src/locales/zh-TW.yaml index b479018acc..3c82339717 100644 --- a/ui/src/locales/zh-TW.yaml +++ b/ui/src/locales/zh-TW.yaml @@ -1620,7 +1620,7 @@ core: descriptions: cannot_be_recovered: 該操作不可恢復。 editor_not_found: 未找到符合 {raw_type} 格式的編輯器,請檢查是否已安裝編輯器插件。 - login_expired: 當前登入已過期,點擊確定跳轉到登入頁面,請確保當前內容已保存,你可以點擊取消手動複製未保存的內容。 + login_expired: 當前登入已過期,點擊確定跳轉到登入頁面,請確保當前內容已保存,你可以點擊取消之後手動複製未保存的內容。 filters: results: keyword: 關鍵字:{keyword}