aboutsummaryrefslogtreecommitdiff
path: root/src/components/Form/People/RegisterPersonForm.js
blob: bca3bde98f6f3c0879ce2aed80452f6bf26dda3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
 * OpenBills - Self hosted browser app to generate and keep track of simple invoices
 * Version - 0
 * Licensed under the MIT license - https://opensource.org/licenses/MIT
 *
 * Copyright (c) 2021 Vidhu Kant Sharma
*/

// TODO: Code isn't tested properly
// I'd be surprised if it < 10 bugs

// TODO: Implement override protection

import React, { useState } from "react";
import axios from "axios";
import "./../Form.scss";


const RegisterPersonForm = (props) => {
  const [newPersonName, setNewPersonName] = useState("");
  const [newPersonPhone, setNewPersonPhone] = useState("");
  const [newPersonEmail, setNewPersonEmail] = useState("");

  const hideSelf = () => props.setVisibility(false);

  const closeOnBGClicked = (event) => 
    event.target.className === "floatingMenuBG" && hideSelf();

  const postForm = (event) => {
    event.preventDefault();
    // TODO: show confirmation before being invisible
    axios.post(
      `/api/people/`
      + `?name=${newPersonName}`
      + `&phone=${newPersonPhone}`
      + `&email=${newPersonEmail}`
    )
      .then((res) => {
        console.log(res);
        props.setVisibility(false);
      })
      .catch((err) => {
        console.log(err);
      });
  }


  return (
    <div className={"floatingMenuBG"} onClick={closeOnBGClicked}>
      <div className={"floatingMenu"}>
        <div className={"formContainer"}>
          <form className={"floatingForm"} onSubmit={postForm}>
            <div className={"wideForm"}>
              <label>
                Client Name: <input className={"wideInputBox"} type="text" value={newPersonName} onChange={
                  (event) => {
                    setNewPersonName(event.target.value);
                  }
                } required />
              </label>

              <label>
                Phone: <input className={"wideInputBox"} type="text" value={newPersonPhone} onChange={
                  (event) => {
                    setNewPersonPhone(event.target.value);
                  }
                } />
              </label>

              <label>
                Email: <input className={"wideInputBox"} type="text" value={newPersonEmail} onChange={
                  (event) => {
                    setNewPersonEmail(event.target.value);
                  }
                } />
              </label>

              <input type="submit" value="submit"/>
            </div>
          </form>
        </div>
      </div>
    </div>
  );
}

export default RegisterPersonForm;