Files
message-pusher/web/src/components/PasswordResetForm.js
T

66 lines
1.7 KiB
JavaScript
Raw Normal View History

2022-11-11 15:35:02 +08:00
import React, { useState } from 'react';
import { Button, Form, Grid, Header, Image, Segment } from 'semantic-ui-react';
import { API, showError, showSuccess } from '../helpers';
const PasswordResetForm = () => {
const [inputs, setInputs] = useState({
email: '',
});
const { email } = inputs;
const [loading, setLoading] = useState(false);
function handleChange(e) {
const { name, value } = e.target;
setInputs((inputs) => ({ ...inputs, [name]: value }));
}
async function handleSubmit(e) {
if (!email) return;
setLoading(true);
const res = await API.get(`/api/reset_password?email=${email}`);
const { success, message } = res.data;
if (success) {
showSuccess('重置邮件发送成功,请检查邮箱!');
setInputs({ ...inputs, email: '' });
} else {
showError(message);
}
setLoading(false);
}
return (
2022-11-11 22:32:22 +08:00
<Grid textAlign='center' style={{ marginTop: '48px' }}>
2022-11-11 15:35:02 +08:00
<Grid.Column style={{ maxWidth: 450 }}>
2022-11-11 22:32:22 +08:00
<Header as='h2' color='telegram' textAlign='center'>
<Image src='/logo.png' /> 密码重置
2022-11-11 15:35:02 +08:00
</Header>
2022-11-11 22:32:22 +08:00
<Form size='large'>
2022-11-11 15:35:02 +08:00
<Segment>
<Form.Input
fluid
2022-11-11 22:32:22 +08:00
icon='mail'
iconPosition='left'
placeholder='邮箱地址'
name='email'
2022-11-11 15:35:02 +08:00
value={email}
onChange={handleChange}
/>
<Button
2022-11-11 22:32:22 +08:00
color='teal'
2022-11-11 15:35:02 +08:00
fluid
2022-11-11 22:32:22 +08:00
size='large'
2022-11-11 15:35:02 +08:00
onClick={handleSubmit}
loading={loading}
>
提交
</Button>
</Segment>
</Form>
</Grid.Column>
</Grid>
);
};
export default PasswordResetForm;