Skip to content

Commit 4695308

Browse files
committed
feat: Now in we have replaced the HarperFetch with API call in edit shape
1 parent adac7eb commit 4695308

2 files changed

Lines changed: 48 additions & 25 deletions

File tree

components/core/CreateShape.js

Lines changed: 17 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import React, { useState, useEffect } from "react";
22

3+
// axios
4+
import axios from "axios";
5+
36
// Bootstrap
47
import Container from "react-bootstrap/Container";
58
import Row from "react-bootstrap/Row";
@@ -302,34 +305,28 @@ const CreateShape = (props) => {
302305
// Editing Shape
303306
if (props.edit) {
304307

305-
const editShape = await harperFetch({
306-
operation: "sql",
307-
sql: `
308-
UPDATE tryshape.shapes
309-
SET
310-
name = '${shapeInformation.name}',
311-
formula = '${shapeInformation.formula}',
312-
vertices = '${shapeInformation.vertices}',
313-
private = '${shapeInformation.private}',
314-
edges = '${shapeInformation.edges}',
315-
notes = '${shapeInformation.notes}',
316-
type = '${shapeInformation.clipPathType}',
317-
backgroundColor = '${shapeInformation.backgroundColor}'
318-
WHERE
319-
shape_id === '${props.shape.shape_id}'
320-
`
308+
const updateShapeResponse = await axios.post('/api/PUT/shape', {
309+
shapeId: props.shape.shape_id,
310+
name: shapeInformation.name,
311+
formula: shapeInformation.formula,
312+
vertices: shapeInformation.vertices,
313+
visibility: shapeInformation.private,
314+
edges: shapeInformation.edges,
315+
notes: shapeInformation.notes,
316+
type: shapeInformation.clipPathType,
317+
backgroundColor: shapeInformation.backgroundColor
321318
});
319+
const editShape = updateShapeResponse.data;
320+
console.log({editShape});
322321

323-
console.log(editShape);
324-
325-
if (editShape["update_hashes"].length > 0) {
322+
if (editShape.data["update_hashes"].length > 0) {
326323
props.handleClose();
327324
toast.success(`Shape ${shapeInformation.name} edited successfully.`);
328325
props.setShapeAction({
329326
...props.shapeAction,
330327
"action": "edit",
331328
"payload": {
332-
"shape_id": editShape['update_hashes']
329+
"shape_id": editShape.data['update_hashes']
333330
}
334331
});
335332
} else {

pages/api/PUT/shape.js

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,36 @@
11

22
export default async function handler(req, res) {
33

4-
const { likes, shapeId } = req.body;
4+
const {
5+
name,
6+
formula,
7+
vertices,
8+
visibility,
9+
edges,
10+
notes,
11+
type,
12+
backgroundColor,
13+
likes,
14+
createdBy,
15+
shapeId } = req.body;
16+
17+
18+
console.log({shapeId});
19+
20+
const record = {};
21+
record['shape_id'] = shapeId;
22+
record['private'] = visibility;
23+
record['name'] = name;
24+
record['formula'] = formula;
25+
record['vertices'] = vertices;
26+
record['edges'] = edges;
27+
record['notes'] = notes;
28+
record['type'] = type;
29+
record['backgroundColor'] = backgroundColor;
30+
record['createdBy'] = createdBy;
31+
record['likes'] = likes;
32+
33+
console.log({record});
534

635
const request = await fetch(process.env.NEXT_PUBLIC_DB_URL, {
736
method: "POST",
@@ -14,10 +43,7 @@ export default async function handler(req, res) {
1443
schema: "tryshape",
1544
table: "shapes",
1645
records: [
17-
{
18-
shape_id: shapeId,
19-
likes: likes,
20-
},
46+
record
2147
],
2248
}),
2349
});

0 commit comments

Comments
 (0)