2023-04-23 04:43:10 +00:00
|
|
|
import React, { useEffect, useState } from 'react';
|
|
|
|
import { Button, Form, Header, Segment } from 'semantic-ui-react';
|
|
|
|
import { useParams } from 'react-router-dom';
|
|
|
|
import { API, showError, showSuccess } from '../../helpers';
|
2023-04-23 07:42:23 +00:00
|
|
|
import { CHANNEL_OPTIONS } from '../../constants';
|
2023-04-23 04:43:10 +00:00
|
|
|
|
|
|
|
const EditChannel = () => {
|
|
|
|
const params = useParams();
|
2023-04-23 07:42:23 +00:00
|
|
|
const channelId = params.id;
|
2023-04-23 04:43:10 +00:00
|
|
|
const [loading, setLoading] = useState(true);
|
|
|
|
const [inputs, setInputs] = useState({
|
2023-04-23 07:42:23 +00:00
|
|
|
name: '',
|
|
|
|
key: '',
|
|
|
|
type: 1,
|
2023-04-23 04:43:10 +00:00
|
|
|
});
|
|
|
|
const handleInputChange = (e, { name, value }) => {
|
|
|
|
setInputs((inputs) => ({ ...inputs, [name]: value }));
|
|
|
|
};
|
|
|
|
|
2023-04-23 07:42:23 +00:00
|
|
|
const loadChannel = async () => {
|
|
|
|
let res = await API.get(`/api/channel/${channelId}`);
|
2023-04-23 04:43:10 +00:00
|
|
|
const { success, message, data } = res.data;
|
|
|
|
if (success) {
|
|
|
|
data.password = '';
|
|
|
|
setInputs(data);
|
|
|
|
} else {
|
|
|
|
showError(message);
|
|
|
|
}
|
|
|
|
setLoading(false);
|
|
|
|
};
|
|
|
|
useEffect(() => {
|
2023-04-23 07:42:23 +00:00
|
|
|
loadChannel().then();
|
2023-04-23 04:43:10 +00:00
|
|
|
}, []);
|
|
|
|
|
|
|
|
const submit = async () => {
|
2023-04-23 07:42:23 +00:00
|
|
|
let res = await API.put(`/api/channel/`, { ...inputs, id: parseInt(channelId) });
|
2023-04-23 04:43:10 +00:00
|
|
|
const { success, message } = res.data;
|
|
|
|
if (success) {
|
2023-04-23 07:42:23 +00:00
|
|
|
showSuccess('渠道更新成功!');
|
2023-04-23 04:43:10 +00:00
|
|
|
} else {
|
|
|
|
showError(message);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<Segment loading={loading}>
|
2023-04-23 07:42:23 +00:00
|
|
|
<Header as='h3'>更新渠道信息</Header>
|
2023-04-23 04:43:10 +00:00
|
|
|
<Form autoComplete='off'>
|
|
|
|
<Form.Field>
|
2023-04-23 07:42:23 +00:00
|
|
|
<Form.Select
|
|
|
|
label='类型'
|
|
|
|
name='type'
|
|
|
|
options={CHANNEL_OPTIONS}
|
|
|
|
value={inputs.type}
|
2023-04-23 04:43:10 +00:00
|
|
|
onChange={handleInputChange}
|
|
|
|
/>
|
|
|
|
</Form.Field>
|
|
|
|
<Form.Field>
|
|
|
|
<Form.Input
|
2023-04-23 07:42:23 +00:00
|
|
|
label='名称'
|
|
|
|
name='name'
|
|
|
|
placeholder={'请输入新的名称'}
|
2023-04-23 04:43:10 +00:00
|
|
|
onChange={handleInputChange}
|
2023-04-23 07:42:23 +00:00
|
|
|
value={inputs.name}
|
2023-04-23 04:43:10 +00:00
|
|
|
autoComplete='off'
|
|
|
|
/>
|
|
|
|
</Form.Field>
|
|
|
|
<Form.Field>
|
|
|
|
<Form.Input
|
2023-04-23 07:42:23 +00:00
|
|
|
label='密钥'
|
|
|
|
name='key'
|
|
|
|
placeholder={'请输入新的密钥'}
|
2023-04-23 04:43:10 +00:00
|
|
|
onChange={handleInputChange}
|
2023-04-23 07:42:23 +00:00
|
|
|
value={inputs.key}
|
|
|
|
// type='password'
|
2023-04-23 04:43:10 +00:00
|
|
|
autoComplete='off'
|
|
|
|
/>
|
|
|
|
</Form.Field>
|
|
|
|
<Button onClick={submit}>提交</Button>
|
|
|
|
</Form>
|
|
|
|
</Segment>
|
|
|
|
</>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default EditChannel;
|