Skip to content

Commit 86e8e5f

Browse files
committed
feat: added modal to confirm shape deletion
1 parent be72a41 commit 86e8e5f

3 files changed

Lines changed: 65 additions & 2 deletions

File tree

components/core/DeleteShape.js

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import React from "react";
2+
3+
import Modal from "react-bootstrap/Modal";
4+
import Button from "react-bootstrap/Button";
5+
6+
const DeleteShape = ({ show, setShow, shape }) => {
7+
return(
8+
<Modal
9+
size="md"
10+
show={ show }
11+
onHide={() => setShow(false)}
12+
centered
13+
>
14+
<Modal.Header closeButton>
15+
<Modal.Title>
16+
Delete Shape
17+
</Modal.Title>
18+
</Modal.Header>
19+
<Modal.Body>
20+
<p>Are you sure you want to delete this shape? </p>
21+
</Modal.Body>
22+
<Modal.Footer>
23+
<Button onClick={() => setShow(false)}>
24+
Cancel
25+
</Button>
26+
<Button>
27+
Yes
28+
</Button>
29+
</Modal.Footer>
30+
</Modal>
31+
);
32+
}
33+
34+
export default DeleteShape;

components/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ export { default as Landing } from "./core/Landing";
44
export { default as SignInModal } from "./core/SignInModal";
55
export { default as ExportShape } from "./core/ExportShape";
66
export { default as CreateShape } from "./core/CreateShape";
7-
export {default as CopyShapeSource} from "./core/CopyShapeSource";
7+
export { default as CopyShapeSource } from "./core/CopyShapeSource";
8+
export { default as DeleteShape } from "./core/DeleteShape";
89

910
// utils
1011
export { default as Header } from "./utils/Header";

components/utils/ShapeList.js

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ import { BsFillHeartFill, BsHeart} from "react-icons/bs";
3030
// Export Shape
3131
import { ExportShape, CopyShapeSource, NoShapeFound } from '..';
3232

33-
// CreateShape to edit shape
33+
// CreateShape
3434
import { CreateShape } from "..";
3535

36+
// DeleteShape
37+
import { DeleteShape } from "..";
38+
3639
// misc unitless
3740
import { getShapeFileName, getShapeId } from '../../utils/misc';
3841

@@ -231,6 +234,10 @@ const ShapeList = (
231234
const [showEditModal, setShowEditModal] = useState(false);
232235
const [shapeToEdit, setShapeToEdit] = useState();
233236

237+
// All about editing private shapes
238+
const [showDeleteModal, setShowDeleteModal] = useState(false);
239+
const [shapeToDelete, setShapeToDelete] = useState();
240+
234241
useEffect(() =>{
235242
const copy = [...shapes];
236243
if(sort === 'recent') {
@@ -295,6 +302,16 @@ const ShapeList = (
295302
setShowEditModal(false);
296303
}
297304

305+
/**
306+
* Method to execute when user clicks on the delte shape
307+
*/
308+
const performDelete = shape => {
309+
// Set the shape details to edit
310+
setShapeToDelete(shape);
311+
// Show the export modal
312+
setShowDeleteModal(true);
313+
}
314+
298315
/**
299316
* Method to execute when user clicks on the likes
300317
*/
@@ -396,6 +413,12 @@ const ShapeList = (
396413
edit={true} />
397414
}
398415

416+
{ shapeToDelete && <DeleteShape
417+
show= { showDeleteModal }
418+
setShow={ setShowDeleteModal }
419+
shape= { shapeToDelete } />
420+
}
421+
399422
{
400423
filteredShape.length === 0 ?
401424
<NoShapeFound
@@ -452,6 +475,11 @@ const ShapeList = (
452475
Edit
453476
</Button> : null
454477
}
478+
{shape.private ?
479+
<Button title="Delete Shape" vairant="outline-light" onClick={() => {performDelete(shape); console.log(shape)}} className="btn-icon">
480+
Delete
481+
</Button> : null
482+
}
455483
</ShapeActionsContainer>
456484
</ShapeActions>
457485
</ShapeCardBody>

0 commit comments

Comments
 (0)