From 95a7a54111f5e0b8158ca8dbff3f50edd22b513d Mon Sep 17 00:00:00 2001 From: mit-27 Date: Sat, 27 Apr 2024 01:09:43 -0400 Subject: [PATCH 01/19] =?UTF-8?q?=F0=9F=94=A5=20Change=20layout=20of=20web?= =?UTF-8?q?app=20and=20remove=20stytch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/client-ts/package.json | 3 - .../app/{ => (Dashboard)}/api-keys/page.tsx | 2 +- .../{ => (Dashboard)}/configuration/page.tsx | 0 .../{ => (Dashboard)}/connections/page.tsx | 0 .../src/app/{ => (Dashboard)}/events/page.tsx | 0 .../{connections => (Dashboard)}/layout.tsx | 19 ++--- apps/client-ts/src/app/api-keys/layout.tsx | 29 ------- .../src/app/configuration/layout.tsx | 30 -------- apps/client-ts/src/app/dashboard/layout.tsx | 3 +- apps/client-ts/src/app/events/layout.tsx | 32 -------- apps/client-ts/src/app/layout.tsx | 21 +++-- .../client-ts/src/components/Nav/main-nav.tsx | 8 +- .../src/components/Nav/theme-provider.tsx | 9 +++ .../src/components/Nav/theme-toggle.tsx | 40 ++++++++++ .../src/components/RootLayout/index.tsx | 77 ++++++++++++------- pnpm-lock.yaml | 38 --------- 16 files changed, 132 insertions(+), 179 deletions(-) rename apps/client-ts/src/app/{ => (Dashboard)}/api-keys/page.tsx (98%) rename apps/client-ts/src/app/{ => (Dashboard)}/configuration/page.tsx (100%) rename apps/client-ts/src/app/{ => (Dashboard)}/connections/page.tsx (100%) rename apps/client-ts/src/app/{ => (Dashboard)}/events/page.tsx (100%) rename apps/client-ts/src/app/{connections => (Dashboard)}/layout.tsx (57%) delete mode 100644 apps/client-ts/src/app/api-keys/layout.tsx delete mode 100644 apps/client-ts/src/app/configuration/layout.tsx delete mode 100644 apps/client-ts/src/app/events/layout.tsx create mode 100644 apps/client-ts/src/components/Nav/theme-provider.tsx create mode 100644 apps/client-ts/src/components/Nav/theme-toggle.tsx diff --git a/apps/client-ts/package.json b/apps/client-ts/package.json index 72f395fcb..29ecdde9b 100644 --- a/apps/client-ts/package.json +++ b/apps/client-ts/package.json @@ -27,8 +27,6 @@ "@radix-ui/react-tabs": "^1.0.4", "@radix-ui/react-tooltip": "^1.0.7", "@radix-ui/react-scroll-area": "^1.0.5", - "@stytch/nextjs": "^18.0.0", - "@stytch/vanilla-js": "^4.7.1", "@tanstack/react-query": "^5.12.2", "@tanstack/react-query-devtools": "^5.25.0", "@tanstack/react-query-next-experimental": "^5.25.0", @@ -50,7 +48,6 @@ "react-hook-form": "^7.51.0", "recharts": "^2.10.1", "sonner": "^1.4.3", - "stytch": "^10.5.0", "tailwind-merge": "^2.2.1", "tailwindcss-animate": "^1.0.7", "zod": "^3.22.4", diff --git a/apps/client-ts/src/app/api-keys/page.tsx b/apps/client-ts/src/app/(Dashboard)/api-keys/page.tsx similarity index 98% rename from apps/client-ts/src/app/api-keys/page.tsx rename to apps/client-ts/src/app/(Dashboard)/api-keys/page.tsx index 675cc647e..c8cd68798 100644 --- a/apps/client-ts/src/app/api-keys/page.tsx +++ b/apps/client-ts/src/app/(Dashboard)/api-keys/page.tsx @@ -34,7 +34,7 @@ import config from "@/lib/config"; import * as z from "zod" import { zodResolver } from "@hookform/resolvers/zod" import { useForm } from "react-hook-form" -import { DataTableLoading } from "../../components/shared/data-table-loading"; +import { DataTableLoading } from "@/components/shared/data-table-loading"; const formSchema = z.object({ diff --git a/apps/client-ts/src/app/configuration/page.tsx b/apps/client-ts/src/app/(Dashboard)/configuration/page.tsx similarity index 100% rename from apps/client-ts/src/app/configuration/page.tsx rename to apps/client-ts/src/app/(Dashboard)/configuration/page.tsx diff --git a/apps/client-ts/src/app/connections/page.tsx b/apps/client-ts/src/app/(Dashboard)/connections/page.tsx similarity index 100% rename from apps/client-ts/src/app/connections/page.tsx rename to apps/client-ts/src/app/(Dashboard)/connections/page.tsx diff --git a/apps/client-ts/src/app/events/page.tsx b/apps/client-ts/src/app/(Dashboard)/events/page.tsx similarity index 100% rename from apps/client-ts/src/app/events/page.tsx rename to apps/client-ts/src/app/(Dashboard)/events/page.tsx diff --git a/apps/client-ts/src/app/connections/layout.tsx b/apps/client-ts/src/app/(Dashboard)/layout.tsx similarity index 57% rename from apps/client-ts/src/app/connections/layout.tsx rename to apps/client-ts/src/app/(Dashboard)/layout.tsx index 1ff2e6a2f..1506d93f6 100644 --- a/apps/client-ts/src/app/connections/layout.tsx +++ b/apps/client-ts/src/app/(Dashboard)/layout.tsx @@ -2,7 +2,6 @@ import { Inter } from "next/font/google"; import "./../globals.css"; import { RootLayout } from "@/components/RootLayout"; -import { useStytchSession } from "@stytch/nextjs"; import { useRouter } from "next/navigation"; import { useEffect } from "react"; import config from "@/lib/config"; @@ -14,18 +13,20 @@ export default function Layout({ }: Readonly<{ children: React.ReactNode; }>) { - const { session,isInitialized } = useStytchSession(); - const router = useRouter(); - useEffect(() => { - if(config.DISTRIBUTION !== "selfhosted" && isInitialized && !session){ - router.push("/b2c/login"); - } - }, [session,isInitialized, router]); + // const { session, isInitialized} = useStytchSession(); + // const router = useRouter(); + // useEffect(() => { + + // if(config.DISTRIBUTION !== "selfhosted" && isInitialized && !session){ + // router.replace("/b2c/login"); + // } + // }, [session,isInitialized, router]); return ( <> - + {children} + ); } diff --git a/apps/client-ts/src/app/api-keys/layout.tsx b/apps/client-ts/src/app/api-keys/layout.tsx deleted file mode 100644 index b291e97b0..000000000 --- a/apps/client-ts/src/app/api-keys/layout.tsx +++ /dev/null @@ -1,29 +0,0 @@ -'use client' -import { Inter } from "next/font/google"; -import "./../globals.css"; -import { RootLayout } from "@/components/RootLayout"; -import { useStytchSession } from "@stytch/nextjs"; -import { useRouter } from "next/navigation"; -import { useEffect } from "react"; -import config from "@/lib/config"; - -export default function Layout({ - children, -}: Readonly<{ - children: React.ReactNode; -}>) { - const { session,isInitialized } = useStytchSession(); - const router = useRouter(); - useEffect(() => { - if(config.DISTRIBUTION !== "selfhosted" && isInitialized && !session){ - router.replace("/b2c/login"); - } - }, [session,isInitialized, router]); - - return ( - <> - - {children} - - ); -} diff --git a/apps/client-ts/src/app/configuration/layout.tsx b/apps/client-ts/src/app/configuration/layout.tsx deleted file mode 100644 index 38ce8043d..000000000 --- a/apps/client-ts/src/app/configuration/layout.tsx +++ /dev/null @@ -1,30 +0,0 @@ -'use client' -import { Inter } from "next/font/google"; -import "./../globals.css"; -import { RootLayout } from "@/components/RootLayout"; -import { useStytchSession } from "@stytch/nextjs"; -import { useRouter } from "next/navigation"; -import { useEffect } from "react"; -import config from "@/lib/config"; - -export default function Layout({ - children, -}: Readonly<{ - children: React.ReactNode; -}>) { - const { session,isInitialized } = useStytchSession(); - - const router = useRouter(); - useEffect(() => { - if(config.DISTRIBUTION !== "selfhosted" && isInitialized && !session){ - router.push("/b2c/login"); - } - }, [session, isInitialized, router]); - - return ( - <> - - {children} - - ); -} diff --git a/apps/client-ts/src/app/dashboard/layout.tsx b/apps/client-ts/src/app/dashboard/layout.tsx index 3d766efc6..993e672d9 100644 --- a/apps/client-ts/src/app/dashboard/layout.tsx +++ b/apps/client-ts/src/app/dashboard/layout.tsx @@ -24,8 +24,9 @@ export default function Layout({ return ( <> - + {children} + ); } diff --git a/apps/client-ts/src/app/events/layout.tsx b/apps/client-ts/src/app/events/layout.tsx deleted file mode 100644 index 6916486b2..000000000 --- a/apps/client-ts/src/app/events/layout.tsx +++ /dev/null @@ -1,32 +0,0 @@ -'use client' -import { Inter } from "next/font/google"; -import "./../globals.css"; -import { RootLayout } from "@/components/RootLayout"; -import { useStytchSession } from "@stytch/nextjs"; -import { useRouter } from "next/navigation"; -import { useEffect } from "react"; -import config from "@/lib/config"; - -const inter = Inter({ subsets: ["latin"] }); - -export default function Layout({ - children, -}: Readonly<{ - children: React.ReactNode; -}>) { - const { session, isInitialized} = useStytchSession(); - const router = useRouter(); - useEffect(() => { - - if(config.DISTRIBUTION !== "selfhosted" && isInitialized && !session){ - router.replace("/b2c/login"); - } - }, [session,isInitialized, router]); - - return ( - <> - - {children} - - ); -} diff --git a/apps/client-ts/src/app/layout.tsx b/apps/client-ts/src/app/layout.tsx index 865a96b3e..f1ba7bb41 100644 --- a/apps/client-ts/src/app/layout.tsx +++ b/apps/client-ts/src/app/layout.tsx @@ -3,6 +3,7 @@ import { Inter } from "next/font/google"; import "./globals.css"; import { Provider } from "@/components/Provider/provider"; import { Toaster } from "@/components/ui/sonner" +import {ThemeProvider} from '@/components/Nav/theme-provider' const inter = Inter({ subsets: ["latin"] }); @@ -17,12 +18,20 @@ export default function RootLayout({ children: React.ReactNode; }>) { return ( - - - - {children} - - + + + + + {children} + + + + ); diff --git a/apps/client-ts/src/components/Nav/main-nav.tsx b/apps/client-ts/src/components/Nav/main-nav.tsx index f51e83b42..913a06b28 100644 --- a/apps/client-ts/src/components/Nav/main-nav.tsx +++ b/apps/client-ts/src/components/Nav/main-nav.tsx @@ -11,15 +11,15 @@ export function MainNav({ onLinkClick: (name: string) => void; className: string; }) { - const [selectedItem, setSelectedItem] = useState("connections"); + const [selectedItem, setSelectedItem] = useState(""); const pathname = usePathname(); useEffect(() => { setSelectedItem(pathname.substring(1)) }, [pathname]) const navItemClassName = (itemName: string) => - `text-sm border-b font-medium w-full text-left px-4 py-2 dark:hover:bg-zinc-900 hover:bg-zinc-200 cursor-pointer ${ - selectedItem === itemName ? 'dark:bg-zinc-800 bg-zinc-200' : 'text-muted-foreground' + `group flex items-center rounded-md px-3 py-2 text-sm font-medium hover:bg-accent hover:text-accent-foreground cursor-pointer ${ + selectedItem === itemName ? 'bg-accent' : 'transparent' } transition-colors`; function click(e: MouseEvent, name: string) { @@ -29,7 +29,7 @@ export function MainNav({ return ( -
{children}
+
{children}
- - ) - :( - <> - )} - - ); + + + ) + }; \ No newline at end of file diff --git a/apps/client-ts/src/hooks/mutations/useFetchUserMutation.tsx b/apps/client-ts/src/hooks/mutations/useFetchUserMutation.tsx index c54a63100..2381f80ef 100644 --- a/apps/client-ts/src/hooks/mutations/useFetchUserMutation.tsx +++ b/apps/client-ts/src/hooks/mutations/useFetchUserMutation.tsx @@ -39,16 +39,16 @@ const useFetchUserMutation = () => { return useMutation({ mutationFn: verifyUser, onMutate: () => { - toast("Fetching the user !", { - description: "", - action: { - label: "Close", - onClick: () => console.log("Close"), - }, - }) + // toast("Fetching the user !", { + // description: "", + // action: { + // label: "Close", + // onClick: () => console.log("Close"), + // }, + // }) }, onError: (error) => { - toast("Fetch User failed !", { + toast.error("Fetch User failed !", { description: error as any, action: { label: "Close", @@ -62,7 +62,7 @@ const useFetchUserMutation = () => { // Cookies.set('access_token',data.access_token,{expires:1}); // console.log("Bearer Token in client Side : ",data.access_token); - toast("User has been fetched !", { + toast.success("User has been fetched !", { description: "", action: { label: "Close", diff --git a/apps/client-ts/src/hooks/mutations/useLoginMutation.tsx b/apps/client-ts/src/hooks/mutations/useLoginMutation.tsx index f17b86e34..5939dd8dc 100644 --- a/apps/client-ts/src/hooks/mutations/useLoginMutation.tsx +++ b/apps/client-ts/src/hooks/mutations/useLoginMutation.tsx @@ -55,16 +55,16 @@ const useLoginMutation = () => { return useMutation({ mutationFn: loginUser, onMutate: () => { - toast("Logging the user !", { - description: "", - action: { - label: "Close", - onClick: () => console.log("Close"), - }, - }) + // toast("Logging the user !", { + // description: "", + // action: { + // label: "Close", + // onClick: () => console.log("Close"), + // }, + // }) }, onError: (error) => { - toast("User generation failed !", { + toast.error("User generation failed !", { description: error as any, action: { label: "Close", @@ -78,7 +78,7 @@ const useLoginMutation = () => { Cookies.set('access_token',data.access_token,{expires:1}); console.log("Bearer Token in client Side : ",data.access_token); - toast("User has been generated !", { + toast.success("User has been generated !", { description: "", action: { label: "Close", diff --git a/packages/api/src/@core/connections/connections.controller.ts b/packages/api/src/@core/connections/connections.controller.ts index 2bbdb4053..cbe8f3088 100644 --- a/packages/api/src/@core/connections/connections.controller.ts +++ b/packages/api/src/@core/connections/connections.controller.ts @@ -1,4 +1,4 @@ -import { Controller, Get, Query, Res } from '@nestjs/common'; +import { Controller, Get, Query, Res, Param } from '@nestjs/common'; import { Response } from 'express'; import { CrmConnectionsService } from './crm/services/crm.connection.service'; import { LoggerService } from '@@core/logger/logger.service'; @@ -139,4 +139,20 @@ export class ConnectionsController { async getConnections() { return await this.prisma.connections.findMany(); } + + // @ApiOperation({ + // operationId: 'getConnectionsByUser', + // summary: 'Retrieve connections by user', + // }) + // @ApiResponse({ status: 200 }) + // @Get(':userId') + // getProjectsByUser(@Param('userId') userId: string) { + // return this.prisma.connections.findMany( + // { + // where: { + // id + // } + // } + // ); + // } } From a4ecb0452f485318009cd6737bae0deba194aaca Mon Sep 17 00:00:00 2001 From: mit-27 Date: Tue, 30 Apr 2024 04:28:13 -0400 Subject: [PATCH 18/19] =?UTF-8?q?=F0=9F=90=9B=20Fix=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/client-ts/src/app/(Dashboard)/layout.tsx | 20 +++++-------------- .../hooks/mutations/useFetchUserMutation.tsx | 1 + 2 files changed, 6 insertions(+), 15 deletions(-) diff --git a/apps/client-ts/src/app/(Dashboard)/layout.tsx b/apps/client-ts/src/app/(Dashboard)/layout.tsx index 296d2c7d7..cf01b3cf5 100644 --- a/apps/client-ts/src/app/(Dashboard)/layout.tsx +++ b/apps/client-ts/src/app/(Dashboard)/layout.tsx @@ -6,7 +6,7 @@ import { useRouter } from "next/navigation"; import { useEffect, useState } from "react"; import Cookies from 'js-cookie'; import useFetchUserMutation from "@/hooks/mutations/useFetchUserMutation"; -import useProfileStore from '@/state/profileStore'; + const inter = Inter({ subsets: ["latin"] }); @@ -19,32 +19,22 @@ export default function Layout({ const [userInitialized,setUserInitialized] = useState(false) const router = useRouter() - const {profile} = useProfileStore() const {mutate: fetchUserMutate} = useFetchUserMutation() useEffect(() => { - - if(profile) - { - setUserInitialized(true) - } - if(!Cookies.get('access_token')) { router.replace("/b2c/login") } else { - if(!userInitialized && !profile) - { - fetchUserMutate(Cookies.get('access_token'),{ - onError: () => router.replace("/b2c/login"), - onSuccess: () => setUserInitialized(true) - }) - } + fetchUserMutate(Cookies.get('access_token'),{ + onError: () => router.replace("/b2c/login"), + onSuccess: () => setUserInitialized(true) + }) } },[]) diff --git a/apps/client-ts/src/hooks/mutations/useFetchUserMutation.tsx b/apps/client-ts/src/hooks/mutations/useFetchUserMutation.tsx index 2381f80ef..51a5ac22b 100644 --- a/apps/client-ts/src/hooks/mutations/useFetchUserMutation.tsx +++ b/apps/client-ts/src/hooks/mutations/useFetchUserMutation.tsx @@ -48,6 +48,7 @@ const useFetchUserMutation = () => { // }) }, onError: (error) => { + Cookies.remove('access_token') toast.error("Fetch User failed !", { description: error as any, action: { From 11f2133a487a988d8c565b1880cdb74dbe19a5c8 Mon Sep 17 00:00:00 2001 From: mit-27 Date: Tue, 30 Apr 2024 14:15:48 -0400 Subject: [PATCH 19/19] =?UTF-8?q?=F0=9F=91=94=20Add=20alert=20dialog=20for?= =?UTF-8?q?=20connection=20and=20api-keys?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/app/(Dashboard)/api-keys/page.tsx | 90 +++++++++++-------- .../Connection/AddConnectionButton.tsx | 16 ++++ .../hooks/mutations/useProjectMutation.tsx | 2 +- 3 files changed, 70 insertions(+), 38 deletions(-) diff --git a/apps/client-ts/src/app/(Dashboard)/api-keys/page.tsx b/apps/client-ts/src/app/(Dashboard)/api-keys/page.tsx index d9cb52d67..0e35dbe7d 100644 --- a/apps/client-ts/src/app/(Dashboard)/api-keys/page.tsx +++ b/apps/client-ts/src/app/(Dashboard)/api-keys/page.tsx @@ -144,44 +144,60 @@ export default function Page() { - - Add New Api Key - - Never share this key, you must saved it it will be displayed once ! - - - -
- -
-
- ( - - API Key Identifier - - - - - This is the API Key Identifier of system. - - - - )} - /> + {idProject==="" ? ( + <> + + + +

You have to create project in order to create API Key.

+ + + + + ) + : + ( + <> + + Add New Api Key + + Never share this key, you must saved it it will be displayed once ! + + + + + +
+
+ ( + + API Key Identifier + + + + + This is the API Key Identifier of system. + + + + )} + /> +
-
- - - - - - + + + + + + + + )}
diff --git a/apps/client-ts/src/components/Connection/AddConnectionButton.tsx b/apps/client-ts/src/components/Connection/AddConnectionButton.tsx index 1344dce95..341f451a3 100644 --- a/apps/client-ts/src/components/Connection/AddConnectionButton.tsx +++ b/apps/client-ts/src/components/Connection/AddConnectionButton.tsx @@ -169,6 +169,20 @@ const AddConnectionButton = ({ + {idProject==="" ? ( + <> + + + +

You have to create project in order to create Connection.

+ + + + + ) + : + ( + <> Share this magic link with your customers @@ -244,6 +258,8 @@ const AddConnectionButton = ({ + + )}
) diff --git a/apps/client-ts/src/hooks/mutations/useProjectMutation.tsx b/apps/client-ts/src/hooks/mutations/useProjectMutation.tsx index 63c98b67b..42c01a4bc 100644 --- a/apps/client-ts/src/hooks/mutations/useProjectMutation.tsx +++ b/apps/client-ts/src/hooks/mutations/useProjectMutation.tsx @@ -47,7 +47,7 @@ const useProjectMutation = () => { }, onSuccess: (data) => { - console.log(data) + // console.log(data) queryClient.setQueryData(['projects'], (oldQueryData = []) => { return [...oldQueryData, data]; });