refactor: update test message content
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { Button, Form, Label, Pagination, Table } from 'semantic-ui-react';
|
import { Button, Form, Label, Pagination, Table } from 'semantic-ui-react';
|
||||||
import { Link } from 'react-router-dom';
|
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 { ITEMS_PER_PAGE } from '../constants';
|
||||||
import { renderChannel, renderTimestamp } from '../helpers/render';
|
import { renderChannel, renderTimestamp } from '../helpers/render';
|
||||||
@@ -154,18 +154,6 @@ const ChannelsTable = () => {
|
|||||||
setLoading(false);
|
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 (
|
return (
|
||||||
<>
|
<>
|
||||||
<Form onSubmit={searchChannels}>
|
<Form onSubmit={searchChannels}>
|
||||||
@@ -269,7 +257,7 @@ const ChannelsTable = () => {
|
|||||||
<Button
|
<Button
|
||||||
size={'small'}
|
size={'small'}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
test(channel.name).then();
|
testChannel(user.username, user.token, channel.name).then();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
测试
|
测试
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { Button, Form, Grid, Header, Message } from 'semantic-ui-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 = () => {
|
const PushSetting = () => {
|
||||||
let [user, setUser] = useState({
|
let [user, setUser] = useState({
|
||||||
@@ -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 (
|
return (
|
||||||
<Grid columns={1}>
|
<Grid columns={1}>
|
||||||
<Grid.Column>
|
<Grid.Column>
|
||||||
@@ -118,7 +106,7 @@ const PushSetting = () => {
|
|||||||
<Button onClick={() => submit('general')} loading={loading}>
|
<Button onClick={() => submit('general')} loading={loading}>
|
||||||
保存
|
保存
|
||||||
</Button>
|
</Button>
|
||||||
<Button onClick={() => test('')}>测试</Button>
|
<Button onClick={() => testChannel(user.username, user.token, '')}>测试</Button>
|
||||||
</Form>
|
</Form>
|
||||||
</Grid.Column>
|
</Grid.Column>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { toast } from 'react-toastify';
|
import { toast } from 'react-toastify';
|
||||||
import { toastConstants } from '../constants';
|
import { toastConstants } from '../constants';
|
||||||
|
import { API } from './api';
|
||||||
|
|
||||||
export function isAdmin() {
|
export function isAdmin() {
|
||||||
let user = localStorage.getItem('user');
|
let user = localStorage.getItem('user');
|
||||||
@@ -153,3 +154,21 @@ export function downloadTextAsFile(text, filename) {
|
|||||||
a.download = filename;
|
a.download = filename;
|
||||||
a.click();
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user