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

77 lines
1.9 KiB
JavaScript
Raw Normal View History

2022-11-11 15:35:02 +08:00
import React, { useEffect, useState } from 'react';
import { Button, Form, Grid, Header, Image, Segment } from 'semantic-ui-react';
import { API, copy, showError, showSuccess } from '../helpers';
import { useSearchParams } from 'react-router-dom';
const PasswordResetConfirm = () => {
const [inputs, setInputs] = useState({
email: '',
2022-11-11 22:32:22 +08:00
token: '',
2022-11-11 15:35:02 +08:00
});
const { email, token } = inputs;
const [loading, setLoading] = useState(false);
const [searchParams, setSearchParams] = useSearchParams();
useEffect(() => {
let token = searchParams.get('token');
2022-11-11 22:32:22 +08:00
let email = searchParams.get('email');
2022-11-11 15:35:02 +08:00
setInputs({
token,
2022-11-11 22:32:22 +08:00
email,
});
2022-11-11 15:35:02 +08:00
}, []);
async function handleSubmit(e) {
if (!email) return;
setLoading(true);
const res = await API.post(`/api/user/reset`, {
email,
2022-11-11 22:32:22 +08:00
token,
2022-11-11 15:35:02 +08:00
});
const { success, message } = res.data;
if (success) {
let password = res.data.data;
await copy(password);
2022-11-22 11:04:06 +08:00
showSuccess(`密码已重置并已复制到剪贴板:${password}`);
2022-11-11 15:35:02 +08:00
} else {
showError(message);
}
setLoading(false);
}
return (
<Grid textAlign='center' style={{ marginTop: '48px' }}>
<Grid.Column style={{ maxWidth: 450 }}>
2022-11-11 22:32:22 +08:00
<Header as='h2' color='telegram' textAlign='center'>
2022-11-11 15:35:02 +08:00
<Image src='/logo.png' /> 密码重置确认
</Header>
<Form size='large'>
<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}
readOnly
/>
<Button
2022-11-22 11:04:06 +08:00
color='telegram'
2022-11-11 15:35:02 +08:00
fluid
size='large'
onClick={handleSubmit}
loading={loading}
>
提交
</Button>
</Segment>
</Form>
</Grid.Column>
</Grid>
);
};
export default PasswordResetConfirm;