RegisterForm.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import React, { useState } from "react";
  2. import { Form, Input, Button, Checkbox } from "antd";
  3. import { UserOutlined, LockOutlined } from "@ant-design/icons";
  4. import { Link } from 'react-router-dom';
  5. // import { BrowserRouter as Router, Route } from 'react-router-dom';
  6. // import createHistory from 'history/createBrowserHistory';
  7. import getGQL from "../utils/getGQL";
  8. import "../styles/RegisterForm.css";
  9. // const history = createHistory()
  10. export default ({store, history}) => {
  11. const [form] = Form.useForm();
  12. const [login, setLogin] = useState("");
  13. const [password, setPassword] = useState("");
  14. const [confPassword, setConfPassword] = useState("");
  15. const onFinish = (values) => {
  16. console.log("Success:", values);
  17. };
  18. const onFinishFailed = (errorInfo) => {
  19. console.log("Failed:", errorInfo);
  20. };
  21. return (
  22. <div className="registerForm">
  23. <div>
  24. <Form
  25. name="basic"
  26. form={form}
  27. onFinish={onFinish}
  28. onFinishFailed={onFinishFailed}
  29. >
  30. <Form.Item onChange={(e)=> setLogin(e.target.value)}
  31. label="Username"
  32. name="username"
  33. value={login}
  34. rules={[
  35. {
  36. required: true,
  37. message: "Please input your username!",
  38. },
  39. ]}
  40. >
  41. <Input
  42. prefix={<UserOutlined className="site-form-item-icon" />}
  43. onChange={(e) => {
  44. form.setFieldsValue({ username: e.target.value });
  45. }}
  46. />
  47. </Form.Item>
  48. <Form.Item onChange={(e)=> setPassword(e.target.value)}
  49. label="Password"
  50. name="password"
  51. value={password}
  52. rules={[
  53. {
  54. required: true,
  55. message: "Please input your password!",
  56. },
  57. ]}
  58. >
  59. <Input.Password
  60. prefix={<LockOutlined className="site-form-item-icon" />}
  61. />
  62. </Form.Item>
  63. <Form.Item onChange={(e)=> setConfPassword(e.target.value)}
  64. label="Confirm password"
  65. name="Confirm password"
  66. value={confPassword}
  67. rules={[
  68. {
  69. required: true,
  70. message: "Please input your password!",
  71. },
  72. ]}
  73. >
  74. <Input.Password
  75. prefix={<LockOutlined className="site-form-item-icon" />}
  76. />
  77. </Form.Item>
  78. <Form.Item>
  79. <Button type="primary" htmlType="submit"
  80. disabled = {password !== confPassword ? true : false}
  81. onClick={async () => {
  82. await getGQL("/graphql")(
  83. `mutation User{
  84. createUser (login: "${login}", password: "${password}"){
  85. _id login
  86. }
  87. }`
  88. ).then((data) => {
  89. console.log(data);
  90. if (!data.errors && login && password) {
  91. history.push("/login");
  92. } else {
  93. }
  94. });
  95. }
  96. }
  97. type="primary"
  98. >
  99. Submit
  100. </Button>
  101. <Link to="/login" className="link-approval">Sign_in</Link>
  102. </Form.Item>
  103. </Form>
  104. </div>
  105. </div>
  106. );
  107. };