From 17b2bcc304ceec2aa41ffa207bab1ee490288796 Mon Sep 17 00:00:00 2001 From: Vignesh Shetty Date: Thu, 16 Jan 2025 07:13:45 +0530 Subject: [PATCH] (fix) : few minor fixes --- app/app/(dashboard)/links/[id]/page.tsx | 48 +++++++------------------ lib/services/pgSingelton.ts | 15 ++++++-- lib/validations/url_create.ts | 3 +- package.json | 2 +- 4 files changed, 27 insertions(+), 41 deletions(-) diff --git a/app/app/(dashboard)/links/[id]/page.tsx b/app/app/(dashboard)/links/[id]/page.tsx index 755c406..98dcc7d 100644 --- a/app/app/(dashboard)/links/[id]/page.tsx +++ b/app/app/(dashboard)/links/[id]/page.tsx @@ -62,37 +62,6 @@ export default function Page({ return parseInt(decodedStr, 10); } - const [link, setLink] = useState({ - devices: { - Desktop: 720, - Mobile: 420, - Tablet: 60, - }, - os: { - windows10: 100, - windows11: 48, - macOS: 50, - }, - browser: { - chrome: 45, - firefox: 50, - safari: 70, - }, - city: { - "New York": 100, - "Los Angeles": 50, - Chicago: 40, - Houston: 30, - }, - locations: [ - { id: 1, country: "United States", engagements: 600, percentage: 50 }, - { id: 2, country: "United Kingdom", engagements: 300, percentage: 25 }, - { id: 3, country: "Canada", engagements: 180, percentage: 15 }, - { id: 4, country: "Australia", engagements: 120, percentage: 10 }, - ], - }); - - const [NoDataSet, setNoDataSet] = useState(Object.keys(link.devices).length); const [fetchLink, setfetchLink] = useState({ id: 1, @@ -140,6 +109,13 @@ export default function Page({ const router = useRouter(); + const [loading, setLoading] = useState(false); + const REDIRECT_URL: string = process.env.REDIRECT_URL || "https://eurl.dev"; + const [title, setTitle] = useState(fetchLink.title); + const [shortCode, setShortcode] = useState(fetchLink.short_code); + const [NoDataSet, setNoDataSet] = useState(0); + const shortLink: string = `${REDIRECT_URL}/${shortCode}`; + useEffect(() => { setLoading(true); getLinkDetailsWithAnalytics(decodeId(params.id).toString()).then((res) => { @@ -149,11 +125,11 @@ export default function Page({ }); }, [router, params.id]); - const [loading, setLoading] = useState(false); - const REDIRECT_URL: string = process.env.REDIRECT_URL || "https://eurl.dev"; - const [title, setTitle] = useState(fetchLink.title); - const [shortCode, setShortcode] = useState(fetchLink.short_code); - const shortLink: string = `${REDIRECT_URL}/${shortCode}`; + useEffect(() => { + setShortcode(fetchLink.short_code); + setTitle(fetchLink.title); + headerAnalytics.devices.length == 0 ? setNoDataSet(1) : setNoDataSet(0); + }, [fetchLink, headerAnalytics]); if (loading) { return ; diff --git a/lib/services/pgSingelton.ts b/lib/services/pgSingelton.ts index 70444a6..4573812 100644 --- a/lib/services/pgSingelton.ts +++ b/lib/services/pgSingelton.ts @@ -5,7 +5,11 @@ class PrismaClientManager { private prismaClient: PrismaClient; private constructor() { - this.prismaClient = new PrismaClient(); + // Use an existing global PrismaClient instance if available, otherwise create a new one + if (!global.prismaClient) { + global.prismaClient = new PrismaClient(); + } + this.prismaClient = global.prismaClient; } public static getInstance(): PrismaClientManager { @@ -23,6 +27,7 @@ class PrismaClientManager { try { return await this.prismaClient.$queryRaw`SELECT 'OK!' as result`; } catch (e) { + console.error("Prisma checkStatus error:", e); return false; } } @@ -32,4 +37,10 @@ class PrismaClientManager { } } -export default PrismaClientManager; \ No newline at end of file +export default PrismaClientManager; + +// Declare a global variable for PrismaClient to persist across reloads +declare global { + // eslint-disable-next-line no-var + var prismaClient: PrismaClient | undefined; +} diff --git a/lib/validations/url_create.ts b/lib/validations/url_create.ts index 6ad93f5..91ac5f4 100644 --- a/lib/validations/url_create.ts +++ b/lib/validations/url_create.ts @@ -3,9 +3,8 @@ import { urlSchema } from "../zod/url"; const validateURLCreateReq = async (formdata: FormData) => { try { const long_url = formdata.get("longUrl"); - let title:any = "New Link"; + const title = formdata.get("title") || "New Link"; - // validation of title need to be done const errors = urlSchema.safeParse({ long_url, }); diff --git a/package.json b/package.json index b62eabc..3de595d 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "private": true, "scripts": { "dev": "next dev", - "build": "npm run prisma:generate && rimraf pg-worker && next build", + "build": "rimraf pg-worker && next build", "start": "next start", "lint": "next lint", "prisma:generate": "npx prisma generate"