summary refs log tree commit diff
path: root/client/src/Components/Form.js
diff options
context:
space:
mode:
authorMelonai <einebeere@gmail.com>2020-05-20 19:52:18 +0200
committerMelonai <einebeere@gmail.com>2020-05-20 19:52:18 +0200
commite58b453f24c8b4081361112862d29c34eb22009d (patch)
tree3437fb38ecb8b22ad5475d88f7e9ca901b320917 /client/src/Components/Form.js
parenta00a8a867cae381982c7b8b77f07836ab4a504ed (diff)
downloadshorest-e58b453f24c8b4081361112862d29c34eb22009d.tar.zst
shorest-e58b453f24c8b4081361112862d29c34eb22009d.zip
port to react and better error handling in backend
Diffstat (limited to 'client/src/Components/Form.js')
-rw-r--r--client/src/Components/Form.js33
1 files changed, 33 insertions, 0 deletions
diff --git a/client/src/Components/Form.js b/client/src/Components/Form.js
new file mode 100644
index 0000000..4d10f98
--- /dev/null
+++ b/client/src/Components/Form.js
@@ -0,0 +1,33 @@
+import React, {useState} from 'react';
+import Button from './Button';
+import isURL from "validator/lib/isURL";
+
+function Form(props) {
+    const [state, setState] = useState({value: '', valid: false});
+
+    const handleSubmit = () => {
+        if (state.valid) {
+            props.addRequest(state.value);
+        }
+    };
+
+    const handleChange = (e) => {
+        const userInput = e.target.value;
+        const valid = isURL('https://' + userInput);
+        setState({value: userInput, valid: valid});
+    };
+
+    return (
+        <form id="form" onSubmit={(e) => e.preventDefault()}>
+            <div className={"input-group" + (state.valid ? "" : " disabled")}>
+                <div className={"input-container" + (state.valid ? "" : " border-r-none")}>
+                    <span className="input-field-text">https://</span>
+                    <input className="input-field" required onChange={handleChange}/>
+                </div>
+                <Button valid={state.valid} submit={handleSubmit}/>
+            </div>
+        </form>
+    )
+}
+
+export default Form;
\ No newline at end of file