diff --git a/frontend/src/hooks/useClients.ts b/frontend/src/hooks/useClients.ts index 92c8077a1..a1780e3f6 100644 --- a/frontend/src/hooks/useClients.ts +++ b/frontend/src/hooks/useClients.ts @@ -350,13 +350,13 @@ export function useClients() { const attachMut = useMutation({ mutationFn: ({ email, inboundIds }: { email: string; inboundIds: number[] }) => - HttpUtil.post(`/panel/api/clients/${encodeURIComponent(email)}/attach`, { inboundIds }, JSON_HEADERS), + HttpUtil.post(`/panel/api/clients/${encodeURIComponent(email)}/attach`, { inboundIds }, { ...JSON_HEADERS, silentSuccess: true }), onSuccess: (msg) => { if (msg?.success) invalidateAll(); }, }); const setExternalLinksMut = useMutation({ mutationFn: ({ email, externalLinks }: { email: string; externalLinks: ExternalLinkInput[] }) => - HttpUtil.post(`/panel/api/clients/${encodeURIComponent(email)}/externalLinks`, { externalLinks }, JSON_HEADERS), + HttpUtil.post(`/panel/api/clients/${encodeURIComponent(email)}/externalLinks`, { externalLinks }, { ...JSON_HEADERS, silentSuccess: true }), onSuccess: (msg) => { if (msg?.success) invalidateAll(); }, }); @@ -370,7 +370,7 @@ export function useClients() { const detachMut = useMutation({ mutationFn: ({ email, inboundIds }: { email: string; inboundIds: number[] }) => - HttpUtil.post(`/panel/api/clients/${encodeURIComponent(email)}/detach`, { inboundIds }, JSON_HEADERS), + HttpUtil.post(`/panel/api/clients/${encodeURIComponent(email)}/detach`, { inboundIds }, { ...JSON_HEADERS, silentSuccess: true }), onSuccess: (msg) => { if (msg?.success) invalidateAll(); }, }); diff --git a/frontend/src/pages/clients/ClientsPage.tsx b/frontend/src/pages/clients/ClientsPage.tsx index 72e4b79e5..d4882c63f 100644 --- a/frontend/src/pages/clients/ClientsPage.tsx +++ b/frontend/src/pages/clients/ClientsPage.tsx @@ -685,16 +685,18 @@ export default function ClientsPage() { } const updateMsg = await update(meta.email, payload); if (!updateMsg?.success) return updateMsg; + const rawEmail = (payload as { email?: unknown }).email; + const emailKey = typeof rawEmail === 'string' && rawEmail.trim() ? rawEmail.trim() : meta.email; if (Array.isArray(meta.attach) && meta.attach.length > 0) { - const r = await attach(meta.email, meta.attach); + const r = await attach(emailKey, meta.attach); if (!r?.success) return r; } if (Array.isArray(meta.detach) && meta.detach.length > 0) { - const r = await detach(meta.email, meta.detach); + const r = await detach(emailKey, meta.detach); if (!r?.success) return r; } // Always replace the client's external links (an empty set clears them). - const r = await setExternalLinks(meta.email, meta.externalLinks); + const r = await setExternalLinks(emailKey, meta.externalLinks); if (!r?.success) return r; return updateMsg; }, [create, update, attach, detach, setExternalLinks]); diff --git a/frontend/src/utils/index.ts b/frontend/src/utils/index.ts index cec7ad2f0..1f2c04d81 100644 --- a/frontend/src/utils/index.ts +++ b/frontend/src/utils/index.ts @@ -19,6 +19,7 @@ export class Msg { export interface HttpOptions extends AxiosRequestConfig { silent?: boolean; + silentSuccess?: boolean; } export interface HttpModal { @@ -27,20 +28,24 @@ export interface HttpModal { } export class HttpUtil { - static _handleMsg(msg: unknown): void { + static _handleMsg(msg: unknown, silentSuccess = false): void { if (!(msg instanceof Msg) || msg.msg === '') { return; } - const messageType = msg.success ? 'success' : 'error'; - getMessage()[messageType](msg.msg); - if ( - msg.success && - msg.obj && - typeof msg.obj === 'object' && - (msg.obj as { nodePending?: unknown }).nodePending === true - ) { - getMessage().warning(i18next.t('pages.inbounds.toasts.savedNodeOfflineWillSync')); + if (msg.success) { + if (!silentSuccess) { + getMessage().success(msg.msg); + } + if ( + msg.obj && + typeof msg.obj === 'object' && + (msg.obj as { nodePending?: unknown }).nodePending === true + ) { + getMessage().warning(i18next.t('pages.inbounds.toasts.savedNodeOfflineWillSync')); + } + return; } + getMessage().error(msg.msg); } static _respToMsg(resp: AxiosResponse | undefined): Msg { @@ -59,11 +64,11 @@ export class HttpUtil { } static async get(url: string, params?: unknown, options: HttpOptions = {}): Promise> { - const { silent, ...axiosOpts } = options; + const { silent, silentSuccess, ...axiosOpts } = options; try { const resp = await axios.get(url, { params, ...axiosOpts }); const msg = this._respToMsg(resp) as Msg; - if (!silent) this._handleMsg(msg); + if (!silent) this._handleMsg(msg, silentSuccess); return msg; } catch (error) { console.error('GET request failed:', error); @@ -75,11 +80,11 @@ export class HttpUtil { } static async post(url: string, data?: unknown, options: HttpOptions = {}): Promise> { - const { silent, ...axiosOpts } = options; + const { silent, silentSuccess, ...axiosOpts } = options; try { const resp = await axios.post(url, data, axiosOpts); const msg = this._respToMsg(resp) as Msg; - if (!silent) this._handleMsg(msg); + if (!silent) this._handleMsg(msg, silentSuccess); return msg; } catch (error) { console.error('POST request failed:', error);