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'; const EditChannel = () => { const params = useParams(); const userId = params.id; const [loading, setLoading] = useState(true); const [inputs, setInputs] = useState({ username: '', display_name: '', password: '', github_id: '', wechat_id: '', email: '', }); const { username, display_name, password, github_id, wechat_id, email } = inputs; const handleInputChange = (e, { name, value }) => { setInputs((inputs) => ({ ...inputs, [name]: value })); }; const loadUser = async () => { let res = undefined; if (userId) { res = await API.get(`/api/user/${userId}`); } else { res = await API.get(`/api/user/self`); } const { success, message, data } = res.data; if (success) { data.password = ''; setInputs(data); } else { showError(message); } setLoading(false); }; useEffect(() => { loadUser().then(); }, []); const submit = async () => { let res = undefined; if (userId) { res = await API.put(`/api/user/`, { ...inputs, id: parseInt(userId) }); } else { res = await API.put(`/api/user/self`, inputs); } const { success, message } = res.data; if (success) { showSuccess('用户信息更新成功!'); } else { showError(message); } }; return ( <>
更新用户信息
); }; export default EditChannel;