From a615447e394e592bdfa3ca60f5f21578dfbb1397 Mon Sep 17 00:00:00 2001 From: tanmay4l Date: Sat, 13 Jul 2024 15:23:52 +0530 Subject: [PATCH 1/3] fixed login --- middleware.ts | 23 +- next.config.js | 3 + package-lock.json | 302 +++-------- package.json | 6 +- pages/TherapistApply/index.tsx | 775 +++-------------------------- pages/TherapistDashboard/index.tsx | 21 +- pages/api/auth/[...nextauth].ts | 15 +- pages/api/therapists/register.ts | 1 + yarn.lock | 103 ++-- 9 files changed, 186 insertions(+), 1063 deletions(-) diff --git a/middleware.ts b/middleware.ts index 1425506..bc7d47f 100644 --- a/middleware.ts +++ b/middleware.ts @@ -2,26 +2,31 @@ import { NextResponse } from "next/server"; import type { NextRequest } from "next/server"; import { getToken } from "next-auth/jwt"; +const protectedRoutes = ["/TherapistDashboard", "/TherapistApply"]; + export async function middleware(request: NextRequest) { const token = await getToken({ req: request, secret: process.env.NEXTAUTH_SECRET, }); - console.log("Middleware token:", token); + console.log("Middleware executed for path:", request.nextUrl.pathname); + console.log("Token:", token); - if (!token && request.nextUrl.pathname === "/TherapistDashboard") { - console.log("No token, redirecting to sign in"); - const url = request.nextUrl.clone(); - url.pathname = "/api/auth/signin"; - url.searchParams.set("callbackUrl", request.url); - return NextResponse.redirect(url); + if ( + !token && + protectedRoutes.some((route) => request.nextUrl.pathname.startsWith(route)) + ) { + console.log("Redirecting to signin page"); + const signInUrl = new URL("/api/auth/signin", request.url); + signInUrl.searchParams.set("callbackUrl", request.url); + return NextResponse.redirect(signInUrl); } - console.log("Proceeding to next middleware or route handler"); + console.log("Proceeding to next middleware/page"); return NextResponse.next(); } export const config = { - matcher: ["/TherapistDashboard"], + matcher: ["/TherapistDashboard/:path*", "/TherapistApply/:path*"], }; diff --git a/next.config.js b/next.config.js index 24f224e..a6a6975 100644 --- a/next.config.js +++ b/next.config.js @@ -12,6 +12,9 @@ const nextConfig = { ], }, reactStrictMode: true, + experimental: { + appDir: true, + }, i18n: { locales: ["en"], defaultLocale: "en", diff --git a/package-lock.json b/package-lock.json index 0b56755..2c765a0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -51,7 +51,6 @@ "remark-math": "^5.1.1", "strip-markdown": "^6.0.0", "thirdweb": "^5.19.1", - "typescript": "5.0.4", "ua-parser-js": "^1.0.35", "usehooks-ts": "^2.9.1" }, @@ -71,7 +70,8 @@ "next-mdx-remote": "^4.4.1", "postcss": "^8.4.38", "prettier": "^2.8.7", - "tailwindcss": "^3.4.3" + "tailwindcss": "^3.4.3", + "typescript": "^5.5.3" } }, "node_modules/@adraffy/ens-normalize": { @@ -787,18 +787,6 @@ "react-dom": ">=18" } }, - "node_modules/@chakra-ui/modal/node_modules/aria-hidden": { - "version": "1.2.3", - "resolved": "https://registry.npmjs.org/aria-hidden/-/aria-hidden-1.2.3.tgz", - "integrity": "sha512-xcLxITLe2HYa1cnYnwCjkOO1PqUHQpozB8x9AR0OgWN2woOBi5kSDVxKfd0b7sb1hw5qFeJhXm9H1nu3xSfLeQ==", - "license": "MIT", - "dependencies": { - "tslib": "^2.0.0" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/@chakra-ui/next-js": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/@chakra-ui/next-js/-/next-js-2.1.2.tgz", @@ -1666,18 +1654,6 @@ "stylis": "4.1.3" } }, - "node_modules/@emotion/babel-plugin/node_modules/@babel/runtime": { - "version": "7.21.0", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.21.0.tgz", - "integrity": "sha512-xwII0//EObnq89Ji5AKYQaRYiW/nZ3llSv29d49IuxPhKbtJoLP+9QUUZ4nVragQVtaVGeZrpB+ZtG/Pdy/POw==", - "license": "MIT", - "dependencies": { - "regenerator-runtime": "^0.13.11" - }, - "engines": { - "node": ">=6.9.0" - } - }, "node_modules/@emotion/cache": { "version": "11.10.7", "license": "MIT", @@ -1736,18 +1712,6 @@ } } }, - "node_modules/@emotion/react/node_modules/@babel/runtime": { - "version": "7.21.0", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.21.0.tgz", - "integrity": "sha512-xwII0//EObnq89Ji5AKYQaRYiW/nZ3llSv29d49IuxPhKbtJoLP+9QUUZ4nVragQVtaVGeZrpB+ZtG/Pdy/POw==", - "license": "MIT", - "dependencies": { - "regenerator-runtime": "^0.13.11" - }, - "engines": { - "node": ">=6.9.0" - } - }, "node_modules/@emotion/serialize": { "version": "1.1.1", "license": "MIT", @@ -1784,18 +1748,6 @@ } } }, - "node_modules/@emotion/styled/node_modules/@babel/runtime": { - "version": "7.21.0", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.21.0.tgz", - "integrity": "sha512-xwII0//EObnq89Ji5AKYQaRYiW/nZ3llSv29d49IuxPhKbtJoLP+9QUUZ4nVragQVtaVGeZrpB+ZtG/Pdy/POw==", - "license": "MIT", - "dependencies": { - "regenerator-runtime": "^0.13.11" - }, - "engines": { - "node": ">=6.9.0" - } - }, "node_modules/@emotion/styled/node_modules/@emotion/is-prop-valid": { "version": "1.2.0", "license": "MIT", @@ -2417,9 +2369,10 @@ } }, "node_modules/@next/env": { - "version": "14.2.3", - "resolved": "https://registry.npmjs.org/@next/env/-/env-14.2.3.tgz", - "integrity": "sha512-W7fd7IbkfmeeY2gXrzJYDx8D2lWKbVoTIj1o1ScPHNzvp30s1AuoEFSdr39bC5sjxJaxTtq3OTCZboNp0lNWHA==" + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/env/-/env-14.2.5.tgz", + "integrity": "sha512-/zZGkrTOsraVfYjGP8uM0p6r0BDT6xWpkjdVbcz66PJVSpwXX3yNiRycxAuDfBKGWBrZBXRuK/YVlkNgxHGwmA==", + "license": "MIT" }, "node_modules/@next/eslint-plugin-next": { "version": "13.3.0", @@ -2431,12 +2384,13 @@ } }, "node_modules/@next/swc-darwin-arm64": { - "version": "14.2.3", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.3.tgz", - "integrity": "sha512-3pEYo/RaGqPP0YzwnlmPN2puaF2WMLM3apt5jLW2fFdXD9+pqcoTzRk+iZsf8ta7+quAe4Q6Ms0nR0SFGFdS1A==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-arm64/-/swc-darwin-arm64-14.2.5.tgz", + "integrity": "sha512-/9zVxJ+K9lrzSGli1///ujyRfon/ZneeZ+v4ptpiPoOU+GKZnm8Wj8ELWU1Pm7GHltYRBklmXMTUqM/DqQ99FQ==", "cpu": [ "arm64" ], + "license": "MIT", "optional": true, "os": [ "darwin" @@ -2446,12 +2400,13 @@ } }, "node_modules/@next/swc-darwin-x64": { - "version": "14.2.3", - "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.3.tgz", - "integrity": "sha512-6adp7waE6P1TYFSXpY366xwsOnEXM+y1kgRpjSRVI2CBDOcbRjsJ67Z6EgKIqWIue52d2q/Mx8g9MszARj8IEA==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/swc-darwin-x64/-/swc-darwin-x64-14.2.5.tgz", + "integrity": "sha512-vXHOPCwfDe9qLDuq7U1OYM2wUY+KQ4Ex6ozwsKxp26BlJ6XXbHleOUldenM67JRyBfVjv371oneEvYd3H2gNSA==", "cpu": [ "x64" ], + "license": "MIT", "optional": true, "os": [ "darwin" @@ -2461,12 +2416,13 @@ } }, "node_modules/@next/swc-linux-arm64-gnu": { - "version": "14.2.3", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.3.tgz", - "integrity": "sha512-cuzCE/1G0ZSnTAHJPUT1rPgQx1w5tzSX7POXSLaS7w2nIUJUD+e25QoXD/hMfxbsT9rslEXugWypJMILBj/QsA==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-gnu/-/swc-linux-arm64-gnu-14.2.5.tgz", + "integrity": "sha512-vlhB8wI+lj8q1ExFW8lbWutA4M2ZazQNvMWuEDqZcuJJc78iUnLdPPunBPX8rC4IgT6lIx/adB+Cwrl99MzNaA==", "cpu": [ "arm64" ], + "license": "MIT", "optional": true, "os": [ "linux" @@ -2476,12 +2432,13 @@ } }, "node_modules/@next/swc-linux-arm64-musl": { - "version": "14.2.3", - "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.3.tgz", - "integrity": "sha512-0D4/oMM2Y9Ta3nGuCcQN8jjJjmDPYpHX9OJzqk42NZGJocU2MqhBq5tWkJrUQOQY9N+In9xOdymzapM09GeiZw==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/swc-linux-arm64-musl/-/swc-linux-arm64-musl-14.2.5.tgz", + "integrity": "sha512-NpDB9NUR2t0hXzJJwQSGu1IAOYybsfeB+LxpGsXrRIb7QOrYmidJz3shzY8cM6+rO4Aojuef0N/PEaX18pi9OA==", "cpu": [ "arm64" ], + "license": "MIT", "optional": true, "os": [ "linux" @@ -2491,12 +2448,13 @@ } }, "node_modules/@next/swc-linux-x64-gnu": { - "version": "14.2.3", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.3.tgz", - "integrity": "sha512-ENPiNnBNDInBLyUU5ii8PMQh+4XLr4pG51tOp6aJ9xqFQ2iRI6IH0Ds2yJkAzNV1CfyagcyzPfROMViS2wOZ9w==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-gnu/-/swc-linux-x64-gnu-14.2.5.tgz", + "integrity": "sha512-8XFikMSxWleYNryWIjiCX+gU201YS+erTUidKdyOVYi5qUQo/gRxv/3N1oZFCgqpesN6FPeqGM72Zve+nReVXQ==", "cpu": [ "x64" ], + "license": "MIT", "optional": true, "os": [ "linux" @@ -2506,12 +2464,13 @@ } }, "node_modules/@next/swc-linux-x64-musl": { - "version": "14.2.3", - "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.3.tgz", - "integrity": "sha512-BTAbq0LnCbF5MtoM7I/9UeUu/8ZBY0i8SFjUMCbPDOLv+un67e2JgyN4pmgfXBwy/I+RHu8q+k+MCkDN6P9ViQ==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/swc-linux-x64-musl/-/swc-linux-x64-musl-14.2.5.tgz", + "integrity": "sha512-6QLwi7RaYiQDcRDSU/os40r5o06b5ue7Jsk5JgdRBGGp8l37RZEh9JsLSM8QF0YDsgcosSeHjglgqi25+m04IQ==", "cpu": [ "x64" ], + "license": "MIT", "optional": true, "os": [ "linux" @@ -2521,12 +2480,13 @@ } }, "node_modules/@next/swc-win32-arm64-msvc": { - "version": "14.2.3", - "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.3.tgz", - "integrity": "sha512-AEHIw/dhAMLNFJFJIJIyOFDzrzI5bAjI9J26gbO5xhAKHYTZ9Or04BesFPXiAYXDNdrwTP2dQceYA4dL1geu8A==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/swc-win32-arm64-msvc/-/swc-win32-arm64-msvc-14.2.5.tgz", + "integrity": "sha512-1GpG2VhbspO+aYoMOQPQiqc/tG3LzmsdBH0LhnDS3JrtDx2QmzXe0B6mSZZiN3Bq7IOMXxv1nlsjzoS1+9mzZw==", "cpu": [ "arm64" ], + "license": "MIT", "optional": true, "os": [ "win32" @@ -2536,12 +2496,13 @@ } }, "node_modules/@next/swc-win32-ia32-msvc": { - "version": "14.2.3", - "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.3.tgz", - "integrity": "sha512-vga40n1q6aYb0CLrM+eEmisfKCR45ixQYXuBXxOOmmoV8sYST9k7E3US32FsY+CkkF7NtzdcebiFT4CHuMSyZw==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/swc-win32-ia32-msvc/-/swc-win32-ia32-msvc-14.2.5.tgz", + "integrity": "sha512-Igh9ZlxwvCDsu6438FXlQTHlRno4gFpJzqPjSIBZooD22tKeI4fE/YMRoHVJHmrQ2P5YL1DoZ0qaOKkbeFWeMg==", "cpu": [ "ia32" ], + "license": "MIT", "optional": true, "os": [ "win32" @@ -2551,12 +2512,13 @@ } }, "node_modules/@next/swc-win32-x64-msvc": { - "version": "14.2.3", - "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.3.tgz", - "integrity": "sha512-Q1/zm43RWynxrO7lW4ehciQVj+5ePBhOK+/K2P7pLFX3JaJ/IZVC69SHidrmZSOkqz7ECIOhhy7XhAFG4JYyHA==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/@next/swc-win32-x64-msvc/-/swc-win32-x64-msvc-14.2.5.tgz", + "integrity": "sha512-tEQ7oinq1/CjSG9uSTerca3v4AZ+dFa+4Yu6ihaG8Ud8ddqLQgFGcnwYls13H5X5CPDPZJdYxyeMui6muOLd4g==", "cpu": [ "x64" ], + "license": "MIT", "optional": true, "os": [ "win32" @@ -5111,18 +5073,6 @@ "npm": ">=6" } }, - "node_modules/babel-plugin-macros/node_modules/@babel/runtime": { - "version": "7.21.0", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.21.0.tgz", - "integrity": "sha512-xwII0//EObnq89Ji5AKYQaRYiW/nZ3llSv29d49IuxPhKbtJoLP+9QUUZ4nVragQVtaVGeZrpB+ZtG/Pdy/POw==", - "license": "MIT", - "dependencies": { - "regenerator-runtime": "^0.13.11" - }, - "engines": { - "node": ">=6.9.0" - } - }, "node_modules/bail": { "version": "2.0.2", "resolved": "https://registry.npmjs.org/bail/-/bail-2.0.2.tgz", @@ -5594,10 +5544,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/call-bind/node_modules/function-bind": { - "version": "1.1.1", - "license": "MIT" - }, "node_modules/callsites": { "version": "3.1.0", "resolved": "https://registry.npmjs.org/callsites/-/callsites-3.1.0.tgz", @@ -7488,18 +7434,6 @@ "eslint": "^3 || ^4 || ^5 || ^6 || ^7 || ^8" } }, - "node_modules/eslint-plugin-jsx-a11y/node_modules/@babel/runtime": { - "version": "7.21.0", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.21.0.tgz", - "integrity": "sha512-xwII0//EObnq89Ji5AKYQaRYiW/nZ3llSv29d49IuxPhKbtJoLP+9QUUZ4nVragQVtaVGeZrpB+ZtG/Pdy/POw==", - "license": "MIT", - "dependencies": { - "regenerator-runtime": "^0.13.11" - }, - "engines": { - "node": ">=6.9.0" - } - }, "node_modules/eslint-plugin-react": { "version": "7.32.2", "resolved": "https://registry.npmjs.org/eslint-plugin-react/-/eslint-plugin-react-7.32.2.tgz", @@ -8357,10 +8291,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/get-intrinsic/node_modules/function-bind": { - "version": "1.1.1", - "license": "MIT" - }, "node_modules/get-nonce": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/get-nonce/-/get-nonce-1.0.1.tgz", @@ -8738,10 +8668,6 @@ "node": ">=8" } }, - "node_modules/has/node_modules/function-bind": { - "version": "1.1.1", - "license": "MIT" - }, "node_modules/hash-base": { "version": "3.0.4", "resolved": "https://registry.npmjs.org/hash-base/-/hash-base-3.0.4.tgz", @@ -12090,11 +12016,12 @@ } }, "node_modules/next": { - "version": "14.2.3", - "resolved": "https://registry.npmjs.org/next/-/next-14.2.3.tgz", - "integrity": "sha512-dowFkFTR8v79NPJO4QsBUtxv0g9BrS/phluVpMAt2ku7H+cbcBJlopXjkWlwxrk/xGqMemr7JkGPGemPrLLX7A==", + "version": "14.2.5", + "resolved": "https://registry.npmjs.org/next/-/next-14.2.5.tgz", + "integrity": "sha512-0f8aRfBVL+mpzfBjYfQuLWh2WyAwtJXCRfkPF4UJ5qd2YwrHczsrSzXU4tRMV0OAxR8ZJZWPFn6uhSC56UTsLA==", + "license": "MIT", "dependencies": { - "@next/env": "14.2.3", + "@next/env": "14.2.5", "@swc/helpers": "0.5.5", "busboy": "1.6.0", "caniuse-lite": "^1.0.30001579", @@ -12109,15 +12036,15 @@ "node": ">=18.17.0" }, "optionalDependencies": { - "@next/swc-darwin-arm64": "14.2.3", - "@next/swc-darwin-x64": "14.2.3", - "@next/swc-linux-arm64-gnu": "14.2.3", - "@next/swc-linux-arm64-musl": "14.2.3", - "@next/swc-linux-x64-gnu": "14.2.3", - "@next/swc-linux-x64-musl": "14.2.3", - "@next/swc-win32-arm64-msvc": "14.2.3", - "@next/swc-win32-ia32-msvc": "14.2.3", - "@next/swc-win32-x64-msvc": "14.2.3" + "@next/swc-darwin-arm64": "14.2.5", + "@next/swc-darwin-x64": "14.2.5", + "@next/swc-linux-arm64-gnu": "14.2.5", + "@next/swc-linux-arm64-musl": "14.2.5", + "@next/swc-linux-x64-gnu": "14.2.5", + "@next/swc-linux-x64-musl": "14.2.5", + "@next/swc-win32-arm64-msvc": "14.2.5", + "@next/swc-win32-ia32-msvc": "14.2.5", + "@next/swc-win32-x64-msvc": "14.2.5" }, "peerDependencies": { "@opentelemetry/api": "^1.1.0", @@ -13726,18 +13653,6 @@ "react": "^15.3.0 || ^16.0.0 || ^17.0.0 || ^18.0.0" } }, - "node_modules/react-clientside-effect/node_modules/@babel/runtime": { - "version": "7.21.0", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.21.0.tgz", - "integrity": "sha512-xwII0//EObnq89Ji5AKYQaRYiW/nZ3llSv29d49IuxPhKbtJoLP+9QUUZ4nVragQVtaVGeZrpB+ZtG/Pdy/POw==", - "license": "MIT", - "dependencies": { - "regenerator-runtime": "^0.13.11" - }, - "engines": { - "node": ">=6.9.0" - } - }, "node_modules/react-dom": { "version": "18.2.0", "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.2.0.tgz", @@ -13780,18 +13695,6 @@ } } }, - "node_modules/react-focus-lock/node_modules/@babel/runtime": { - "version": "7.21.0", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.21.0.tgz", - "integrity": "sha512-xwII0//EObnq89Ji5AKYQaRYiW/nZ3llSv29d49IuxPhKbtJoLP+9QUUZ4nVragQVtaVGeZrpB+ZtG/Pdy/POw==", - "license": "MIT", - "dependencies": { - "regenerator-runtime": "^0.13.11" - }, - "engines": { - "node": ">=6.9.0" - } - }, "node_modules/react-icons": { "version": "4.8.0", "resolved": "https://registry.npmjs.org/react-icons/-/react-icons-4.8.0.tgz", @@ -13968,6 +13871,7 @@ "version": "0.13.11", "resolved": "https://registry.npmjs.org/regenerator-runtime/-/regenerator-runtime-0.13.11.tgz", "integrity": "sha512-kY1AZVr2Ra+t+piVaJ4gxaFaReZVH40AKNo7UCX6W+dEwBo/2oZJzqfuN1qLq1oL45o56cPaTXELwrTh8Fpggg==", + "dev": true, "license": "MIT" }, "node_modules/regexp.prototype.flags": { @@ -14805,12 +14709,6 @@ "url": "https://opencollective.com/unified" } }, - "node_modules/remark-stringify/node_modules/mdast-util-to-markdown/node_modules/@types/unist": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.2.tgz", - "integrity": "sha512-dqId9J8K/vGi5Zr7oo212BGii5m3q5Hxlkwy3WpYuKPklmBEvsbMYYyLxAQpSffdLl/gdW0XUpKWFvYmyoWCoQ==", - "license": "MIT" - }, "node_modules/remark-stringify/node_modules/mdast-util-to-string": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/mdast-util-to-string/-/mdast-util-to-string-4.0.0.tgz", @@ -14936,12 +14834,6 @@ "url": "https://opencollective.com/unified" } }, - "node_modules/remark-stringify/node_modules/unified/node_modules/@types/unist": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.2.tgz", - "integrity": "sha512-dqId9J8K/vGi5Zr7oo212BGii5m3q5Hxlkwy3WpYuKPklmBEvsbMYYyLxAQpSffdLl/gdW0XUpKWFvYmyoWCoQ==", - "license": "MIT" - }, "node_modules/remark-stringify/node_modules/unist-util-is": { "version": "6.0.0", "resolved": "https://registry.npmjs.org/unist-util-is/-/unist-util-is-6.0.0.tgz", @@ -14955,12 +14847,6 @@ "url": "https://opencollective.com/unified" } }, - "node_modules/remark-stringify/node_modules/unist-util-is/node_modules/@types/unist": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.2.tgz", - "integrity": "sha512-dqId9J8K/vGi5Zr7oo212BGii5m3q5Hxlkwy3WpYuKPklmBEvsbMYYyLxAQpSffdLl/gdW0XUpKWFvYmyoWCoQ==", - "license": "MIT" - }, "node_modules/remark-stringify/node_modules/unist-util-stringify-position": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/unist-util-stringify-position/-/unist-util-stringify-position-4.0.0.tgz", @@ -14974,12 +14860,6 @@ "url": "https://opencollective.com/unified" } }, - "node_modules/remark-stringify/node_modules/unist-util-stringify-position/node_modules/@types/unist": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.2.tgz", - "integrity": "sha512-dqId9J8K/vGi5Zr7oo212BGii5m3q5Hxlkwy3WpYuKPklmBEvsbMYYyLxAQpSffdLl/gdW0XUpKWFvYmyoWCoQ==", - "license": "MIT" - }, "node_modules/remark-stringify/node_modules/unist-util-visit": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/unist-util-visit/-/unist-util-visit-5.0.0.tgz", @@ -15009,18 +14889,6 @@ "url": "https://opencollective.com/unified" } }, - "node_modules/remark-stringify/node_modules/unist-util-visit-parents/node_modules/@types/unist": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.2.tgz", - "integrity": "sha512-dqId9J8K/vGi5Zr7oo212BGii5m3q5Hxlkwy3WpYuKPklmBEvsbMYYyLxAQpSffdLl/gdW0XUpKWFvYmyoWCoQ==", - "license": "MIT" - }, - "node_modules/remark-stringify/node_modules/unist-util-visit/node_modules/@types/unist": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.2.tgz", - "integrity": "sha512-dqId9J8K/vGi5Zr7oo212BGii5m3q5Hxlkwy3WpYuKPklmBEvsbMYYyLxAQpSffdLl/gdW0XUpKWFvYmyoWCoQ==", - "license": "MIT" - }, "node_modules/remark-stringify/node_modules/vfile": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/vfile/-/vfile-6.0.1.tgz", @@ -15050,18 +14918,6 @@ "url": "https://opencollective.com/unified" } }, - "node_modules/remark-stringify/node_modules/vfile-message/node_modules/@types/unist": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.2.tgz", - "integrity": "sha512-dqId9J8K/vGi5Zr7oo212BGii5m3q5Hxlkwy3WpYuKPklmBEvsbMYYyLxAQpSffdLl/gdW0XUpKWFvYmyoWCoQ==", - "license": "MIT" - }, - "node_modules/remark-stringify/node_modules/vfile/node_modules/@types/unist": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.2.tgz", - "integrity": "sha512-dqId9J8K/vGi5Zr7oo212BGii5m3q5Hxlkwy3WpYuKPklmBEvsbMYYyLxAQpSffdLl/gdW0XUpKWFvYmyoWCoQ==", - "license": "MIT" - }, "node_modules/remark/node_modules/@types/mdast": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/@types/mdast/-/mdast-4.0.3.tgz", @@ -15096,12 +14952,6 @@ "url": "https://opencollective.com/unified" } }, - "node_modules/remark/node_modules/unified/node_modules/@types/unist": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.2.tgz", - "integrity": "sha512-dqId9J8K/vGi5Zr7oo212BGii5m3q5Hxlkwy3WpYuKPklmBEvsbMYYyLxAQpSffdLl/gdW0XUpKWFvYmyoWCoQ==", - "license": "MIT" - }, "node_modules/remark/node_modules/unist-util-stringify-position": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/unist-util-stringify-position/-/unist-util-stringify-position-4.0.0.tgz", @@ -15115,12 +14965,6 @@ "url": "https://opencollective.com/unified" } }, - "node_modules/remark/node_modules/unist-util-stringify-position/node_modules/@types/unist": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.2.tgz", - "integrity": "sha512-dqId9J8K/vGi5Zr7oo212BGii5m3q5Hxlkwy3WpYuKPklmBEvsbMYYyLxAQpSffdLl/gdW0XUpKWFvYmyoWCoQ==", - "license": "MIT" - }, "node_modules/remark/node_modules/vfile": { "version": "6.0.1", "resolved": "https://registry.npmjs.org/vfile/-/vfile-6.0.1.tgz", @@ -15150,18 +14994,6 @@ "url": "https://opencollective.com/unified" } }, - "node_modules/remark/node_modules/vfile-message/node_modules/@types/unist": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.2.tgz", - "integrity": "sha512-dqId9J8K/vGi5Zr7oo212BGii5m3q5Hxlkwy3WpYuKPklmBEvsbMYYyLxAQpSffdLl/gdW0XUpKWFvYmyoWCoQ==", - "license": "MIT" - }, - "node_modules/remark/node_modules/vfile/node_modules/@types/unist": { - "version": "3.0.2", - "resolved": "https://registry.npmjs.org/@types/unist/-/unist-3.0.2.tgz", - "integrity": "sha512-dqId9J8K/vGi5Zr7oo212BGii5m3q5Hxlkwy3WpYuKPklmBEvsbMYYyLxAQpSffdLl/gdW0XUpKWFvYmyoWCoQ==", - "license": "MIT" - }, "node_modules/require-directory": { "version": "2.1.1", "resolved": "https://registry.npmjs.org/require-directory/-/require-directory-2.1.1.tgz", @@ -16436,18 +16268,6 @@ } } }, - "node_modules/thirdweb/node_modules/@babel/runtime": { - "version": "7.21.0", - "resolved": "https://registry.npmjs.org/@babel/runtime/-/runtime-7.21.0.tgz", - "integrity": "sha512-xwII0//EObnq89Ji5AKYQaRYiW/nZ3llSv29d49IuxPhKbtJoLP+9QUUZ4nVragQVtaVGeZrpB+ZtG/Pdy/POw==", - "license": "MIT", - "dependencies": { - "regenerator-runtime": "^0.13.11" - }, - "engines": { - "node": ">=6.9.0" - } - }, "node_modules/thirdweb/node_modules/@emotion/babel-plugin": { "version": "11.11.0", "resolved": "https://registry.npmjs.org/@emotion/babel-plugin/-/babel-plugin-11.11.0.tgz", @@ -16937,16 +16757,16 @@ } }, "node_modules/typescript": { - "version": "5.0.4", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.4.tgz", - "integrity": "sha512-cW9T5W9xY37cc+jfEnaUvX91foxtHkza3Nw3wkoF4sSlKn0MONdkdEndig/qPBWXNkmplh3NzayQzCiHM4/hqw==", + "version": "5.5.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.3.tgz", + "integrity": "sha512-/hreyEujaB0w76zKo6717l3L0o/qEUtRgdvUBvlkhoWeOVMjMuHNHk0BRBzikzuGDqNmPQbg5ifMEqsHLiIUcQ==", "license": "Apache-2.0", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" }, "engines": { - "node": ">=12.20" + "node": ">=14.17" } }, "node_modules/ua-parser-js": { diff --git a/package.json b/package.json index a5aa2b0..60639e4 100644 --- a/package.json +++ b/package.json @@ -4,7 +4,7 @@ "private": true, "scripts": { "dev": "next dev", - "build": "next build", + "build": "next build", "postbuild": "next-sitemap", "start": "next start", "lint": "next lint", @@ -55,7 +55,6 @@ "remark-math": "^5.1.1", "strip-markdown": "^6.0.0", "thirdweb": "^5.19.1", - "typescript": "5.0.4", "ua-parser-js": "^1.0.35", "usehooks-ts": "^2.9.1" }, @@ -75,7 +74,8 @@ "next-mdx-remote": "^4.4.1", "postcss": "^8.4.38", "prettier": "^2.8.7", - "tailwindcss": "^3.4.3" + "tailwindcss": "^3.4.3", + "typescript": "^5.5.3" }, "lint-staged": { "*.{js,css,md}": "prettier --write" diff --git a/pages/TherapistApply/index.tsx b/pages/TherapistApply/index.tsx index bdc10fb..4cf55b2 100644 --- a/pages/TherapistApply/index.tsx +++ b/pages/TherapistApply/index.tsx @@ -1,213 +1,72 @@ import { GetServerSideProps } from "next"; import { getSession, useSession } from "next-auth/react"; -import prisma from "../../db/db"; -import { Therapist, Specialization, TherapistType } from "@prisma/client"; -import { useState, useEffect } from "react"; -import { - ArrowButton, - Box, - Container, - Input, - Radio, - RadioGroup, - ShadowBox, - Stack, - Text, - Textarea, - Checkbox, -} from "@/lib/ui"; -import Image from "next/image"; -import Logo from "../../public/images/logo.png"; +import prisma from "@/db/db"; +import { Therapist } from "@prisma/client"; +import { useEffect, useState } from "react"; import { useRouter } from "next/router"; -type TherapistWithRelations = Therapist & { - specializations: Specialization[]; - certifications: { - name: string; - issuedAt: Date; - expiresAt: Date | null; - issuedBy: string; - }[]; - education: { - institution: string; - degree: string; - fieldOfStudy: string; - startDate: Date; - endDate: Date | null; - grade: number | null; - }[]; - workExperience: { - company: string; - position: string; - startDate: Date; - endDate: Date | null; - description: string | null; - }[]; -}; - interface TherapistApplyProps { - therapist: TherapistWithRelations | null; -} - -interface FormData { - type: TherapistType; - fullName: string; - dateOfBirth: string; - gender: string; - currentLocation: string; - languages: string[]; - hoursAvailable: number; - experienceYears: number; - specializations: string[]; - heardFrom: string; - workingElsewhere: boolean; - whyJoining: string; - linkedinProfile: string; - referredBy: string; - longBio: string; - certifications: Array<{ - name: string; - issuedAt: string; - expiresAt: string; - issuedBy: string; - }>; - education: Array<{ - institution: string; - degree: string; - fieldOfStudy: string; - startDate: string; - endDate: string; - grade: number | null; - }>; - workExperience: Array<{ - company: string; - position: string; - startDate: string; - endDate: string; - description: string; - }>; + therapist: + | (Omit & { dateOfBirth: string | null }) + | null; } export default function TherapistApply({ therapist }: TherapistApplyProps) { const { data: session, status } = useSession(); const router = useRouter(); + const [formData, setFormData] = useState({ + // ... your existing formData initialization + dateOfBirth: "", // Adjust based on your form requirements + }); useEffect(() => { if (status === "unauthenticated") { - router.push("/api/auth/signin?callbackUrl=/TherapistApply"); + router.push("/"); } }, [status, router]); - const [formData, setFormData] = useState({ - type: TherapistType.PROFESSIONAL, - fullName: "", - dateOfBirth: "", - gender: "", - currentLocation: "", - languages: [], - hoursAvailable: 0, - experienceYears: 0, - specializations: [], - heardFrom: "", - workingElsewhere: false, - whyJoining: "", - linkedinProfile: "", - referredBy: "", - longBio: "", - certifications: [{ name: "", issuedAt: "", expiresAt: "", issuedBy: "" }], - education: [ - { - institution: "", - degree: "", - fieldOfStudy: "", - startDate: "", - endDate: "", - grade: null, - }, - ], - workExperience: [ - { - company: "", - position: "", - startDate: "", - endDate: "", - description: "", - }, - ], - }); + useEffect(() => { + if (therapist && therapist.dateOfBirth) { + setFormData((prev) => ({ + ...prev, + dateOfBirth: new Date(therapist.dateOfBirth) + .toISOString() + .split("T")[0], + })); + } + }, [therapist]); const handleChange = ( - e: React.ChangeEvent - ) => { - const { name, value, type } = e.target; - setFormData((prev) => ({ - ...prev, - [name]: - type === "checkbox" ? (e.target as HTMLInputElement).checked : value, - })); - }; - - const handleArrayChange = ( - index: number, - field: keyof FormData, - subfield: string, - value: string | number + e: React.ChangeEvent< + HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement + > ) => { + const { name, value } = e.target; setFormData((prev) => ({ ...prev, - [field]: (prev[field] as any[]).map((item, i) => - i === index ? { ...item, [subfield]: value } : item - ), - })); - }; - - const removeArrayItem = (field: keyof FormData, index: number) => { - setFormData((prev) => ({ - ...prev, - [field]: (prev[field] as any[]).filter((_, i) => i !== index), - })); - }; - const addArrayItem = (field: keyof FormData) => { - setFormData((prev) => ({ - ...prev, - [field]: [...(prev[field] as any[]), {}], + [name]: value, })); }; - const handleSubmit = async (e: React.FormEvent) => { + const handleSubmit = async (e: React.FormEvent) => { e.preventDefault(); - if (!session) { - console.error("No session found"); - return; - } + try { const response = await fetch("/api/therapists/register", { method: "POST", headers: { "Content-Type": "application/json", }, - body: JSON.stringify({ - ...formData, - certifications: formData.certifications.filter( - (cert) => cert.name && cert.issuedAt - ), - education: formData.education.filter( - (edu) => edu.institution && edu.startDate - ), - workExperience: formData.workExperience.filter( - (exp) => exp.company && exp.startDate - ), - }), + body: JSON.stringify(formData), }); + if (response.ok) { router.push("/TherapistDashboard"); - window.location.href = "/TherapistDashboard"; } else { - const errorData = await response.json(); - console.error("Failed to register therapist:", errorData.message); + console.error("Failed to register therapist:", response.statusText); } } catch (error) { - console.error("Error:", error); + console.error("Error registering therapist:", error); } }; @@ -215,544 +74,18 @@ export default function TherapistApply({ therapist }: TherapistApplyProps) { return
Loading...
; } + if (!session) { + return
Please sign in to apply as a therapist.
; + } + if (therapist) { - // ... (existing code for displaying therapist info) + return
You have already applied as a therapist.
; } return ( -
- - - - - - - depressionhub -
- Please enter your Full Name - - Please choose your profession - - setFormData((prev) => ({ - ...prev, - type: value as TherapistType, - })) - } - value={formData.type} - > - - - Professional - - - Student - - - - Date of Birth - - Gender - - Current Location - - Languages (comma-separated) - - setFormData((prev) => ({ - ...prev, - languages: e.target.value - .split(",") - .map((lang) => lang.trim()), - })) - } - placeholder="Languages" - required - size="sm" - className="w-full" - variant="flushed" - /> - Hours Available - - Years of Experience - - - Specializations (comma-separated) - - - setFormData((prev) => ({ - ...prev, - specializations: e.target.value - .split(",") - .map((spec) => spec.trim()), - })) - } - placeholder="Specializations" - required - size="sm" - className="w-full" - variant="flushed" - /> - How did you hear about us? - - Are you working elsewhere? - - setFormData((prev) => ({ - ...prev, - workingElsewhere: e.target.checked, - })) - } - > - Yes, Im working elsewhere - - - setFormData((prev) => ({ - ...prev, - workingElsewhere: e.target.checked, - })) - } - > - No, Im not working - - - Why are you joining? -