Skip to content

Commit 06a7c11

Browse files
committed
feat: The delete shape now works with API
1 parent da7d51a commit 06a7c11

2 files changed

Lines changed: 37 additions & 13 deletions

File tree

components/core/DeleteShape.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
import React from "react";
22

3+
// axios
4+
import axios from "axios";
5+
6+
// bootstrap
37
import Modal from "react-bootstrap/Modal";
48
import Button from "react-bootstrap/Button";
59

10+
// toast
611
import toast from "react-hot-toast";
712

8-
import { harperFetch } from "../../utils/HarperFetch";
9-
1013
// Styled Component
1114
import styled from "styled-components";
1215

@@ -46,25 +49,20 @@ const ContentWrapper = styled.div`
4649
const DeleteShape = ({ show, setShow, shape, shapeAction, setShapeAction }) => {
4750

4851
const handleDelete = async() => {
49-
const deleteShape = await harperFetch({
50-
operation: "sql",
51-
sql: `
52-
DELETE FROM tryshape.shapes
53-
WHERE
54-
shape_id === '${shape.shape_id}'
55-
`
52+
const deleteShapeResponse = await axios.post('/api/DELETE/shape', {
53+
shapeId: shape.shape_id
5654
});
55+
const deleteShape = deleteShapeResponse.data;
56+
console.log({deleteShape});
5757

58-
console.log(deleteShape);
59-
60-
if (deleteShape["deleted_hashes"].length > 0) {
58+
if (deleteShape.data["deleted_hashes"].length > 0) {
6159
setShow(false);
6260
toast.success(`Shape ${shape.name} deleted successfully.`);
6361
setShapeAction({
6462
...shapeAction,
6563
"action": "delete",
6664
"payload": {
67-
"shape_id": deleteShape["deleted_hashes"]
65+
"shape_id": deleteShape.data["deleted_hashes"]
6866
}
6967
});
7068
} else {

pages/api/DELETE/shape.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
2+
export default async function handler(req, res) {
3+
4+
const { shapeId } = req.body;
5+
6+
console.log(shapeId);
7+
8+
const request = await fetch(process.env.NEXT_PUBLIC_DB_URL, {
9+
method: "POST",
10+
headers: {
11+
"Content-Type": "application/json",
12+
Authorization: `Basic ${process.env.NEXT_PUBLIC_DB_AUTHORIZATION}`,
13+
},
14+
body: JSON.stringify({
15+
operation: "delete",
16+
schema: "tryshape",
17+
table: "shapes",
18+
hash_values: [shapeId],
19+
}),
20+
});
21+
22+
const data = await request.json();
23+
24+
res.status(200).json({ data });
25+
}
26+

0 commit comments

Comments
 (0)