From f9e0587411746785255ca77b87215d4edf109c93 Mon Sep 17 00:00:00 2001 From: rxhul18 Date: Sun, 12 Jan 2025 18:18:23 +0530 Subject: [PATCH 1/6] Prisma and backend completed --- apps/api/app/v1/[[...route]]/feedback.ts | 10 ++ apps/api/app/v1/[[...route]]/route.ts | 2 + apps/api/package.json | 1 + apps/app/components/custom/feedback-modal.tsx | 129 ++++++++++++++++++ .../app/components/custom/infobar/infobar.tsx | 34 +++-- ...kActionButton.tsx => quick-action-btn.tsx} | 20 +-- .../app/components/custom/sidebar/sidebar.tsx | 8 +- apps/app/middleware.ts | 50 ------- apps/app/package.json | 1 + apps/www/app/auth/page.tsx | 2 +- packages/auth/package.json | 1 + packages/db/prisma/schema.prisma | 9 ++ pnpm-lock.yaml | 100 ++++++++++---- 13 files changed, 254 insertions(+), 113 deletions(-) create mode 100644 apps/api/app/v1/[[...route]]/feedback.ts create mode 100644 apps/app/components/custom/feedback-modal.tsx rename apps/app/components/custom/sidebar/{QuickActionButton.tsx => quick-action-btn.tsx} (79%) delete mode 100644 apps/app/middleware.ts diff --git a/apps/api/app/v1/[[...route]]/feedback.ts b/apps/api/app/v1/[[...route]]/feedback.ts new file mode 100644 index 0000000..a30a9a9 --- /dev/null +++ b/apps/api/app/v1/[[...route]]/feedback.ts @@ -0,0 +1,10 @@ +import { Hono } from "hono"; +const app = new Hono().get("/", (c) => { + console.log("feedback") + return c.json({ + message: "i am alive", + status: 200, + }); +}); + +export default app; diff --git a/apps/api/app/v1/[[...route]]/route.ts b/apps/api/app/v1/[[...route]]/route.ts index e47f543..4392659 100644 --- a/apps/api/app/v1/[[...route]]/route.ts +++ b/apps/api/app/v1/[[...route]]/route.ts @@ -9,6 +9,7 @@ import health from "./health"; import user from "./user"; import project from "./project"; import contributors from "./contributors"; +import feedback from "./feedback"; import { cors } from "hono/cors"; import workspace from "./workspace"; import { Ratelimit } from "@upstash/ratelimit"; @@ -75,6 +76,7 @@ app.route("/user", user); app.route("/contributors", contributors); app.route("/workspace", workspace); app.route("/project", project); +app.route("/feedback",feedback) const GET = handle(app); const POST = handle(app); diff --git a/apps/api/package.json b/apps/api/package.json index cd21e32..12272ae 100644 --- a/apps/api/package.json +++ b/apps/api/package.json @@ -26,6 +26,7 @@ "@repo/types": "workspace:*", "@upstash/ratelimit": "^2.0.5", "@upstash/redis": "^1.34.3", + "better-auth-harmony": "^1.1.3", "hono": "^4.6.16", "nanoid": "^5.0.9", "next": "15.1.4", diff --git a/apps/app/components/custom/feedback-modal.tsx b/apps/app/components/custom/feedback-modal.tsx new file mode 100644 index 0000000..0009353 --- /dev/null +++ b/apps/app/components/custom/feedback-modal.tsx @@ -0,0 +1,129 @@ +/* eslint-disable react/no-unescaped-entities */ +'use client'; +import { Button } from "@/components/ui/button" +import { + Dialog, + DialogContent, + DialogDescription, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog" +import { toast } from "sonner"; +import { Profanity } from "profanity-validator"; +import { Frown, Meh, MessageSquare, Smile } from 'lucide-react'; +import { Textarea } from "../ui/textarea"; +import { useForm } from "react-hook-form"; +import { z } from "zod"; +import { + Form, + FormControl, + FormField, + FormItem, + FormMessage, +} from "@/components/ui/form"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { useState } from "react"; + +const profanity = new Profanity({ + customWords:["saidev", "premium",'money'], + heat: 0.9, +}); + +const profanityCheck = async (value: string) => { + const result = await profanity.validateField(value); + return result.isValid; +}; + +const postSchema = z.object({ + description: z + .string() + .min(10, "Description must be at least 10 characters") + .refine(async (val) => await profanityCheck(val), { + message: "Inappropriate content detected in description", + }) +}); + +type PostSchema = z.infer; + +export function FeedbackModal() { + const [selectedEmo, setSelectedEmo] = useState<'happy' | 'idle' | 'sad' | null>(null); + + const form = useForm({ + resolver: zodResolver(postSchema), + }); + + const onSubmit = async (data: PostSchema) => { + try { + const validatedData = await postSchema.parseAsync({ ...data }); + const finalFeedback = { + desc:validatedData.description, + emotion: selectedEmo + } + console.log(finalFeedback); + toast.success("Feedback submitted successfully!"); + } catch (error) { + console.error("Validation error:", error); + toast.error("Validation failed. Check form errors."); + } + }; + + return ( + + + + + + + Leave feedback + + We'd love to hear what went well or how we can improve the product experience. + + +
+ + ( + + +