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 {getGQL, url, headers }from "../utils/getGQL";
  7. import "../styles/RegisterForm.css";
  8. // const history = createHistory()
  9. export default ({store, history}) => {
  10. const [form] = Form.useForm();
  11. const [login, setLogin] = useState("");
  12. const [password, setPassword] = useState("");
  13. const [confPassword, setConfPassword] = useState("");
  14. const onFinish = (values) => {
  15. console.log("Success:", values);
  16. };
  17. const onFinishFailed = (errorInfo) => {
  18. console.log("Failed:", errorInfo);
  19. };
  20. return (
  21. <div className="registerForm">
  22. <div>
  23. <Form
  24. name="basic"
  25. form={form}
  26. onFinish={onFinish}
  27. onFinishFailed={onFinishFailed}
  28. >
  29. <Form.Item onChange={(e)=> setLogin(e.target.value)}
  30. label="Username"
  31. name="username"
  32. value={login}
  33. rules={[
  34. {
  35. required: true,
  36. message: "Please input your username!",
  37. },
  38. ]}
  39. >
  40. <Input
  41. prefix={<UserOutlined className="site-form-item-icon" />}
  42. onChange={(e) => {
  43. form.setFieldsValue({ username: e.target.value });
  44. }}
  45. />
  46. </Form.Item>
  47. <Form.Item onChange={(e)=> setPassword(e.target.value)}
  48. label="Password"
  49. name="password"
  50. value={password}
  51. rules={[
  52. {
  53. required: true,
  54. message: "Please input your password!",
  55. },
  56. ]}
  57. >
  58. <Input.Password
  59. prefix={<LockOutlined className="site-form-item-icon" />}
  60. />
  61. </Form.Item>
  62. <Form.Item onChange={(e)=> setConfPassword(e.target.value)}
  63. label="Confirm password"
  64. name="Confirm password"
  65. value={confPassword}
  66. rules={[
  67. {
  68. required: true,
  69. message: "Please input your password!",
  70. },
  71. ]}
  72. >
  73. <Input.Password
  74. prefix={<LockOutlined className="site-form-item-icon" />}
  75. />
  76. </Form.Item>
  77. <Form.Item>
  78. <Button type="primary" htmlType="submit"
  79. disabled = {password !== confPassword}
  80. onClick={async () => {
  81. // await getGQL("/graphql")(
  82. let response = await getGQL(url)(
  83. `mutation User{
  84. createUser (login: "${login}", password: "${password}"){
  85. _id login
  86. }
  87. }`
  88. ).then((response) => {
  89. console.log(response);
  90. if (!response.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. };