From 99bf0ca127e363651bb98ab0cd047b69f295b11e Mon Sep 17 00:00:00 2001 From: JustSong Date: Sun, 7 May 2023 13:32:47 +0800 Subject: [PATCH] refactor: update test message content --- web/src/components/ChannelsTable.js | 16 ++-------------- web/src/components/PushSetting.js | 16 ++-------------- web/src/helpers/utils.js | 19 +++++++++++++++++++ 3 files changed, 23 insertions(+), 28 deletions(-) diff --git a/web/src/components/ChannelsTable.js b/web/src/components/ChannelsTable.js index 8ebcf54f8..6174ba540 100644 --- a/web/src/components/ChannelsTable.js +++ b/web/src/components/ChannelsTable.js @@ -1,7 +1,7 @@ import React, { useEffect, useState } from 'react'; import { Button, Form, Label, Pagination, Table } from 'semantic-ui-react'; import { Link } from 'react-router-dom'; -import { API, showError, showSuccess } from '../helpers'; +import { API, showError, showSuccess, testChannel } from '../helpers'; import { ITEMS_PER_PAGE } from '../constants'; import { renderChannel, renderTimestamp } from '../helpers/render'; @@ -154,18 +154,6 @@ const ChannelsTable = () => { setLoading(false); }; - const test = async (channel) => { - let res = await API.get( - `/push/${user.username}?token=${user.token}&channel=${channel}&title=消息推送服务&description=配置成功!` - ); - const { success, message } = res.data; - if (success) { - showSuccess('测试消息已发送'); - } else { - showError(message); - } - }; - return ( <>
@@ -269,7 +257,7 @@ const ChannelsTable = () => { - +
diff --git a/web/src/helpers/utils.js b/web/src/helpers/utils.js index e24762631..39aa3b557 100644 --- a/web/src/helpers/utils.js +++ b/web/src/helpers/utils.js @@ -1,5 +1,6 @@ import { toast } from 'react-toastify'; import { toastConstants } from '../constants'; +import { API } from './api'; export function isAdmin() { let user = localStorage.getItem('user'); @@ -152,4 +153,22 @@ export function downloadTextAsFile(text, filename) { a.href = url; a.download = filename; a.click(); +} + +export async function testChannel(username, token, channel) { + let res = await API.post( + `/push/${username}/`, { + token, + channel, + title: '消息推送服务', + description: channel === "" ? '消息推送通道测试成功' : `消息推送通道 ${channel} 测试成功`, + content: '欢迎使用消息推送服务,这是一条测试消息。' + } + ); + const { success, message } = res.data; + if (success) { + showSuccess('测试消息已发送'); + } else { + showError(message); + } } \ No newline at end of file