Skip to content

Commit dea6337

Browse files
committed
feat: No need to pass the entire object as create operation update
1 parent ffc32aa commit dea6337

1 file changed

Lines changed: 17 additions & 25 deletions

File tree

components/core/CreateShape.js

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const CreateShape = (props) => {
2020

2121
// Store the default state as a variable so resetting form is easier
2222
const initialState = {
23-
"name": "Tilted Square",
23+
"name": "",
2424
"formula": "polygon(10% 10%, 90% 10%, 90% 90%, 10% 80%)",
2525
"vertices": 4,
2626
"private": false,
@@ -103,7 +103,7 @@ const CreateShape = (props) => {
103103
if (value === "circle") {
104104
setShapeInformation({
105105
...shapeInformation,
106-
"name": "Circle",
106+
"name": "",
107107
"type": "circle",
108108
"formula": "circle(50% at 50% 50%)",
109109
});
@@ -112,7 +112,7 @@ const CreateShape = (props) => {
112112
if (value === "ellipse") {
113113
setShapeInformation({
114114
...shapeInformation,
115-
"name": "Ellipse",
115+
"name": "",
116116
"type": "ellipse",
117117
"formula": "ellipse(25% 40% at 50% 50%)",
118118
});
@@ -290,29 +290,21 @@ const CreateShape = (props) => {
290290
} else {
291291
console.log(`The user ${props.user.email} present in DB`);
292292
}
293+
294+
// Finally, close the modal and update the shape in UI
295+
props.handleClose();
296+
toast.success(`Shape ${shapeInformation.name} created successfully.`);
297+
props.setShapeAction({
298+
...props.shapeAction,
299+
"action": "add",
300+
"payload": {
301+
"shape_id": insertShape['inserted_hashes']
302+
}
303+
});
304+
} else {
305+
toast.error('OOPS!! We hit a bummer. Please try again.');
293306
}
294-
props.handleClose();
295-
toast.success(`Shape ${shapeInformation.name} created successfully.`);
296-
props.setShapeAction({
297-
...props.shapeAction,
298-
"action": "add",
299-
"payload": {
300-
"backgroundColor": shapeInformation.backgroundColor,
301-
"createdAt": null,
302-
"createdBy": props.user.email,
303-
"edges": shapeInformation.edges,
304-
"email": null,
305-
"email1": props.user.email,
306-
"formula": shapeInformation.formula,
307-
"likes": 0,
308-
"name": shapeInformation.name,
309-
"name1": props.user.displayName,
310-
"notes": shapeInformation.notes,
311-
"photoURL": props.user.photoURL,
312-
"private": shapeInformation.private,
313-
"type": shapeInformation.clipPathType
314-
}
315-
});
307+
316308
}
317309

318310
return(

0 commit comments

Comments
 (0)