feat: add message editor (close #59)

This commit is contained in:
JustSong
2023-05-09 09:36:01 +08:00
parent 4796b7dd69
commit d8aaec9b84
6 changed files with 244 additions and 38 deletions
+5
View File
@@ -18,6 +18,11 @@ const headerButtons = [
to: '/message',
icon: 'mail',
},
{
name: '编辑',
to: '/editor',
icon: 'edit',
},
{
name: '通道',
to: '/channel',
+10
View File
@@ -11,6 +11,7 @@ import { API, openPage, showError, showSuccess, showWarning } from '../helpers';
import { ITEMS_PER_PAGE } from '../constants';
import { renderTimestamp } from '../helpers/render';
import { Link } from 'react-router-dom';
function renderStatus(status) {
switch (status) {
@@ -317,6 +318,15 @@ const MessagesTable = () => {
>
查看
</Button>
<Button
size={'small'}
primary
loading={loading}
as={Link}
to={'/editor/' + message.id}
>
编辑
</Button>
<Button
size={'small'}
color={'yellow'}
+16 -38
View File
@@ -1,6 +1,7 @@
import React, { useEffect, useState } from 'react';
import { Button, Form, Grid, Header, Message } from 'semantic-ui-react';
import { API, showError, showSuccess, testChannel } from '../helpers';
import { loadUser, loadUserChannels } from '../helpers/loader';
const PushSetting = () => {
let [user, setUser] = useState({
@@ -16,44 +17,19 @@ const PushSetting = () => {
setUser((inputs) => ({ ...inputs, [name]: value }));
};
const loadUser = async () => {
let res = await API.get(`/api/user/self`);
const { success, message, data } = res.data;
if (success) {
if (data.channel === '') {
data.channel = 'email';
}
if (data.token === ' ') {
data.token = '';
}
setUser(data);
} else {
showError(message);
}
setLoading(false);
};
const loadUserChannels = async () => {
let res = await API.get(`/api/channel?brief=true`);
const { success, message, data } = res.data;
if (success) {
data.forEach((channel) => {
channel.key = channel.name;
channel.text = channel.name;
channel.value = channel.name;
if (channel.description === '') {
channel.description = '无备注信息';
}
});
setChannels(data);
} else {
showError(message);
}
};
useEffect(() => {
loadUser().then();
loadUserChannels().then();
const loader = async () => {
let user = await loadUser();
if (user) {
setUser(user);
}
let channels = await loadUserChannels();
if (channels) {
setChannels(channels);
}
setLoading(false);
};
loader().then();
}, []);
const submit = async (which) => {
@@ -106,7 +82,9 @@ const PushSetting = () => {
<Button onClick={() => submit('general')} loading={loading}>
保存
</Button>
<Button onClick={() => testChannel(user.username, user.token, '')}>测试</Button>
<Button onClick={() => testChannel(user.username, user.token, '')}>
测试
</Button>
</Form>
</Grid.Column>
</Grid>