working
This commit is contained in:
parent
f33f424920
commit
7e4aaf925c
13
client/package-lock.json
generated
13
client/package-lock.json
generated
@ -3685,6 +3685,11 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"classnames": {
|
||||||
|
"version": "2.2.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/classnames/-/classnames-2.2.6.tgz",
|
||||||
|
"integrity": "sha512-JR/iSQOSt+LQIWwrwEzJ9uk0xfN3mTVYMwt1Ir5mUcSN6pU+V4zQFFaJsclJbPuAUQH+yfWef6tm7l1quW3C8Q=="
|
||||||
|
},
|
||||||
"clean-css": {
|
"clean-css": {
|
||||||
"version": "4.2.3",
|
"version": "4.2.3",
|
||||||
"resolved": "https://registry.npmjs.org/clean-css/-/clean-css-4.2.3.tgz",
|
"resolved": "https://registry.npmjs.org/clean-css/-/clean-css-4.2.3.tgz",
|
||||||
@ -11480,6 +11485,14 @@
|
|||||||
"scheduler": "^0.20.1"
|
"scheduler": "^0.20.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"react-dropdown": {
|
||||||
|
"version": "1.9.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/react-dropdown/-/react-dropdown-1.9.2.tgz",
|
||||||
|
"integrity": "sha512-g4eufErTi5P5T5bGK+VmLl//qvAHy79jm6KKx8G2Tl3mG90bpigb+Aw85P+C2JUdAnIIQdv8kP/oHN314GvAfw==",
|
||||||
|
"requires": {
|
||||||
|
"classnames": "^2.2.3"
|
||||||
|
}
|
||||||
|
},
|
||||||
"react-error-overlay": {
|
"react-error-overlay": {
|
||||||
"version": "6.0.9",
|
"version": "6.0.9",
|
||||||
"resolved": "https://registry.npmjs.org/react-error-overlay/-/react-error-overlay-6.0.9.tgz",
|
"resolved": "https://registry.npmjs.org/react-error-overlay/-/react-error-overlay-6.0.9.tgz",
|
||||||
|
@ -8,6 +8,7 @@
|
|||||||
"@testing-library/user-event": "^12.1.10",
|
"@testing-library/user-event": "^12.1.10",
|
||||||
"react": "^17.0.1",
|
"react": "^17.0.1",
|
||||||
"react-dom": "^17.0.1",
|
"react-dom": "^17.0.1",
|
||||||
|
"react-dropdown": "^1.9.2",
|
||||||
"react-scripts": "4.0.2",
|
"react-scripts": "4.0.2",
|
||||||
"web-vitals": "^1.0.1"
|
"web-vitals": "^1.0.1"
|
||||||
},
|
},
|
||||||
|
16
client/src/checkAuth.js
Normal file
16
client/src/checkAuth.js
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
import axios from "axios";
|
||||||
|
|
||||||
|
async function readCookie() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await axios.get("/readCookie");
|
||||||
|
if (res.data === "No Cookie Set") {
|
||||||
|
document.location = "/";
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default readCookie;
|
||||||
|
|
@ -1,25 +1,9 @@
|
|||||||
import React, { useState, useEffect } from "react";
|
import React from "react";
|
||||||
import MTable from "./accountTable";
|
import MTable from "./accountTable";
|
||||||
import axios from "axios";
|
import readCookie from "../checkAuth";
|
||||||
|
|
||||||
function Accounts() {
|
function Accounts() {
|
||||||
const readCookie = async () => {
|
readCookie();
|
||||||
try {
|
|
||||||
const res = await axios.get("/readCookie");
|
|
||||||
|
|
||||||
if (res.data === "No Cookie Set") {
|
|
||||||
document.location = "/"
|
|
||||||
// this.props.history.push('/accounts');
|
|
||||||
}
|
|
||||||
} catch (e) {
|
|
||||||
// setScreen("auth");
|
|
||||||
console.log(e);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
readCookie();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div style={{ padding: "30px" }}>
|
<div style={{ padding: "30px" }}>
|
||||||
|
@ -1,9 +1,14 @@
|
|||||||
import React, { Component } from "react";
|
import React, { Component } from "react";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import DropDown from "./accountDropDown"
|
import Dropdown from "react-dropdown";
|
||||||
|
import "react-dropdown/style.css";
|
||||||
|
import readCookie from "../checkAuth"
|
||||||
|
|
||||||
|
let arr = [];
|
||||||
class AddAccount extends Component {
|
class AddAccount extends Component {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
readCookie();
|
||||||
|
|
||||||
super();
|
super();
|
||||||
this.state = {
|
this.state = {
|
||||||
username: "",
|
username: "",
|
||||||
@ -12,13 +17,32 @@ class AddAccount extends Component {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
componentDidMount() {
|
componentDidMount() {
|
||||||
// fetch("/getStreams")
|
this.fetchOptions();
|
||||||
// .then((res) => res.json())
|
|
||||||
// .then((streams) => this.setState({ streams }));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fetchOptions() {
|
||||||
|
fetch("/getStreamNames")
|
||||||
|
.then((res) => {
|
||||||
|
return res.json();
|
||||||
|
})
|
||||||
|
.then((json) => {
|
||||||
|
json.forEach((account) => {
|
||||||
|
arr.push(account.streamName);
|
||||||
|
});
|
||||||
|
this.setState({ options: arr });
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
_onSelect = (e) => {
|
||||||
|
/*
|
||||||
|
Because we named the inputs to match their
|
||||||
|
corresponding values in state, it's
|
||||||
|
super easy to update the state
|
||||||
|
*/
|
||||||
|
this.setState({ stream: e.value });
|
||||||
|
};
|
||||||
|
|
||||||
onChange = (e) => {
|
onChange = (e) => {
|
||||||
/*
|
/*
|
||||||
Because we named the inputs to match their
|
Because we named the inputs to match their
|
||||||
@ -44,7 +68,7 @@ class AddAccount extends Component {
|
|||||||
.then((res) => {
|
.then((res) => {
|
||||||
console.log(res);
|
console.log(res);
|
||||||
console.log(res.data);
|
console.log(res.data);
|
||||||
if (res.data.includes('Added successfully')) {
|
if (res.data.includes("Added successfully")) {
|
||||||
document.location = "/accounts";
|
document.location = "/accounts";
|
||||||
} else {
|
} else {
|
||||||
document.location = "/AddAccount";
|
document.location = "/AddAccount";
|
||||||
@ -53,8 +77,7 @@ class AddAccount extends Component {
|
|||||||
};
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
const { username, password } = this.state;
|
||||||
const { username, password, stream } = this.state;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section class="container">
|
<section class="container">
|
||||||
@ -73,7 +96,7 @@ class AddAccount extends Component {
|
|||||||
/>
|
/>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Password -
|
Password -
|
||||||
<input
|
<input
|
||||||
type="text"
|
type="text"
|
||||||
name="password"
|
name="password"
|
||||||
@ -82,17 +105,16 @@ class AddAccount extends Component {
|
|||||||
/>
|
/>
|
||||||
</p>
|
</p>
|
||||||
<p>
|
<p>
|
||||||
Stream Name -
|
Stream Name -
|
||||||
<input
|
<Dropdown
|
||||||
type="text"
|
options={arr}
|
||||||
name="stream"
|
onChange={this._onSelect}
|
||||||
value={stream}
|
value={arr[0]}
|
||||||
onChange={this.onChange}
|
placeholder="Select an option"
|
||||||
/>
|
/>
|
||||||
</p>
|
</p>
|
||||||
<br />
|
<br />
|
||||||
<button type="submit">Add Account</button>
|
<button type="submit">Add Account</button>
|
||||||
<DropDown />
|
|
||||||
</form>
|
</form>
|
||||||
</p>
|
</p>
|
||||||
</article>
|
</article>
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
|
import Dropdown from "react-dropdown";
|
||||||
|
import "react-dropdown/style.css";
|
||||||
|
|
||||||
var values;
|
var values;
|
||||||
|
let arr = [];
|
||||||
class DropDown extends React.Component {
|
class DropDown extends React.Component {
|
||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
@ -21,7 +23,7 @@ class DropDown extends React.Component {
|
|||||||
})
|
})
|
||||||
.then((json) => {
|
.then((json) => {
|
||||||
values = json;
|
values = json;
|
||||||
let arr = [];
|
|
||||||
values.forEach((element) => {
|
values.forEach((element) => {
|
||||||
arr.push(element.streamName);
|
arr.push(element.streamName);
|
||||||
});
|
});
|
||||||
@ -29,23 +31,38 @@ class DropDown extends React.Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
state = { value: "Large" };
|
|
||||||
|
|
||||||
handleChange = (event) => {
|
handleChange = (event) => {
|
||||||
this.setState({
|
this.setState({
|
||||||
value: event.target.value
|
value: event.target.value,
|
||||||
});
|
});
|
||||||
}
|
};
|
||||||
|
|
||||||
|
_onSelect = (e) => {
|
||||||
|
/*
|
||||||
|
Because we named the inputs to match their
|
||||||
|
corresponding values in state, it's
|
||||||
|
super easy to update the state
|
||||||
|
*/
|
||||||
|
this.setState({ stream: e.value });
|
||||||
|
};
|
||||||
|
|
||||||
|
onChange = (e) => {
|
||||||
|
/*
|
||||||
|
Because we named the inputs to match their
|
||||||
|
corresponding values in state, it's
|
||||||
|
super easy to update the state
|
||||||
|
*/
|
||||||
|
this.setState({ [e.target.name]: e.target.value });
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<div className="drop-down">
|
<Dropdown
|
||||||
<select>
|
options={arr}
|
||||||
{this.state.options.map((option, key) => (
|
onChange={this._onSelect}
|
||||||
<option key={key}>{option}</option>
|
value={arr[0]}
|
||||||
))}
|
placeholder="Select an option"
|
||||||
</select>
|
/>
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user