PasswordResetConfirm.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import React, { useEffect, useState } from 'react';
  2. import { Button, Form, Grid, Header, Image, Segment } from 'semantic-ui-react';
  3. import { API, copy, showError, showSuccess } from '../helpers';
  4. import { useSearchParams } from 'react-router-dom';
  5. const PasswordResetConfirm = () => {
  6. const [inputs, setInputs] = useState({
  7. email: '',
  8. token: '',
  9. });
  10. const { email, token } = inputs;
  11. const [loading, setLoading] = useState(false);
  12. const [searchParams, setSearchParams] = useSearchParams();
  13. useEffect(() => {
  14. let token = searchParams.get('token');
  15. let email = searchParams.get('email');
  16. setInputs({
  17. token,
  18. email,
  19. });
  20. }, []);
  21. async function handleSubmit(e) {
  22. if (!email) return;
  23. setLoading(true);
  24. const res = await API.post(`/api/user/reset`, {
  25. email,
  26. token,
  27. });
  28. const { success, message } = res.data;
  29. if (success) {
  30. let password = res.data.data;
  31. await copy(password);
  32. showSuccess(`密码已重置并已复制到剪贴板:${password}`);
  33. } else {
  34. showError(message);
  35. }
  36. setLoading(false);
  37. }
  38. return (
  39. <Grid textAlign='center' style={{ marginTop: '48px' }}>
  40. <Grid.Column style={{ maxWidth: 450 }}>
  41. <Header as='h2' color='' textAlign='center'>
  42. <Image src='/logo.png' /> 密码重置确认
  43. </Header>
  44. <Form size='large'>
  45. <Segment>
  46. <Form.Input
  47. fluid
  48. icon='mail'
  49. iconPosition='left'
  50. placeholder='邮箱地址'
  51. name='email'
  52. value={email}
  53. readOnly
  54. />
  55. <Button
  56. color=''
  57. fluid
  58. size='large'
  59. onClick={handleSubmit}
  60. loading={loading}
  61. >
  62. 提交
  63. </Button>
  64. </Segment>
  65. </Form>
  66. </Grid.Column>
  67. </Grid>
  68. );
  69. };
  70. export default PasswordResetConfirm;