Skip to content

Commit

Permalink
add comment from user function
Browse files Browse the repository at this point in the history
  • Loading branch information
Highlander-maker committed Jun 23, 2022
1 parent d1db883 commit a274e66
Show file tree
Hide file tree
Showing 4 changed files with 257 additions and 1 deletion.
165 changes: 165 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"react-portable-text": "^0.4.3"
},
"devDependencies": {
"@babel/preset-react": "^7.17.12",
"@types/node": "17.0.35",
"@types/react": "18.0.9",
"@types/react-dom": "18.0.5",
Expand Down
38 changes: 38 additions & 0 deletions pages/api/createComment.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import type { NextApiRequest, NextApiResponse } from "next";
import sanityClient from "@sanity/client";

const config = {
dataset: process.env.NEXT_PUBLIC_SANITY_DATASET,
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID,
useCdn: process.env.NODE_BNV === "production",
token: process.env.SANITY_API_TOKEN,
};

const client = sanityClient(config);

export default async function creatComment(
req: NextApiRequest,
res: NextApiResponse
) {
const { _id, name, email, comment } = JSON.parse(req.body);

try {
await client.create({
_type: "comment",
post: {
_type: "reference",
_ref: _id,
},
name,
email,
comment,
});
} catch (err) {
return res.status(500).json({ message: "Couldn't submit comment", err });
}

console.log("Comment submitted");

return res.status(500).json({ message: "Comment submitted" });
}
54 changes: 53 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,13 @@
dependencies:
"@babel/helper-plugin-utils" "^7.8.0"

"@babel/plugin-syntax-jsx@^7.17.12":
"integrity" "sha512-spyY3E3AURfxh/RHtjx5j6hs8am5NbUBGfcZ2vB3uShSpZdQyXSf5rR5Mk76vbtlAZOelyVQ71Fg0x9SG4fsog=="
"resolved" "https://registry.npmjs.org/@babel/plugin-syntax-jsx/-/plugin-syntax-jsx-7.17.12.tgz"
"version" "7.17.12"
dependencies:
"@babel/helper-plugin-utils" "^7.17.12"

"@babel/plugin-syntax-logical-assignment-operators@^7.10.4":
"integrity" "sha512-d8waShlpFDinQ5MtvGU9xDAOzKH47+FFoney2baFIoMr952hKOLp1HR7VszoZvOsV/4+RRszNY7D17ba0te0ig=="
"resolved" "https://registry.npmjs.org/@babel/plugin-syntax-logical-assignment-operators/-/plugin-syntax-logical-assignment-operators-7.10.4.tgz"
Expand Down Expand Up @@ -698,6 +705,39 @@
dependencies:
"@babel/helper-plugin-utils" "^7.16.7"

"@babel/plugin-transform-react-display-name@^7.16.7":
"integrity" "sha512-qgIg8BcZgd0G/Cz916D5+9kqX0c7nPZyXaP8R2tLNN5tkyIZdG5fEwBrxwplzSnjC1jvQmyMNVwUCZPcbGY7Pg=="
"resolved" "https://registry.npmjs.org/@babel/plugin-transform-react-display-name/-/plugin-transform-react-display-name-7.16.7.tgz"
"version" "7.16.7"
dependencies:
"@babel/helper-plugin-utils" "^7.16.7"

"@babel/plugin-transform-react-jsx-development@^7.16.7":
"integrity" "sha512-RMvQWvpla+xy6MlBpPlrKZCMRs2AGiHOGHY3xRwl0pEeim348dDyxeH4xBsMPbIMhujeq7ihE702eM2Ew0Wo+A=="
"resolved" "https://registry.npmjs.org/@babel/plugin-transform-react-jsx-development/-/plugin-transform-react-jsx-development-7.16.7.tgz"
"version" "7.16.7"
dependencies:
"@babel/plugin-transform-react-jsx" "^7.16.7"

"@babel/plugin-transform-react-jsx@^7.16.7", "@babel/plugin-transform-react-jsx@^7.17.12":
"integrity" "sha512-Lcaw8bxd1DKht3thfD4A12dqo1X16he1Lm8rIv8sTwjAYNInRS1qHa9aJoqvzpscItXvftKDCfaEQzwoVyXpEQ=="
"resolved" "https://registry.npmjs.org/@babel/plugin-transform-react-jsx/-/plugin-transform-react-jsx-7.17.12.tgz"
"version" "7.17.12"
dependencies:
"@babel/helper-annotate-as-pure" "^7.16.7"
"@babel/helper-module-imports" "^7.16.7"
"@babel/helper-plugin-utils" "^7.17.12"
"@babel/plugin-syntax-jsx" "^7.17.12"
"@babel/types" "^7.17.12"

"@babel/plugin-transform-react-pure-annotations@^7.16.7":
"integrity" "sha512-6+0IK6ouvqDn9bmEG7mEyF/pwlJXVj5lwydybpyyH3D0A7Hftk+NCTdYjnLNZksn261xaOV5ksmp20pQEmc2RQ=="
"resolved" "https://registry.npmjs.org/@babel/plugin-transform-react-pure-annotations/-/plugin-transform-react-pure-annotations-7.18.0.tgz"
"version" "7.18.0"
dependencies:
"@babel/helper-annotate-as-pure" "^7.16.7"
"@babel/helper-plugin-utils" "^7.17.12"

"@babel/plugin-transform-regenerator@^7.18.0":
"integrity" "sha512-C8YdRw9uzx25HSIzwA7EM7YP0FhCe5wNvJbZzjVNHHPGVcDJ3Aie+qGYYdS1oVQgn+B3eAIJbWFLrJ4Jipv7nw=="
"resolved" "https://registry.npmjs.org/@babel/plugin-transform-regenerator/-/plugin-transform-regenerator-7.18.0.tgz"
Expand Down Expand Up @@ -856,6 +896,18 @@
"@babel/types" "^7.4.4"
"esutils" "^2.0.2"

"@babel/preset-react@^7.17.12":
"integrity" "sha512-h5U+rwreXtZaRBEQhW1hOJLMq8XNJBQ/9oymXiCXTuT/0uOwpbT0gUt+sXeOqoXBgNuUKI7TaObVwoEyWkpFgA=="
"resolved" "https://registry.npmjs.org/@babel/preset-react/-/preset-react-7.17.12.tgz"
"version" "7.17.12"
dependencies:
"@babel/helper-plugin-utils" "^7.17.12"
"@babel/helper-validator-option" "^7.16.7"
"@babel/plugin-transform-react-display-name" "^7.16.7"
"@babel/plugin-transform-react-jsx" "^7.17.12"
"@babel/plugin-transform-react-jsx-development" "^7.16.7"
"@babel/plugin-transform-react-pure-annotations" "^7.16.7"

"@babel/runtime@^7.8.4":
"integrity" "sha512-38Y8f7YUhce/K7RMwTp7m0uCumpv9hZkitCbBClqQIow1qSbCvGkcegKOXpEWCQLfWmevgRiWokZ1GkpfhbZug=="
"resolved" "https://registry.npmjs.org/@babel/runtime/-/runtime-7.18.3.tgz"
Expand Down Expand Up @@ -888,7 +940,7 @@
"debug" "^4.1.0"
"globals" "^11.1.0"

"@babel/types@^7.16.0", "@babel/types@^7.16.7", "@babel/types@^7.16.8", "@babel/types@^7.17.0", "@babel/types@^7.18.0", "@babel/types@^7.18.2", "@babel/types@^7.18.4", "@babel/types@^7.4.4":
"@babel/types@^7.16.0", "@babel/types@^7.16.7", "@babel/types@^7.16.8", "@babel/types@^7.17.0", "@babel/types@^7.17.12", "@babel/types@^7.18.0", "@babel/types@^7.18.2", "@babel/types@^7.18.4", "@babel/types@^7.4.4":
"integrity" "sha512-ThN1mBcMq5pG/Vm2IcBmPPfyPXbd8S02rS+OBIDENdufvqC7Z/jHPCv9IcP01277aKtDI8g/2XysBN4hA8niiw=="
"resolved" "https://registry.npmjs.org/@babel/types/-/types-7.18.4.tgz"
"version" "7.18.4"
Expand Down

0 comments on commit a274e66

Please sign in to comment.