From f29a94339b0b5615160af1bb7a7f20ec690b3043 Mon Sep 17 00:00:00 2001 From: Rogee Date: Fri, 11 Sep 2026 11:28:46 +0800 Subject: [PATCH] fix(frontend): localize agent creation errors --- .../dashboard/i18n/locale/en/agentMgmt.json | 1 + .../i18n/locale/zh_CN/agentMgmt.json | 1 + .../dashboard/settings/agents/AddAgent.vue | 24 ++++++++----------- 3 files changed, 12 insertions(+), 14 deletions(-) diff --git a/frontend/app/javascript/dashboard/i18n/locale/en/agentMgmt.json b/frontend/app/javascript/dashboard/i18n/locale/en/agentMgmt.json index b0fa3cc3..0d54a762 100644 --- a/frontend/app/javascript/dashboard/i18n/locale/en/agentMgmt.json +++ b/frontend/app/javascript/dashboard/i18n/locale/en/agentMgmt.json @@ -46,6 +46,7 @@ "API": { "SUCCESS_MESSAGE": "Agent added successfully", "EXIST_MESSAGE": "Agent email already in use, Please try another email address", + "LIMIT_MESSAGE": "Agent limit reached. Please upgrade your plan or add more seats.", "ERROR_MESSAGE": "Could not connect to Woot Server, Please try again later" } }, diff --git a/frontend/app/javascript/dashboard/i18n/locale/zh_CN/agentMgmt.json b/frontend/app/javascript/dashboard/i18n/locale/zh_CN/agentMgmt.json index 2a1f8f05..1b41eecc 100644 --- a/frontend/app/javascript/dashboard/i18n/locale/zh_CN/agentMgmt.json +++ b/frontend/app/javascript/dashboard/i18n/locale/zh_CN/agentMgmt.json @@ -46,6 +46,7 @@ "API": { "SUCCESS_MESSAGE": "添加客服成功", "EXIST_MESSAGE": "该邮箱已被注册,请输入新的电子邮箱", + "LIMIT_MESSAGE": "客服数量已达到上限,请升级套餐或增加客服名额", "ERROR_MESSAGE": "无法连接服务器,请稍后再试" } }, diff --git a/frontend/app/javascript/dashboard/routes/dashboard/settings/agents/AddAgent.vue b/frontend/app/javascript/dashboard/routes/dashboard/settings/agents/AddAgent.vue index 20dc9449..706eb74b 100644 --- a/frontend/app/javascript/dashboard/routes/dashboard/settings/agents/AddAgent.vue +++ b/frontend/app/javascript/dashboard/routes/dashboard/settings/agents/AddAgent.vue @@ -90,23 +90,19 @@ const addAgent = async () => { emit('close'); } } catch (error) { - const { - response: { - data: { - error: errorResponse = '', - attributes: attributes = [], - message: attrError = '', - } = {}, - } = {}, - } = error; + const status = error?.response?.status; + const data = error?.response?.data; + const attributes = data?.attributes || []; - let errorMessage = ''; - if (error?.response?.status === 422 && !attributes.includes('base')) { - errorMessage = t('AGENT_MGMT.ADD.API.EXIST_MESSAGE'); + if (status === 422 && !attributes.includes('base')) { + useAlert(t('AGENT_MGMT.ADD.API.EXIST_MESSAGE')); + } else if (status === 402 || data?.error?.code === 'PAYMENT_REQUIRED') { + useAlert(t('AGENT_MGMT.ADD.API.LIMIT_MESSAGE')); } else { - errorMessage = t('AGENT_MGMT.ADD.API.ERROR_MESSAGE'); + // Never pass the structured API error object to the toast. It renders as + // raw JSON and the backend message is not localized. + useAlert(t('AGENT_MGMT.ADD.API.ERROR_MESSAGE')); } - useAlert(errorResponse || attrError || errorMessage); } };