123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- import React, { useState } from "react";
- import { Form, Input, Button, Checkbox } from "antd";
- import { UserOutlined, LockOutlined } from "@ant-design/icons";
- import { Link } from 'react-router-dom';
- // import { BrowserRouter as Router, Route } from 'react-router-dom';
- import {getGQL, url, headers }from "../utils/getGQL";
- import "../styles/RegisterForm.css";
- // const history = createHistory()
- export default ({store, history}) => {
- const [form] = Form.useForm();
- const [login, setLogin] = useState("");
- const [password, setPassword] = useState("");
- const [confPassword, setConfPassword] = useState("");
- const onFinish = (values) => {
- console.log("Success:", values);
- };
- const onFinishFailed = (errorInfo) => {
- console.log("Failed:", errorInfo);
- };
- return (
- <div className="registerForm">
- <div>
- <Form
- name="basic"
- form={form}
- onFinish={onFinish}
- onFinishFailed={onFinishFailed}
- >
- <Form.Item onChange={(e)=> setLogin(e.target.value)}
- label="Username"
- name="username"
- value={login}
- rules={[
- {
- required: true,
- message: "Please input your username!",
- },
- ]}
- >
- <Input
- prefix={<UserOutlined className="site-form-item-icon" />}
- onChange={(e) => {
- form.setFieldsValue({ username: e.target.value });
- }}
- />
- </Form.Item>
- <Form.Item onChange={(e)=> setPassword(e.target.value)}
- label="Password"
- name="password"
- value={password}
- rules={[
- {
- required: true,
- message: "Please input your password!",
- },
- ]}
- >
- <Input.Password
- prefix={<LockOutlined className="site-form-item-icon" />}
- />
- </Form.Item>
- <Form.Item onChange={(e)=> setConfPassword(e.target.value)}
- label="Confirm password"
- name="Confirm password"
- value={confPassword}
- rules={[
- {
- required: true,
- message: "Please input your password!",
- },
- ]}
- >
- <Input.Password
- prefix={<LockOutlined className="site-form-item-icon" />}
- />
- </Form.Item>
- <Form.Item>
- <Button type="primary" htmlType="submit"
- disabled = {password !== confPassword}
- onClick={async () => {
- // await getGQL("/graphql")(
- let response = await getGQL(url)(
- `mutation User{
- createUser (login: "${login}", password: "${password}"){
- _id login
- }
- }`
- ).then((response) => {
- console.log(response);
- if (!response.errors && login && password) {
- history.push("/login");
- } else {
- }
- });
- }
- }
- type="primary"
- >
- Submit
- </Button>
- <Link to="/login" className="link-approval">Sign_in</Link>
- </Form.Item>
- </Form>
- </div>
- </div>
- );
- };
|