feat: reset form data on cancel

This commit is contained in:
overflowerror 2021-08-21 19:40:01 +02:00
parent 75fca7d41b
commit 7f98a5c07e
2 changed files with 32 additions and 2 deletions

View file

@ -1,4 +1,4 @@
import {FunctionComponent, useState} from "react";
import {FunctionComponent, useEffect, useState} from "react";
import {
Button,
Dialog,
@ -37,6 +37,16 @@ const AccountDialog: FunctionComponent<AccountFormDialogProps> = (
const [error, setError] = useState<string | null>(null)
useEffect(() => {
if (!open) {
// dialog is closed; reset component
setError(null)
setCode("")
setAccountId(null)
setActiveStep(0)
}
})
return (
<Dialog open={open}>
<DialogTitle title={"New Account"}/>

View file

@ -1,4 +1,4 @@
import React, {FunctionComponent, useState} from "react";
import React, {FunctionComponent, useEffect, useState} from "react";
import {
Button,
Dialog,
@ -7,6 +7,7 @@ import {
DialogTitle,
Grid,
IconButton,
InputAdornment,
TextField
} from "@material-ui/core";
import DeleteIcon from '@material-ui/icons/Delete';
@ -41,10 +42,21 @@ const Index: FunctionComponent<ThreadFormProps> = (
return _idCounter
}
const [_initial, _setInitial] = useState<Thread>(initial)
const [thread, setThread] = useState<Thread>(initial)
const [error, setError] = useState<string | null>(null)
useEffect(() => {
if (initial != _initial) {
// initial changed
_setInitial(initial)
setThread(initial)
setError(null)
_setIdCounter(0)
}
})
return (
<Dialog open={open}>
<DialogTitle title={"Thread"}/>
@ -113,6 +125,14 @@ const Index: FunctionComponent<ThreadFormProps> = (
...thread
})
}}
InputProps={{
endAdornment: (
<InputAdornment position="end">
{280 - thread.tweets[index].text.length}
</InputAdornment>
)
}}
variant="outlined"
fullWidth
/>