Skip to content

Commit bb648f7

Browse files
committed
feat: Form now resets when modal is closed
1 parent beb1899 commit bb648f7

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

components/core/CreateShape.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@ import { harperFetch } from "../../utils/HarperFetch";
1818

1919
const CreateShape = (props) => {
2020

21-
// shapeInformation holds all information about the shape
22-
const [shapeInformation, setShapeInformation] = useState({
21+
const initialState = {
2322
"name": "Tilted Square",
2423
"formula": "polygon(10% 10%, 90% 10%, 90% 90%, 10% 80%)",
2524
"vertices": 4,
@@ -47,6 +46,11 @@ const CreateShape = (props) => {
4746
"y": "80%",
4847
},
4948
]
49+
}
50+
51+
// shapeInformation holds all information about the shape
52+
const [shapeInformation, setShapeInformation] = useState({
53+
...initialState,
5054
});
5155

5256
// Changes shapeInformation when something in ShapeForm or ShapePreview is altered
@@ -330,7 +334,7 @@ const CreateShape = (props) => {
330334
</Container>
331335
</Modal.Body>
332336
<Modal.Footer>
333-
<Button onClick={() => props.handleClose()} variant="outline-info">
337+
<Button onClick={() => { setShapeInformation({ ...initialState }); props.handleClose(); }} variant="outline-info">
334338
Close
335339
</Button>
336340
<Button variant="secondary" type="submit" form="createShapeForm" disabled={!shapeInformation.name}>

0 commit comments

Comments
 (0)