disable buttons and inputs while post. close #37
This commit is contained in:
@@ -66,6 +66,7 @@ export default function CreateAccount() {
|
|||||||
const [password, setPassword] = React.useState("");
|
const [password, setPassword] = React.useState("");
|
||||||
const [login, setLogin] = React.useState(true);
|
const [login, setLogin] = React.useState(true);
|
||||||
const [status, setStatus] = React.useState(null);
|
const [status, setStatus] = React.useState(null);
|
||||||
|
const [button, setButton] = React.useState(false);
|
||||||
|
|
||||||
const putCreateAccount = async (url, data) => {
|
const putCreateAccount = async (url, data) => {
|
||||||
const response = await fetch(url, {
|
const response = await fetch(url, {
|
||||||
@@ -83,10 +84,12 @@ export default function CreateAccount() {
|
|||||||
if (response.status == "200") {
|
if (response.status == "200") {
|
||||||
setLogin(false)
|
setLogin(false)
|
||||||
}
|
}
|
||||||
|
setButton(false)
|
||||||
setTimeout(() => { setStatus(null) }, 5000)
|
setTimeout(() => { setStatus(null) }, 5000)
|
||||||
}
|
}
|
||||||
const handleClick = (e) => {
|
const handleClick = (e) => {
|
||||||
if (username !== "" && password !== "") {
|
if (username !== "" && password !== "") {
|
||||||
|
setButton(true)
|
||||||
putCreateAccount(url, { email: username, password: password })
|
putCreateAccount(url, { email: username, password: password })
|
||||||
|
|
||||||
setUsername("")
|
setUsername("")
|
||||||
@@ -97,6 +100,7 @@ export default function CreateAccount() {
|
|||||||
const handleKeyDown = (e) => {
|
const handleKeyDown = (e) => {
|
||||||
if (e.keyCode == 13) {
|
if (e.keyCode == 13) {
|
||||||
if (username !== "" && password !== "") {
|
if (username !== "" && password !== "") {
|
||||||
|
setButton(true)
|
||||||
putCreateAccount(url, { email: username, password: password })
|
putCreateAccount(url, { email: username, password: password })
|
||||||
|
|
||||||
setUsername("")
|
setUsername("")
|
||||||
@@ -140,6 +144,7 @@ export default function CreateAccount() {
|
|||||||
value={username}
|
value={username}
|
||||||
className={classes.input}
|
className={classes.input}
|
||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
|
disabled={button}
|
||||||
/>
|
/>
|
||||||
</Box >
|
</Box >
|
||||||
</Grid>
|
</Grid>
|
||||||
@@ -156,12 +161,13 @@ export default function CreateAccount() {
|
|||||||
onChange={handleChangePW}
|
onChange={handleChangePW}
|
||||||
className={classes.input}
|
className={classes.input}
|
||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
|
disabled={button}
|
||||||
/>
|
/>
|
||||||
</Box >
|
</Box >
|
||||||
</Grid>
|
</Grid>
|
||||||
<Grid item xs={12}>
|
<Grid item xs={12}>
|
||||||
<Box display="flex" justifyContent="center" >
|
<Box display="flex" justifyContent="center" >
|
||||||
<Button variant="contained" color="secondary" onClick={handleClick} >
|
<Button disabled={button} variant="contained" color="secondary" onClick={handleClick} >
|
||||||
Create Account
|
Create Account
|
||||||
</Button>
|
</Button>
|
||||||
</Box >
|
</Box >
|
||||||
|
|||||||
@@ -68,6 +68,7 @@ export default function Login() {
|
|||||||
const [password, setPassword] = React.useState("");
|
const [password, setPassword] = React.useState("");
|
||||||
const [login, setLogin] = React.useState(true);
|
const [login, setLogin] = React.useState(true);
|
||||||
const [status, setStatus] = React.useState(null);
|
const [status, setStatus] = React.useState(null);
|
||||||
|
const [button, setButton] = React.useState(false);
|
||||||
|
|
||||||
const postLogin = async (url, data) => {
|
const postLogin = async (url, data) => {
|
||||||
|
|
||||||
@@ -86,13 +87,14 @@ export default function Login() {
|
|||||||
if (response.status == "200") {
|
if (response.status == "200") {
|
||||||
setLogin(false)
|
setLogin(false)
|
||||||
}
|
}
|
||||||
|
setButton(false)
|
||||||
setTimeout(() => { setStatus(null) }, 5000)
|
setTimeout(() => { setStatus(null) }, 5000)
|
||||||
}
|
}
|
||||||
|
|
||||||
const handleClick = (e) => {
|
const handleClick = (e) => {
|
||||||
|
|
||||||
if (username !== "" && password !== "") {
|
if (username !== "" && password !== "") {
|
||||||
|
setButton(true)
|
||||||
postLogin(url, { email: username, password: password })
|
postLogin(url, { email: username, password: password })
|
||||||
|
|
||||||
setUsername("")
|
setUsername("")
|
||||||
@@ -103,6 +105,7 @@ export default function Login() {
|
|||||||
const handleKeyDown = (e) => {
|
const handleKeyDown = (e) => {
|
||||||
if (e.keyCode == 13) {
|
if (e.keyCode == 13) {
|
||||||
if (username !== "" && password !== "") {
|
if (username !== "" && password !== "") {
|
||||||
|
setButton(true)
|
||||||
postLogin(url, { email: username, password: password })
|
postLogin(url, { email: username, password: password })
|
||||||
|
|
||||||
setUsername("")
|
setUsername("")
|
||||||
@@ -149,6 +152,7 @@ export default function Login() {
|
|||||||
onChange={handleChangeUSR}
|
onChange={handleChangeUSR}
|
||||||
className={classes.input}
|
className={classes.input}
|
||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
|
disabled={button}
|
||||||
/>
|
/>
|
||||||
</Box >
|
</Box >
|
||||||
</Grid>
|
</Grid>
|
||||||
@@ -165,6 +169,7 @@ export default function Login() {
|
|||||||
onChange={handleChangePW}
|
onChange={handleChangePW}
|
||||||
className={classes.input}
|
className={classes.input}
|
||||||
onKeyDown={handleKeyDown}
|
onKeyDown={handleKeyDown}
|
||||||
|
disabled={button}
|
||||||
/>
|
/>
|
||||||
</Box >
|
</Box >
|
||||||
</Grid>
|
</Grid>
|
||||||
@@ -179,7 +184,7 @@ export default function Login() {
|
|||||||
</Grid>
|
</Grid>
|
||||||
<Grid item xs={12}>
|
<Grid item xs={12}>
|
||||||
<Box display="flex" justifyContent="center" >
|
<Box display="flex" justifyContent="center" >
|
||||||
<Button variant="contained" color="secondary" onClick={handleClick}>
|
<Button disabled={button} variant="contained" color="secondary" onClick={handleClick}>
|
||||||
Login
|
Login
|
||||||
</Button>
|
</Button>
|
||||||
</Box >
|
</Box >
|
||||||
|
|||||||
Reference in New Issue
Block a user