Post a review
This commit is contained in:
parent
81c84ee5ed
commit
44643a49f9
|
@ -37,6 +37,7 @@ export default function App({
|
|||
email,
|
||||
tos,
|
||||
privacy,
|
||||
slug,
|
||||
}: {
|
||||
name: string;
|
||||
type: AppType["type"];
|
||||
|
@ -54,6 +55,7 @@ export default function App({
|
|||
email: string; // required
|
||||
tos?: string;
|
||||
privacy?: string;
|
||||
slug: string;
|
||||
}) {
|
||||
const { t } = useLocale();
|
||||
|
||||
|
@ -62,16 +64,26 @@ export default function App({
|
|||
const [comment, setComment] = useState("");
|
||||
const totalStars = 5;
|
||||
|
||||
// const onSubmitReview = async (rating: number, comment: string) => {
|
||||
// try {
|
||||
// const body = {
|
||||
// rating: rating,
|
||||
// comment: comment
|
||||
// }
|
||||
const onSubmitReview = async (slug: string, rating: number, comment: string) => {
|
||||
try {
|
||||
const body = {
|
||||
slug: slug,
|
||||
rating: rating,
|
||||
comment: comment,
|
||||
};
|
||||
|
||||
// const
|
||||
// }
|
||||
// }
|
||||
const res = await fetch("/api/app-store/reviews", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(body),
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
});
|
||||
console.log("🚀 ~ file: App.tsx ~ line 82 ~ onSubmitReview ~ res", res);
|
||||
} catch (error) {
|
||||
console.log("🚀 ~ file: App.tsx ~ line 82 ~ onSubmitReview ~ error", error);
|
||||
}
|
||||
};
|
||||
|
||||
const priceInDollar = Intl.NumberFormat("en-US", {
|
||||
style: "currency",
|
||||
|
@ -283,7 +295,7 @@ export default function App({
|
|||
rows={3}
|
||||
onChange={(event) => setComment(event.target.value)}
|
||||
className="my-1 block rounded-sm border-gray-300 py-2 pb-2 shadow-sm sm:text-sm"></textarea>
|
||||
<Button>{t("submit")}</Button>
|
||||
<Button onClick={() => onSubmitReview(slug, rating, comment)}>{t("submit")}</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Shell>
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
import dayjs from "dayjs";
|
||||
import type { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
import prisma from "@calcom/prisma";
|
||||
|
||||
import { getSession } from "@lib/auth";
|
||||
|
||||
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
console.log("This triggers ");
|
||||
if (req.method === "POST") {
|
||||
const session = await getSession({ req });
|
||||
if (!session?.user?.id) {
|
||||
return res.status(401).json({ message: "Not authenticated" });
|
||||
}
|
||||
await prisma.appReview.create({
|
||||
data: {
|
||||
slug: req.body.slug,
|
||||
date: dayjs().toISOString(),
|
||||
user: {
|
||||
connect: {
|
||||
id: session.user.id,
|
||||
},
|
||||
},
|
||||
rating: req.body.rating,
|
||||
comment: req.body.comment,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
res.end();
|
||||
}
|
|
@ -61,6 +61,7 @@ function SingleAppPage({ data, source }: inferSSRProps<typeof getStaticProps>) {
|
|||
docs={data.docsUrl}
|
||||
website={data.url}
|
||||
email={data.email}
|
||||
slug={data.slug}
|
||||
// tos="https://zoom.us/terms"
|
||||
// privacy="https://zoom.us/privacy"
|
||||
body={<MDXRemote {...source} components={components} />}
|
||||
|
|
|
@ -483,6 +483,7 @@ model AppReview {
|
|||
slug String @unique
|
||||
userId Int
|
||||
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
|
||||
date DateTime
|
||||
rating Int
|
||||
review String?
|
||||
comment String?
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user