Skip to content

Commit

Permalink
refactor: update test message content
Browse files Browse the repository at this point in the history
  • Loading branch information
songquanpeng committed May 7, 2023
1 parent ea8f9bf commit 99bf0ca
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 28 deletions.
16 changes: 2 additions & 14 deletions web/src/components/ChannelsTable.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 (
<>
<Form onSubmit={searchChannels}>
Expand Down Expand Up @@ -269,7 +257,7 @@ const ChannelsTable = () => {
<Button
size={'small'}
onClick={() => {
test(channel.name).then();
testChannel(user.username, user.token, channel.name).then();
}}
>
测试
Expand Down
16 changes: 2 additions & 14 deletions web/src/components/PushSetting.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { useEffect, useState } from 'react';
import { Button, Form, Grid, Header, Message } from 'semantic-ui-react';
import { API, showError, showSuccess } from '../helpers';
import { API, showError, showSuccess, testChannel } from '../helpers';

const PushSetting = () => {
let [user, setUser] = useState({
Expand Down Expand Up @@ -79,18 +79,6 @@ const PushSetting = () => {
}
};

const test = async () => {
let res = await API.get(
`/push/${user.username}?token=${user.token}&channel=${user.channel}&title=消息推送服务&description=配置成功!`
);
const { success, message } = res.data;
if (success) {
showSuccess('测试消息已发送');
} else {
showError(message);
}
};

return (
<Grid columns={1}>
<Grid.Column>
Expand Down Expand Up @@ -118,7 +106,7 @@ const PushSetting = () => {
<Button onClick={() => submit('general')} loading={loading}>
保存
</Button>
<Button onClick={() => test('')}>测试</Button>
<Button onClick={() => testChannel(user.username, user.token, '')}>测试</Button>
</Form>
</Grid.Column>
</Grid>
Expand Down
19 changes: 19 additions & 0 deletions web/src/helpers/utils.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -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);
}
}

0 comments on commit 99bf0ca

Please sign in to comment.