From 11560bf0addf44de3cd822b5d15591a400c7f8c7 Mon Sep 17 00:00:00 2001 From: nael Date: Mon, 20 May 2024 08:43:08 +0200 Subject: [PATCH 1/2] :sparkles: Scrolbar fixes --- .../src/components/Configuration/AddAuthCredentialsForm.tsx | 2 +- .../components/Configuration/Connector/ConnectorDisplay.tsx | 2 +- .../src/components/Configuration/Connector/ConnectorList.tsx | 4 ++-- .../src/components/shared/data-table-webhook-scopes.tsx | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/apps/client-ts/src/components/Configuration/AddAuthCredentialsForm.tsx b/apps/client-ts/src/components/Configuration/AddAuthCredentialsForm.tsx index 9dea608ff..2be360979 100644 --- a/apps/client-ts/src/components/Configuration/AddAuthCredentialsForm.tsx +++ b/apps/client-ts/src/components/Configuration/AddAuthCredentialsForm.tsx @@ -527,7 +527,7 @@ const AddAuthCredentialsForm = (prop : propType) => { {copied ? 'Copied!' : <>

Copy

- + } diff --git a/apps/client-ts/src/components/Configuration/Connector/ConnectorDisplay.tsx b/apps/client-ts/src/components/Configuration/Connector/ConnectorDisplay.tsx index 628a48fb6..dad3dbce7 100644 --- a/apps/client-ts/src/components/Configuration/Connector/ConnectorDisplay.tsx +++ b/apps/client-ts/src/components/Configuration/Connector/ConnectorDisplay.tsx @@ -346,7 +346,7 @@ export function ConnectorDisplay({ item }: ItemDisplayProps) { {copied ? 'Copied!' : ( <>

Copy

- + )} diff --git a/apps/client-ts/src/components/Configuration/Connector/ConnectorList.tsx b/apps/client-ts/src/components/Configuration/Connector/ConnectorList.tsx index 6088bda14..8912954ce 100644 --- a/apps/client-ts/src/components/Configuration/Connector/ConnectorList.tsx +++ b/apps/client-ts/src/components/Configuration/Connector/ConnectorList.tsx @@ -13,11 +13,11 @@ export function ConnectorList({ items }: ConnectorListProps) { const [connector, setConnector] = useConnector() return ( - +
{items.map((item) => ( @@ -192,8 +187,10 @@ export default function Page() {
- - + + diff --git a/apps/client-ts/src/app/(Dashboard)/b2c/profile/page.tsx b/apps/client-ts/src/app/(Dashboard)/b2c/profile/page.tsx index 1d73e54ad..6bfd9fd9b 100644 --- a/apps/client-ts/src/app/(Dashboard)/b2c/profile/page.tsx +++ b/apps/client-ts/src/app/(Dashboard)/b2c/profile/page.tsx @@ -18,12 +18,9 @@ import { useQueryClient } from '@tanstack/react-query'; const Profile = () => { - const { profile, setProfile } = useProfileStore(); const { setIdProject } = useProjectStore(); const queryClient = useQueryClient(); - - const router = useRouter(); @@ -33,7 +30,6 @@ const Profile = () => { setProfile(null) setIdProject("") queryClient.clear() - } return ( @@ -68,5 +64,4 @@ const Profile = () => { ); }; - export default Profile; \ No newline at end of file diff --git a/apps/client-ts/src/app/(Dashboard)/configuration/page.tsx b/apps/client-ts/src/app/(Dashboard)/configuration/page.tsx index 4d44232cf..01c866fa0 100644 --- a/apps/client-ts/src/app/(Dashboard)/configuration/page.tsx +++ b/apps/client-ts/src/app/(Dashboard)/configuration/page.tsx @@ -18,40 +18,38 @@ import { TabsList, TabsTrigger, } from "@/components/ui/tabs" -import { LinkedUsersPage } from "@/components/Configuration/LinkedUsersPage"; +import { LinkedUsersPage } from "@/components/Configuration/LinkedUsers/LinkedUsersPage"; import { Button } from "@/components/ui/button"; import { PlusCircledIcon } from "@radix-ui/react-icons"; -import { FModal } from "@/components/Configuration/FieldMappingModal" +import { FModal } from "@/components/Configuration/FieldMappings/FieldMappingModal" import { Separator } from "@/components/ui/separator"; -import FieldMappingsTable from "@/components/Configuration/FieldMappingsTable"; -import AddLinkedAccount from "@/components/Configuration/AddLinkedAccount"; -import useLinkedUsers from "@/hooks/useLinkedUsers"; -import useFieldMappings from "@/hooks/useFieldMappings"; +import FieldMappingsTable from "@/components/Configuration/FieldMappings/FieldMappingsTable"; +import AddLinkedAccount from "@/components/Configuration/LinkedUsers/AddLinkedAccount"; +import useLinkedUsers from "@/hooks/get/useLinkedUsers"; +import useFieldMappings from "@/hooks/get/useFieldMappings"; import { Skeleton } from "@/components/ui/skeleton"; import { useState } from "react"; -import { LoadingSpinner } from "@/components/Connection/LoadingSpinner"; -import AddWebhook from "@/components/Configuration/AddWebhook"; +import AddWebhook from "@/components/Configuration/Webhooks/AddWebhook"; import { cn } from "@/lib/utils"; -import { WebhooksPage } from "@/components/Configuration/WebhooksPage"; -import useWebhooks from "@/hooks/useWebhooks"; +import { WebhooksPage } from "@/components/Configuration/Webhooks/WebhooksPage"; +import useWebhooks from "@/hooks/get/useWebhooks"; import { usePostHog } from 'posthog-js/react' import config from "@/lib/config"; import useProjectStore from "@/state/projectStore"; -import AddAuthCredentials from "@/components/Configuration/AddAuthCredentials"; -import AuthCredentialsTable from "@/components/Configuration/AuthCredentialsTable"; -import useConnectionStrategies from "@/hooks/useConnectionStrategies"; +import useConnectionStrategies from "@/hooks/get/useConnectionStrategies"; import { extractAuthMode,extractProvider,extractVertical} from '@panora/shared' import { Heading } from "@/components/ui/heading"; -import CustomConnectorPage from "@/components/Configuration/CustomConnectorPage"; +import CustomConnectorPage from "@/components/Configuration/Connector/CustomConnectorPage"; +import { PlusCircle } from "lucide-react"; export default function Page() { const {idProject} = useProjectStore(); const { data: linkedUsers, isLoading, error } = useLinkedUsers(); const { data: webhooks, isLoading: isWebhooksLoading, error: isWebhooksError } = useWebhooks(); - const {data: connectionStrategies, isLoading: isConnectionStrategiesLoading,error: isConnectionStategiesError} = useConnectionStrategies() - + const { data: connectionStrategies, isLoading: isConnectionStrategiesLoading, error: isConnectionStategiesError} = useConnectionStrategies() const { data: mappings, isLoading: isFieldMappingsLoading, error: isFieldMappingsError } = useFieldMappings(); + const [open, setOpen] = useState(false); const handleClose = () => { setOpen(false); @@ -79,13 +77,11 @@ export default function Page() { console.log("error fetching webhooks.."); } - if(isConnectionStrategiesLoading) - { + if(isConnectionStrategiesLoading){ console.log("loading Connection Strategies..."); } - if(isConnectionStategiesError) - { + if(isConnectionStategiesError){ console.log("error Fetching connection Strategies!") } @@ -99,8 +95,6 @@ export default function Page() { data_type: mapping.data_type, })) - // console.log(ConnectionStrategies) - const mappingConnectionStrategies = connectionStrategies?.map(cs => ({ id_cs : cs.id_connection_strategy, provider_name : extractProvider(cs.type), @@ -110,8 +104,6 @@ export default function Page() { status: cs.status })) - console.log(mappingConnectionStrategies) - return (
@@ -157,19 +149,19 @@ export default function Page() {
- @@ -211,28 +203,9 @@ export default function Page() {
- -
- - - - Your Providers - - Use and setup the credentials of your providers. - - - - - - - -
-
- -
diff --git a/apps/client-ts/src/app/(Dashboard)/layout.tsx b/apps/client-ts/src/app/(Dashboard)/layout.tsx index 195d4fc98..84449c320 100644 --- a/apps/client-ts/src/app/(Dashboard)/layout.tsx +++ b/apps/client-ts/src/app/(Dashboard)/layout.tsx @@ -1,13 +1,10 @@ 'use client' -import { Inter } from "next/font/google"; import "./../globals.css"; import { RootLayout } from "@/components/RootLayout"; import { useRouter } from "next/navigation"; import { useEffect, useState } from "react"; import Cookies from 'js-cookie'; -import useFetchUserMutation from "@/hooks/mutations/useFetchUserMutation"; - -const inter = Inter({ subsets: ["latin"] }); +import useUser from "@/hooks/get/useUser"; export default function Layout({ children, @@ -17,27 +14,21 @@ export default function Layout({ const [userInitialized,setUserInitialized] = useState(false) const router = useRouter() - const {mutate: fetchUserMutate} = useFetchUserMutation() - - + const { mutate } = useUser() useEffect(() => { - if(!Cookies.get('access_token')) - { - router.replace("/b2c/login") - } - else - { - - fetchUserMutate(Cookies.get('access_token'),{ + if(!Cookies.get('access_token')) { + router.replace("/b2c/login") + }else { + mutate( + Cookies.get('access_token'), + { onError: () => router.replace("/b2c/login"), onSuccess: () => setUserInitialized(true) - }) + } + ) } },[]) - - - return ( <> {userInitialized ? ( diff --git a/apps/client-ts/src/app/b2c/login/page.tsx b/apps/client-ts/src/app/b2c/login/page.tsx index fe12e7715..5784cd977 100644 --- a/apps/client-ts/src/app/b2c/login/page.tsx +++ b/apps/client-ts/src/app/b2c/login/page.tsx @@ -11,17 +11,15 @@ import { useRouter } from "next/navigation"; import { useEffect, useState } from "react"; import Cookies from 'js-cookie'; import useProfileStore from "@/state/profileStore"; -import useFetchUserMutation from "@/hooks/mutations/useFetchUserMutation"; +import useUser from "@/hooks/get/useUser"; export default function Page() { - const [userInitialized,setUserInitialized] = useState(true) - const {mutate : fetchUserMutate} = useFetchUserMutation() + const {mutate} = useUser() const router = useRouter() const {profile} = useProfileStore(); useEffect(() => { - if(profile) { router.replace('/connections'); @@ -38,7 +36,7 @@ export default function Page() { if(Cookies.get('access_token') && !profile) { - fetchUserMutate(Cookies.get('access_token'),{ + mutate(Cookies.get('access_token'),{ onError: () => setUserInitialized(false) }) } diff --git a/apps/client-ts/src/app/dashboard/page.tsx b/apps/client-ts/src/app/dashboard/page.tsx deleted file mode 100644 index a0a5ef377..000000000 --- a/apps/client-ts/src/app/dashboard/page.tsx +++ /dev/null @@ -1,91 +0,0 @@ -'use client'; - -import { Line, LineChart, ResponsiveContainer} from "recharts"; -import { Overview } from "@/components/Dashboard/overview"; -import { Button } from "@/components/ui/button"; -import { CalendarDateRangePicker } from "@/components/Dashboard/date-range-picker" -import { - Card, - CardContent, - CardDescription, - CardHeader, - CardTitle, -} from "@/components/ui/card" -import { - Tabs, - TabsContent, -} from "@/components/ui/tabs" - -export default function Page() { - - const data = [ - { name: 'Jan', revenue: 15000 }, - { name: 'Feb', revenue: 21000 }, - { name: 'Mar', revenue: 18000 }, - { name: 'Apr', revenue: 25000 }, - { name: 'May', revenue: 27000 }, - ]; - - return ( -
-
-
-

Dashboard

-
- - -
-
- - -
- - - Total API Requests - - - - - -
- - - Total Connections - - +39 from last month - - - - - - - - - - - - - - Linked Accounts - - +78% from last month - - - - - - - - - - -
- -
-
-
-
- -
- ); - } diff --git a/apps/client-ts/src/components/ApiKeys/columns.tsx b/apps/client-ts/src/components/ApiKeys/columns.tsx new file mode 100644 index 000000000..cb399e906 --- /dev/null +++ b/apps/client-ts/src/components/ApiKeys/columns.tsx @@ -0,0 +1,100 @@ +"use client" + +import { ColumnDef } from "@tanstack/react-table" +import { Badge } from "@/components/ui/badge" +import { ApiKey } from "./schema" +import { DataTableColumnHeader } from "../shared/data-table-column-header" +import { DataTableRowActions } from "../shared/data-table-row-actions" +import { PasswordInput } from "../ui/password-input" +import { useState } from "react" +import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "../ui/tooltip" +import { Button } from "../ui/button" + +export function useColumns() { + const [copiedState, setCopiedState] = useState<{ [key: string]: boolean }>({}); + + const handleCopy = (token: string) => { + navigator.clipboard.writeText(token); + setCopiedState((prevState) => ({ + ...prevState, + [token]: true, + })); + setTimeout(() => { + setCopiedState((prevState) => ({ + ...prevState, + [token]: false, + })); + }, 2000); // Reset copied state after 2 seconds + }; + + return [ + { + accessorKey: "name", + header: ({ column }) => ( + + ), + cell: ({ row }) =>
{row.getValue("name")}
, + enableSorting: false, + enableHiding: false, + }, + { + accessorKey: "token", + header: ({ column }) => ( + + ), + cell: ({ row }) => { + const token: string = row.getValue("token"); + const copied = copiedState[token] || false; + + return ( +
+
+ +
+
handleCopy(token)} + > + + + + + + +

Copy Key

+
+
+
+ +
+
+ ); + }, + }, + { + accessorKey: "created", + header: ({ column }) => ( + + ), + cell: ({ row }) =>
{row.getValue("created")}
, + filterFn: (row, id, value) => { + return value.includes(row.getValue(id)) + }, + }, + { + id: "actions", + cell: ({ row }) => , + }, + ] as ColumnDef[]; +} diff --git a/apps/client-ts/src/components/ApiKeys/data/api-keys.ts b/apps/client-ts/src/components/ApiKeys/data/api-keys.ts deleted file mode 100644 index c31e53e38..000000000 --- a/apps/client-ts/src/components/ApiKeys/data/api-keys.ts +++ /dev/null @@ -1,22 +0,0 @@ -export const API_KEYS = [ - { - "name": "API Key 1", - "token": "sk_test_e74394c2-f063-4693-af5f-84b7281de5e8", - "created": "Jul 31, 2019" - }, - { - "name": "API Key 1", - "token": "sk_test_e74394c2-f063-4693-af5f-84b7281de5e8", - "created": "Jul 31, 2019" - }, - { - "name": "API Key 1", - "token": "sk_test_e74394c2-f063-4693-af5f-84b7281de5e8", - "created": "Jul 31, 2019" - }, - { - "name": "API Key 1", - "token": "sk_test_e74394c2-f063-4693-af5f-84b7281de5e8", - "created": "Jul 31, 2019" - } -] \ No newline at end of file diff --git a/apps/client-ts/src/components/ApiKeys/data/columns.tsx b/apps/client-ts/src/components/ApiKeys/data/columns.tsx deleted file mode 100644 index c33d1577a..000000000 --- a/apps/client-ts/src/components/ApiKeys/data/columns.tsx +++ /dev/null @@ -1,63 +0,0 @@ -"use client" - -import { ColumnDef } from "@tanstack/react-table" -import { Badge } from "@/components/ui/badge" - - -import { ApiKey } from "./schema" -import { DataTableColumnHeader } from "../../shared/data-table-column-header" -import { DataTableRowActions } from "../../shared/data-table-row-actions" - -function insertDots(originalString: string): string { - if(!originalString) return ""; - if (originalString.length <= 50) { - return originalString; - } - return originalString.substring(0, 50 - 3) + '...'; -} - -export const columns: ColumnDef[] = [ - { - accessorKey: "name", - header: ({ column }) => ( - - ), - cell: ({ row }) =>
{row.getValue("name")}
, - enableSorting: false, - enableHiding: false, - }, - { - accessorKey: "token", - header: ({ column }) => ( - - ), - cell: ({ row }) => -
-
- {insertDots(row.getValue("token"))} -
-
navigator.clipboard.writeText(row.getValue("token"))} - > - -
-
- , - - }, - { - accessorKey: "created", - header: ({ column }) => ( - - ), - cell: ({ row }) =>
{row.getValue("created")}
, - filterFn: (row, id, value) => { - return value.includes(row.getValue(id)) - }, - }, - { - id: "actions", - cell: ({ row }) => , - }, -] \ No newline at end of file diff --git a/apps/client-ts/src/components/ApiKeys/data/data.tsx b/apps/client-ts/src/components/ApiKeys/data/data.tsx deleted file mode 100644 index 03743ba86..000000000 --- a/apps/client-ts/src/components/ApiKeys/data/data.tsx +++ /dev/null @@ -1,71 +0,0 @@ -import { - ArrowDownIcon, - ArrowRightIcon, - ArrowUpIcon, - CheckCircledIcon, - CircleIcon, - CrossCircledIcon, - QuestionMarkCircledIcon, - StopwatchIcon, - } from "@radix-ui/react-icons" - - export const labels = [ - { - value: "bug", - label: "Bug", - }, - { - value: "feature", - label: "Feature", - }, - { - value: "documentation", - label: "Documentation", - }, - ] - - export const statuses = [ - { - value: "backlog", - label: "Backlog", - icon: QuestionMarkCircledIcon, - }, - { - value: "todo", - label: "Todo", - icon: CircleIcon, - }, - { - value: "in progress", - label: "In Progress", - icon: StopwatchIcon, - }, - { - value: "done", - label: "Done", - icon: CheckCircledIcon, - }, - { - value: "canceled", - label: "Canceled", - icon: CrossCircledIcon, - }, - ] - - export const priorities = [ - { - label: "Low", - value: "low", - icon: ArrowDownIcon, - }, - { - label: "Medium", - value: "medium", - icon: ArrowRightIcon, - }, - { - label: "High", - value: "high", - icon: ArrowUpIcon, - }, - ] \ No newline at end of file diff --git a/apps/client-ts/src/components/ApiKeys/data/seed.ts b/apps/client-ts/src/components/ApiKeys/data/seed.ts deleted file mode 100644 index b35a5ef17..000000000 --- a/apps/client-ts/src/components/ApiKeys/data/seed.ts +++ /dev/null @@ -1,20 +0,0 @@ -import fs from "fs" -import path from "path" -import { faker } from "@faker-js/faker" - -import { labels, priorities, statuses } from "./data" - -const tasks = Array.from({ length: 100 }, () => ({ - id: `TASK-${faker.number.int({ min: 1000, max: 9999 })}`, - title: faker.hacker.phrase().replace(/^./, (letter) => letter.toUpperCase()), - status: faker.helpers.arrayElement(statuses).value, - label: faker.helpers.arrayElement(labels).value, - direction: faker.helpers.arrayElement(priorities).value, -})) - -fs.writeFileSync( - path.join(__dirname, "tasks.json"), - JSON.stringify(tasks, null, 2) -) - -console.log("✅ Tasks data generated.") \ No newline at end of file diff --git a/apps/client-ts/src/components/ApiKeys/data/schema.ts b/apps/client-ts/src/components/ApiKeys/schema.ts similarity index 62% rename from apps/client-ts/src/components/ApiKeys/data/schema.ts rename to apps/client-ts/src/components/ApiKeys/schema.ts index eb8015db0..b7fcd2442 100644 --- a/apps/client-ts/src/components/ApiKeys/data/schema.ts +++ b/apps/client-ts/src/components/ApiKeys/schema.ts @@ -1,8 +1,7 @@ import { z } from "zod" -// We're keeping a simple non-relational schema here. -// IRL, you will have a schema for your data models. export const apiKeySchema = z.object({ + id_api_key: z.string(), name: z.string(), token: z.string(), created: z.string(), diff --git a/apps/client-ts/src/components/Auth/CustomLoginComponent/CreateUserForm.tsx b/apps/client-ts/src/components/Auth/CustomLoginComponent/CreateUserForm.tsx index 314114c9b..c8705d92a 100644 --- a/apps/client-ts/src/components/Auth/CustomLoginComponent/CreateUserForm.tsx +++ b/apps/client-ts/src/components/Auth/CustomLoginComponent/CreateUserForm.tsx @@ -15,7 +15,6 @@ import * as z from "zod" import { Form, FormControl, - FormDescription, FormField, FormItem, FormLabel, @@ -24,7 +23,7 @@ import { import { zodResolver } from "@hookform/resolvers/zod" import { useForm } from "react-hook-form" import { PasswordInput } from '@/components/ui/password-input' -import useCreateUserMutation from '@/hooks/mutations/useCreateUserMutation' +import useCreateUser from '@/hooks/create/useCreateUser' const formSchema = z.object({ first_name: z.string().min(2,{ @@ -44,7 +43,7 @@ const formSchema = z.object({ const CreateUserForm = () => { - const {mutate : createUserMutate} = useCreateUserMutation(); + const {mutate : createUserMutate} = useCreateUser(); const form = useForm>({ resolver: zodResolver(formSchema), @@ -153,7 +152,7 @@ const CreateUserForm = () => { - + diff --git a/apps/client-ts/src/components/Auth/CustomLoginComponent/LoginUserForm.tsx b/apps/client-ts/src/components/Auth/CustomLoginComponent/LoginUserForm.tsx index 5726493bc..076257337 100644 --- a/apps/client-ts/src/components/Auth/CustomLoginComponent/LoginUserForm.tsx +++ b/apps/client-ts/src/components/Auth/CustomLoginComponent/LoginUserForm.tsx @@ -10,13 +10,11 @@ import { } from "@/components/ui/card" import { Input } from "@/components/ui/input" import { Button } from "@/components/ui/button" -import { Label } from "@/components/ui/label" import { PasswordInput } from '@/components/ui/password-input' import * as z from "zod" import { Form, FormControl, - FormDescription, FormField, FormItem, FormLabel, @@ -24,7 +22,7 @@ import { } from "@/components/ui/form" import { zodResolver } from "@hookform/resolvers/zod" import { useForm } from "react-hook-form" -import useLoginMutation from '@/hooks/mutations/useLoginMutation' +import useCreateLogin from '@/hooks/create/useCreateLogin' import { useRouter } from "next/navigation"; const formSchema = z.object({ @@ -40,7 +38,7 @@ const LoginUserForm = () => { const router = useRouter() - const {mutate : loginMutate} = useLoginMutation() + const {mutate : loginMutate} = useCreateLogin() const form = useForm>({ resolver: zodResolver(formSchema), @@ -51,7 +49,6 @@ const LoginUserForm = () => { }) const onSubmit = (values: z.infer) => { - loginMutate({ email:values.email, password_hash:values.password diff --git a/apps/client-ts/src/components/Configuration/AddAuthCredentials.tsx b/apps/client-ts/src/components/Configuration/AddAuthCredentials.tsx deleted file mode 100644 index 572aa41c2..000000000 --- a/apps/client-ts/src/components/Configuration/AddAuthCredentials.tsx +++ /dev/null @@ -1,57 +0,0 @@ -'use client' - -import { Button } from "@/components/ui/button" -import { - Dialog, - DialogContent, - DialogTrigger, -} from "@/components/ui/dialog" - -import { PlusCircledIcon } from "@radix-ui/react-icons" -import { useState } from "react" -import useProjectStore from "@/state/projectStore" - -import { cn } from "@/lib/utils" - -import { usePostHog } from 'posthog-js/react' -import config from "@/lib/config" - -import AddAuthCredentialsForm from "./AddAuthCredentialsForm" - -const AddAuthCredentials = () => { - const [open, setOpen] = useState(false); - const posthog = usePostHog() - const {idProject} = useProjectStore(); - - const handleOpenChange = (open: boolean) => { - setOpen(open) - // form.reset() - }; - - return ( - - - - - - setOpen(false)} /> - - - ) -} - -export default AddAuthCredentials; \ No newline at end of file diff --git a/apps/client-ts/src/components/Configuration/AddAuthCredentialsForm.tsx b/apps/client-ts/src/components/Configuration/AddAuthCredentialsForm.tsx deleted file mode 100644 index 2be360979..000000000 --- a/apps/client-ts/src/components/Configuration/AddAuthCredentialsForm.tsx +++ /dev/null @@ -1,613 +0,0 @@ -import React,{useEffect, useState} from 'react' -import { CaretSortIcon, CheckIcon } from "@radix-ui/react-icons" -import {ScrollArea} from '@/components/ui/scrollbar' -import { Input } from "@/components/ui/input" -import { zodResolver } from "@hookform/resolvers/zod" -import { useForm } from "react-hook-form" -import { Button } from "@/components/ui/button" -import config from "@/lib/config" -import { - Command, - CommandEmpty, - CommandGroup, - CommandInput, - CommandItem, - } from "@/components/ui/command" -import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue, - } from "@/components/ui/select" -import { - CardContent, - CardDescription, - CardFooter, - CardHeader, - CardTitle, -} from "@/components/ui/card" -import { - Popover, - PopoverContent, - PopoverTrigger, - } from "@/components/ui/popover" -import { - Form, - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage, -} from "@/components/ui/form" -import {PasswordInput} from '@/components/ui/password-input' -import { ALL_PROVIDERS,getLogoURL,providerToType,AuthStrategy } from "@panora/shared" -import { z } from "zod" -import { cn } from "@/lib/utils" -import useProjectStore from "@/state/projectStore" -import useConnectionStrategyMutation from '@/hooks/mutations/useConnectionStrategy' -import { usePostHog } from 'posthog-js/react' -import useConnectionStrategyAuthCredentialsMutation from '@/hooks/mutations/useConnectionStrategyAuthCredentials' -import useUpdateConnectionStrategyMutation from '@/hooks/mutations/useUpdateConnectionStrategy' - - - -const formSchema = z.object({ - provider_name: z.string().min(2, { - message: "Provider should be selected.", - }), - auth_type : z.string().min(2, { - message: "Authentication type should be selected.", - }), - client_id : z.string({ - required_error: "Please Enter a Client ID", - }), - client_secret : z.string({ - required_error: "Please Enter a Client Secret", - }), - scope : z.string({ - required_error: "Please Enter a scope", - }), - api_key: z.string({ - required_error: "Please Enter a API Key", - }), - username: z.string({ - required_error: "Please Enter Username", - }), - secret: z.string({ - required_error: "Please Enter Secret", - }), -}) - - interface propType { - performUpdate: boolean, - closeDialog?: () => void, - data?:{ - provider_name: string, - auth_type: string, - status: boolean, - id_cs: string, - vertical: string, - type: string, - // client_id?:string, - // client_secret?:string, - // scope?:string, - // api_key?:string, - // username?:string, - // secret?:string, - } - - } - -const AddAuthCredentialsForm = (prop : propType) => { - const [copied, setCopied] = useState(false); - const [popoverOpen,setPopOverOpen] = useState(false); - const {idProject} = useProjectStore() - const {mutate : createCS} = useConnectionStrategyMutation(); - const {mutate :updateCS} = useUpdateConnectionStrategyMutation() - const {mutateAsync : fetchCredentials, data : fetchedData} = useConnectionStrategyAuthCredentialsMutation(); - - const form = useForm>({ - resolver: zodResolver(formSchema), - defaultValues: { - provider_name: prop.data?.provider_name? `${prop.data?.provider_name.toLowerCase()}-${prop.data?.vertical.toUpperCase()}` : "", - auth_type: prop.data?.auth_type? prop.data?.auth_type : "", - client_id:"", - client_secret:"", - scope:"", - api_key:"", - username:"", - secret:"", - }, - - }) - - const posthog = usePostHog() - - useEffect(() => { - - if(prop.performUpdate) - { - - console.log(prop.data) - - fetchCredentials({ - type: prop.data?.type, - attributes: prop.data?.auth_type===AuthStrategy.oauth2 ? ["client_id","client_secret","scope"] - : prop.data?.auth_type===AuthStrategy.api_key ? ["api_key"] : ["username","secret"] - }, - { - onSuccess(data, variables, context) { - - if(prop.data?.auth_type===AuthStrategy.oauth2) - { - form.setValue("client_id",data[0]) - form.setValue("client_secret",data[1]) - form.setValue("scope",data[2]) - - - } - else if(prop.data?.auth_type===AuthStrategy.api_key) - { - form.setValue("api_key",data[0]) - - } - else - { - form.setValue("username",data[0]) - form.setValue("secret",data[0]) - - } - - }, - } - ) - } - - },[]) - - const handlePopOverClose = () => { - setPopOverOpen(false); - } - - const handleCopy = async () => { - try { - await navigator.clipboard.writeText("localhost:3000/connections/oauth/callback") - setCopied(true); - setTimeout(() => setCopied(false), 2000); // Reset copied state after 2 seconds - } catch (err) { - console.error('Failed to copy: ', err); - } - }; - - - - const Watch = form.watch() - - function onSubmit(values: z.infer) { - - - const {client_id,client_secret,scope,provider_name,api_key,auth_type,secret,username} = values - - - switch(values.auth_type) - { - case AuthStrategy.oauth2: - if(client_id==="" || client_secret==="" || scope==="") - { - if(client_id==="") - { - form.setError("client_id",{"message":"Please Enter Client ID"}) - } - if(client_secret==="") - { - form.setError("client_secret",{"message":"Please Enter Client Secret"}) - } - if(scope==="") - { - form.setError("scope",{"message":"Please Enter the scope"}) - } - break; - } - if(prop.performUpdate) - { - updateCS({ - id_cs:prop.data?.id_cs, - updateToggle: false, - status:prop.data?.status, - attributes:["client_id","client_secret","scope"], - values:[client_id,client_secret,scope] - }) - posthog?.capture("Connection_strategy_OAuth2_updated", { - id_project: idProject, - mode: config.DISTRIBUTION - }); - } - else - { - createCS({ - type: providerToType(provider_name.split("-")[0],provider_name.split("-")[1],AuthStrategy.oauth2), - attributes:["client_id","client_secret","scope"], - values:[client_id,client_secret,scope] - }); - posthog?.capture("Connection_strategy_OAuth2_created", { - id_project: idProject, - mode: config.DISTRIBUTION - }); - } - - form.reset(); - console.log(values) - if(prop.closeDialog!=undefined) - { - prop.closeDialog() - } - break; - - case AuthStrategy.api_key: - if(values.api_key==="") - { - form.setError("api_key",{"message":"Please Enter API Key"}); - break; - } - if(prop.performUpdate) - { - updateCS({ - id_cs:prop.data?.id_cs, - updateToggle: false, - status:prop.data?.status, - attributes:["api_key"], - values:[api_key] - }) - posthog?.capture("Connection_strategy_API_KEY_updated", { - id_project: idProject, - mode: config.DISTRIBUTION - }); - } - else - { - createCS({ - type: providerToType(provider_name.split("-")[0],provider_name.split("-")[1],AuthStrategy.api_key), - attributes:["api_key"], - values:[api_key] - }); - posthog?.capture("Connection_strategy_API_KEY_created", { - id_project: idProject, - mode: config.DISTRIBUTION - }); - } - - form.reset(); - console.log(values) - if(prop.closeDialog!=undefined) - { - prop.closeDialog() - } - break; - - case AuthStrategy.basic: - if(values.username==="" || values.secret==="") - { - if(values.username==="") - { - form.setError("username",{"message":"Please Enter Username"}) - } - if(values.secret==="") - { - form.setError("secret",{"message":"Please Enter Secret"}) - } - break; - - } - if(prop.performUpdate) - { - updateCS({ - id_cs:prop.data?.id_cs, - updateToggle: false, - status:prop.data?.status, - attributes:["username","secret"], - values:[username,secret] - }) - posthog?.capture("Connection_strategy_BASIC_AUTH_updated", { - id_project: idProject, - mode: config.DISTRIBUTION - }); - } - else - { - createCS({ - type: providerToType(provider_name.split("-")[0],provider_name.split("-")[1],AuthStrategy.basic), - attributes:["username","secret"], - values:[username,secret] - }); - posthog?.capture("Connection_strategy_BASIC_AUTH_created", { - id_project: idProject, - mode: config.DISTRIBUTION - }); - } - - form.reset(); - console.log(values) - if(prop.closeDialog!=undefined) - { - prop.closeDialog() - } - break; - } - - - } - - - - - return ( - <> -
- - - - Add OAuth Credentials - - In the event that you are using your own OAuth credentials, Panora gives you have the option to import them instead of using our pre-made OAuth apps. - - - -
- ( - - Provider - - - - - - - - - - No Provider found. - - - - {ALL_PROVIDERS.map((provider) => ( - { - form.setValue("provider_name", `${provider.value}-${provider.vertical}`) - form.clearErrors("provider_name") - handlePopOverClose(); - }} - className={field.value===`${provider.value}-${provider.vertical}` ? "bg-gray-200 w-full" : "w-full"} - - > -
handleWalletClick(provider.name)} - > -
- {provider.value} - {provider.value.charAt(0).toUpperCase() + provider.value.slice(1)} - {provider.vertical} - -
- {/* */} - - -
- -
- ))} -
-
-
-
-
- -
- )} - /> - - {/*
*/} - -
- ( - - Authentication Method - - - - - - )} - /> - -
- - {/* If Authentication Method is OAuth2 */} - - {Watch.auth_type===AuthStrategy.oauth2 ? - <> -
- ( - - Client ID - - - - - - )} - /> -
-
- ( - - Client Secret - - - - - - )} - /> -
-
- ( - - Scope - - - - - - )} - /> -
-
- Redirect URI -
- {/*

localhost:3000/connections/oauth/callback

*/} - - - - - - - -
- -
- - : - <>} - - {Watch.auth_type===AuthStrategy.api_key ? - <> -
- ( - - API Key - - - - - - )} - /> -
- - : - <>} - - {Watch.auth_type===AuthStrategy.basic ? - <> -
- ( - - Username - - - - - - )} - /> -
-
- ( - - Secret - - - - - - )} - /> -
- - : - <>} -
- - - -
- - - ) -} - -export default AddAuthCredentialsForm \ No newline at end of file diff --git a/apps/client-ts/src/components/Configuration/AuthCredentialsTable.tsx b/apps/client-ts/src/components/Configuration/AuthCredentialsTable.tsx deleted file mode 100644 index 248814990..000000000 --- a/apps/client-ts/src/components/Configuration/AuthCredentialsTable.tsx +++ /dev/null @@ -1,41 +0,0 @@ -import { - Card, - CardContent, - CardHeader, - CardTitle, - } from "@/components/ui/card" -import { DataTable } from "@/components/shared/data-table"; -import { authColumns } from "./authColumns"; -import {AuthStrategy} from '@panora/shared' -import { DataTableLoading } from "@/components/shared/data-table-loading"; -import { Suspense } from "react"; - -export interface authCredentialsMapping { - id_cs : string, - provider_name : string, - auth_type: AuthStrategy, - vertical: string, - type: string, - status: boolean, -} - -export default function AuthCredentialsTable({ - mappings, - isLoading -}: { mappings: authCredentialsMapping[] | undefined; isLoading: boolean }) { - - // const countDefined = mappings?.filter(mapping => mapping.status === "defined").length; - // const countMapped = mappings?.filter(mapping => mapping.status === "mapped").length; - if(isLoading){ - return ; - } - return ( - <> -
- - {mappings && } - -
- - ) -} \ No newline at end of file diff --git a/apps/client-ts/src/components/Configuration/Connector/ConnectorDisplay.tsx b/apps/client-ts/src/components/Configuration/Connector/ConnectorDisplay.tsx index dad3dbce7..440497963 100644 --- a/apps/client-ts/src/components/Configuration/Connector/ConnectorDisplay.tsx +++ b/apps/client-ts/src/components/Configuration/Connector/ConnectorDisplay.tsx @@ -11,41 +11,18 @@ import config from "@/lib/config" import { AuthStrategy, providerToType, Provider, extractProvider, extractVertical } from "@panora/shared" import { useEffect, useState } from "react" import useProjectStore from "@/state/projectStore" -import useConnectionStrategyMutation from "@/hooks/mutations/useConnectionStrategy" -import useUpdateConnectionStrategyMutation from "@/hooks/mutations/useUpdateConnectionStrategy" -import useConnectionStrategyAuthCredentialsMutation from "@/hooks/mutations/useConnectionStrategyAuthCredentials" import { usePostHog } from 'posthog-js/react' import { Input } from "@/components/ui/input" -import useConnectionStrategies from "@/hooks/useConnectionStrategies" +import useConnectionStrategies from "@/hooks/get/useConnectionStrategies" import { DataTableFacetedFilter } from "@/components/shared/data-table-faceted-filter" +import useCreateConnectionStrategy from "@/hooks/create/useCreateConnectionStrategy" +import useUpdateConnectionStrategy from "@/hooks/update/useUpdateConnectionStrategy" +import useConnectionStrategyAuthCredentials from "@/hooks/get/useConnectionStrategyAuthCredentials" interface ItemDisplayProps { item?: Provider } -export const statuses = [ - { - value: "backlog", - label: "Backlog", - }, - { - value: "todo", - label: "Todo", - }, - { - value: "in progress", - label: "In Progress", - }, - { - value: "done", - label: "Done", - }, - { - value: "canceled", - label: "Canceled", - }, -] - const formSchema = z.object({ client_id : z.string({ required_error: "Please Enter a Client ID", @@ -72,9 +49,10 @@ export function ConnectorDisplay({ item }: ItemDisplayProps) { const [switchEnabled, setSwitchEnabled] = useState(false); const { idProject } = useProjectStore() const { data: connectionStrategies, isLoading: isConnectionStrategiesLoading, error: isConnectionStategiesError } = useConnectionStrategies() - const { mutate: createCS } = useConnectionStrategyMutation(); - const { mutate: updateCS } = useUpdateConnectionStrategyMutation() - const { mutateAsync: fetchCredentials, data: fetchedData } = useConnectionStrategyAuthCredentialsMutation(); + const { mutate: createCS } = useCreateConnectionStrategy(); + const { mutate: updateCS } = useUpdateConnectionStrategy() + const { mutateAsync: fetchCredentials, data: fetchedData } = useConnectionStrategyAuthCredentials(); + const posthog = usePostHog() const mappingConnectionStrategies = connectionStrategies?.filter((cs) => extractVertical(cs.type).toLowerCase() == item?.vertical && extractProvider(cs.type).toLowerCase() == item?.name) @@ -92,7 +70,7 @@ export function ConnectorDisplay({ item }: ItemDisplayProps) { const handleCopy = async () => { try { - await navigator.clipboard.writeText("localhost:3000/connections/oauth/callback") + await navigator.clipboard.writeText(`${config.API_URL}/connections/oauth/callback`) setCopied(true); setTimeout(() => setCopied(false), 2000); // Reset copied state after 2 seconds } catch (err) { @@ -341,7 +319,7 @@ export function ConnectorDisplay({ item }: ItemDisplayProps) {
Redirect URI
- +
} - +
diff --git a/apps/client-ts/src/components/Configuration/CustomConnectorPage.tsx b/apps/client-ts/src/components/Configuration/Connector/CustomConnectorPage.tsx similarity index 94% rename from apps/client-ts/src/components/Configuration/CustomConnectorPage.tsx rename to apps/client-ts/src/components/Configuration/Connector/CustomConnectorPage.tsx index 32c6c1728..74f81e840 100644 --- a/apps/client-ts/src/components/Configuration/CustomConnectorPage.tsx +++ b/apps/client-ts/src/components/Configuration/Connector/CustomConnectorPage.tsx @@ -1,6 +1,6 @@ import * as React from "react" import useVerticalStore from "@/state/verticalStore"; -import { ConnectorLayout } from "./Connector/ConnectorLayout" +import { ConnectorLayout } from "./ConnectorLayout" import { providersArray, Provider } from "@panora/shared" export default function CustomConnectorPage() { diff --git a/apps/client-ts/src/components/Configuration/FieldMappingModal.tsx b/apps/client-ts/src/components/Configuration/FieldMappings/FieldMappingModal.tsx similarity index 97% rename from apps/client-ts/src/components/Configuration/FieldMappingModal.tsx rename to apps/client-ts/src/components/Configuration/FieldMappings/FieldMappingModal.tsx index bdbfca3ad..661a6aa3e 100644 --- a/apps/client-ts/src/components/Configuration/FieldMappingModal.tsx +++ b/apps/client-ts/src/components/Configuration/FieldMappings/FieldMappingModal.tsx @@ -34,20 +34,20 @@ import { SelectTrigger, SelectValue, } from "@/components/ui/select" -import useDefineFieldMutation from "@/hooks/mutations/useDefineFieldMutation" -import useMapFieldMutation from "@/hooks/mutations/useMapFieldMutation" +import useMapField from "@/hooks/create/useMapField" import { useEffect, useState } from "react" -import useFieldMappings from "@/hooks/useFieldMappings" -import useProviderProperties from "@/hooks/useProviderProperties" +import useFieldMappings from "@/hooks/get/useFieldMappings" +import useProviderProperties from "@/hooks/get/useProviderProperties" import { standardObjects } from "@panora/shared/src/standardObjects" import useProjectStore from "@/state/projectStore" -import useLinkedUsers from "@/hooks/useLinkedUsers" +import useLinkedUsers from "@/hooks/get/useLinkedUsers" import { zodResolver } from "@hookform/resolvers/zod" import { useForm } from "react-hook-form" import * as z from "zod" import { usePostHog } from 'posthog-js/react' import config from "@/lib/config" import { CRM_PROVIDERS } from "@panora/shared" +import useDefineField from "@/hooks/create/useDefineField" const defineFormSchema = z.object({ @@ -108,8 +108,8 @@ export function FModal({ onClose }: {onClose: () => void}) { const {idProject} = useProjectStore(); const { data: mappings } = useFieldMappings(); - const { mutate: mutateDefineField } = useDefineFieldMutation(); - const { mutate: mutateMapField } = useMapFieldMutation(); + const { mutate: mutateDefineField } = useDefineField(); + const { mutate: mutateMapField } = useMapField(); const { data: linkedUsers } = useLinkedUsers(); // TODO: HANDLE VERTICAL AND PROVIDERS FOR CUSTOM MAPPINGS const { data: sourceCustomFields, error, isLoading } = useProviderProperties(linkedUserId,sourceProvider, "crm"); diff --git a/apps/client-ts/src/components/Configuration/FieldMappingsTable.tsx b/apps/client-ts/src/components/Configuration/FieldMappings/FieldMappingsTable.tsx similarity index 100% rename from apps/client-ts/src/components/Configuration/FieldMappingsTable.tsx rename to apps/client-ts/src/components/Configuration/FieldMappings/FieldMappingsTable.tsx diff --git a/apps/client-ts/src/components/Configuration/columns.tsx b/apps/client-ts/src/components/Configuration/FieldMappings/columns.tsx similarity index 95% rename from apps/client-ts/src/components/Configuration/columns.tsx rename to apps/client-ts/src/components/Configuration/FieldMappings/columns.tsx index 0034a183f..a53ee5b9a 100644 --- a/apps/client-ts/src/components/Configuration/columns.tsx +++ b/apps/client-ts/src/components/Configuration/FieldMappings/columns.tsx @@ -5,9 +5,9 @@ import { ColumnDef } from "@tanstack/react-table" import { Badge } from "@/components/ui/badge" import { Checkbox } from "@/components/ui/checkbox" -import { DataTableColumnHeader } from "../shared/data-table-column-header" -import { DataTableRowActions } from "../shared/data-table-row-actions" -import { Mapping } from "./data/schema" +import { DataTableColumnHeader } from "../../shared/data-table-column-header" +import { DataTableRowActions } from "../../shared/data-table-row-actions" +import { Mapping } from "./schema" export const columns: ColumnDef[] = [ { diff --git a/apps/client-ts/src/components/Configuration/data/schema.ts b/apps/client-ts/src/components/Configuration/FieldMappings/schema.ts similarity index 61% rename from apps/client-ts/src/components/Configuration/data/schema.ts rename to apps/client-ts/src/components/Configuration/FieldMappings/schema.ts index ff760c476..c8baec250 100644 --- a/apps/client-ts/src/components/Configuration/data/schema.ts +++ b/apps/client-ts/src/components/Configuration/FieldMappings/schema.ts @@ -1,7 +1,5 @@ import { z } from "zod" -// We're keeping a simple non-relational schema here. -// IRL, you will have a schema for your data models. export const mappingSchema = z.object({ standard_object: z.string(), source_app: z.string(), @@ -12,4 +10,4 @@ export const mappingSchema = z.object({ data_type: z.string() }) -export type Mapping = z.infer \ No newline at end of file +export type Mapping = z.infer diff --git a/apps/client-ts/src/components/Configuration/AddLinkedAccount.tsx b/apps/client-ts/src/components/Configuration/LinkedUsers/AddLinkedAccount.tsx similarity index 91% rename from apps/client-ts/src/components/Configuration/AddLinkedAccount.tsx rename to apps/client-ts/src/components/Configuration/LinkedUsers/AddLinkedAccount.tsx index c3c510fee..e2772bb28 100644 --- a/apps/client-ts/src/components/Configuration/AddLinkedAccount.tsx +++ b/apps/client-ts/src/components/Configuration/LinkedUsers/AddLinkedAccount.tsx @@ -35,7 +35,7 @@ import { import { PlusCircledIcon } from "@radix-ui/react-icons" import { cn } from "@/lib/utils" import { useState } from "react" -import useLinkedUserMutation from "@/hooks/mutations/useLinkedUserMutation" +import useCreateLinkedUser from "@/hooks/create/useCreateLinkedUser" import useOrganisationStore from "@/state/organisationStore" import useProjectStore from "@/state/projectStore" import { zodResolver } from "@hookform/resolvers/zod" @@ -43,6 +43,7 @@ import { useForm } from "react-hook-form" import * as z from "zod" import { usePostHog } from 'posthog-js/react' import config from "@/lib/config" +import { PlusCircle } from "lucide-react" interface LinkedUserModalObj { open: boolean; @@ -61,7 +62,7 @@ const AddLinkedAccount = () => { import: false }) - const { mutate } = useLinkedUserMutation(); + const { mutate } = useCreateLinkedUser(); const handleOpenChange = (open: boolean) => { setShowNewLinkedUserDialog(prevState => ({ ...prevState, open })); @@ -70,16 +71,13 @@ const AddLinkedAccount = () => { const posthog = usePostHog() - const {idOrg} = useOrganisationStore(); const {idProject} = useProjectStore(); - const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { linkedUserIdentifier: "", }, - }) function onSubmit(values: z.infer) { @@ -103,16 +101,15 @@ const AddLinkedAccount = () => { - + @@ -134,6 +131,7 @@ const AddLinkedAccount = () => { >

Add New Linked User

+ @@ -205,10 +203,10 @@ const AddLinkedAccount = () => { - - + diff --git a/apps/client-ts/src/components/Configuration/LinkedUsers/LinkedUsersPage.tsx b/apps/client-ts/src/components/Configuration/LinkedUsers/LinkedUsersPage.tsx new file mode 100644 index 000000000..7b70e6390 --- /dev/null +++ b/apps/client-ts/src/components/Configuration/LinkedUsers/LinkedUsersPage.tsx @@ -0,0 +1,20 @@ +import { DataTable } from "../../shared/data-table"; +import { columns } from "./columns"; + + +export function LinkedUsersPage({ + linkedUsers, + isLoading +}: { linkedUsers: Record[] | undefined; isLoading: boolean }) { + + const lusers = linkedUsers?.map(lu => ({ + linked_user_id: lu.id_linked_user, + remote_user_id: lu.linked_user_origin_id, + })) + + return ( + <> + {linkedUsers && } + + ) +} \ No newline at end of file diff --git a/apps/client-ts/src/components/Configuration/LinkedUsers/columns.tsx b/apps/client-ts/src/components/Configuration/LinkedUsers/columns.tsx new file mode 100644 index 000000000..4af3a2ec7 --- /dev/null +++ b/apps/client-ts/src/components/Configuration/LinkedUsers/columns.tsx @@ -0,0 +1,63 @@ +import { ColumnDef } from "@tanstack/react-table"; +import { ColumnLU } from "./schema"; +import { DataTableColumnHeader } from "@/components/shared/data-table-column-header"; +import { Badge } from "@/components/ui/badge"; +import { Checkbox } from "@/components/ui/checkbox"; + +export const columns: ColumnDef[] = [ + { + id: "select", + header: ({ table }) => ( + table.toggleAllPageRowsSelected(!!value)} + aria-label="Select all" + className="translate-y-[2px]" + /> + ), + cell: ({ row }) => ( + row.toggleSelected(!!value)} + aria-label="Select row" + className="translate-y-[2px]" + /> + ), + enableSorting: false, + enableHiding: false, + }, + { + accessorKey: "linked_user_id", + header: ({ column }) => ( + + ), + cell: ({ row }) =>{ + return ( +
+ {row.getValue("linked_user_id")} +
+ ) + }, + enableSorting: false, + enableHiding: false, + }, + { + accessorKey: "remote_user_id", + header: ({ column }) => ( + + ), + cell: ({ row }) => { + return ( +
+ {row.getValue("remote_user_id")} +
+ ) + }, + enableSorting: false, + enableHiding: false, + }, + + ] \ No newline at end of file diff --git a/apps/client-ts/src/components/Configuration/LinkedUsers/schema.ts b/apps/client-ts/src/components/Configuration/LinkedUsers/schema.ts new file mode 100644 index 000000000..71eb68289 --- /dev/null +++ b/apps/client-ts/src/components/Configuration/LinkedUsers/schema.ts @@ -0,0 +1,7 @@ +import { z } from "zod" + +export const linkedUsersSchema = z.object({ + linked_user_id: z.string(), + remote_user_id: z.string(), +}) +export type ColumnLU = z.infer \ No newline at end of file diff --git a/apps/client-ts/src/components/Configuration/LinkedUsersPage.tsx b/apps/client-ts/src/components/Configuration/LinkedUsersPage.tsx deleted file mode 100644 index ea7b11fa0..000000000 --- a/apps/client-ts/src/components/Configuration/LinkedUsersPage.tsx +++ /dev/null @@ -1,42 +0,0 @@ -/* eslint-disable react/jsx-key */ -import { - Avatar, - AvatarFallback, - AvatarImage, - } from "@/components/ui/avatar" -import { Badge } from "@/components/ui/badge" -import { Skeleton } from "@/components/ui/skeleton"; - -export function LinkedUsersPage({ - linkedUsers, - isLoading -}: { linkedUsers: Record[] | undefined; isLoading: boolean }) { - - return ( -
- {linkedUsers && linkedUsers.map((linkedUser)=>{ - return ( -
- - - OM - -
-

- {isLoading ? : linkedUser.id_linked_user} -

-

- {isLoading ? : linkedUser.alias} -

-
-
- {isLoading ? : linkedUser.linked_user_origin_id} -
- -
- ) - })} - -
- ) -} \ No newline at end of file diff --git a/apps/client-ts/src/components/Configuration/AddWebhook.tsx b/apps/client-ts/src/components/Configuration/Webhooks/AddWebhook.tsx similarity index 91% rename from apps/client-ts/src/components/Configuration/AddWebhook.tsx rename to apps/client-ts/src/components/Configuration/Webhooks/AddWebhook.tsx index babdbcc67..4b4cbc9ff 100644 --- a/apps/client-ts/src/components/Configuration/AddWebhook.tsx +++ b/apps/client-ts/src/components/Configuration/Webhooks/AddWebhook.tsx @@ -10,7 +10,6 @@ import { Input } from "@/components/ui/input" import { PlusCircledIcon } from "@radix-ui/react-icons" import { useState } from "react" import useProjectStore from "@/state/projectStore" -import useWebhookMutation from "@/hooks/mutations/useWebhookMutation" import { CardContent, CardDescription, @@ -33,7 +32,8 @@ import { useForm } from "react-hook-form" import * as z from "zod" import { usePostHog } from 'posthog-js/react' import config from "@/lib/config" -import { DataTableFacetedFilterWebhook } from "../shared/data-table-webhook-scopes" +import { DataTableFacetedFilterWebhook } from "../../shared/data-table-webhook-scopes" +import useCreateWebhook from "@/hooks/create/useCreateWebhook" const formSchema = z.object({ @@ -53,7 +53,7 @@ const AddWebhook = () => { const {idProject} = useProjectStore(); - const { mutate } = useWebhookMutation(); + const { mutate } = useCreateWebhook(); const form = useForm>({ resolver: zodResolver(formSchema), @@ -89,25 +89,24 @@ const AddWebhook = () => { return ( -
- Create a webhook @@ -115,7 +114,7 @@ const AddWebhook = () => { Set up your webhook endpoint to receive live events from Panora. - +
{ />
- - + + diff --git a/apps/client-ts/src/components/Configuration/Webhooks/WebhooksPage.tsx b/apps/client-ts/src/components/Configuration/Webhooks/WebhooksPage.tsx new file mode 100644 index 000000000..38f1f766f --- /dev/null +++ b/apps/client-ts/src/components/Configuration/Webhooks/WebhooksPage.tsx @@ -0,0 +1,43 @@ +/* eslint-disable react/jsx-key */ +'use client' + +import { DataTable } from "@/components/shared/data-table"; +import { DataTableLoading } from "@/components/shared/data-table-loading"; +import { useEffect, useState } from "react"; +import { useColumns } from "./columns"; + +interface Webhook { + scope: string; + url: string; + endpoint_description: string; + secret: string; + id_webhook_endpoint: string; + active: boolean; +} +export function WebhooksPage({ + webhooks: initialWebhooks, + isLoading +}: { webhooks: Webhook[] | undefined; isLoading: boolean }) { + const [webhooks, setWebhooks] = useState(initialWebhooks); + + const columns = useColumns(webhooks, setWebhooks); + + useEffect(() => { + const whs = initialWebhooks?.map((wh) => ({ + scope: wh.scope, + url: wh.url, + endpoint_description: wh.endpoint_description, + secret: wh.secret, + id_webhook_endpoint: wh.id_webhook_endpoint, + active: wh.active + })); + setWebhooks(whs) + }, [initialWebhooks]); + + return ( +
+ {isLoading && } + {webhooks && } +
+ ) +} \ No newline at end of file diff --git a/apps/client-ts/src/components/Configuration/Webhooks/columns.tsx b/apps/client-ts/src/components/Configuration/Webhooks/columns.tsx new file mode 100644 index 000000000..633c6b610 --- /dev/null +++ b/apps/client-ts/src/components/Configuration/Webhooks/columns.tsx @@ -0,0 +1,189 @@ +/* eslint-disable react/jsx-key */ +'use client' + +import { ColumnDef } from "@tanstack/react-table" +import { Badge } from "@/components/ui/badge" +import { Webhook } from "./schema" +import { PasswordInput } from "@/components/ui/password-input" +import { useState } from "react" +import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip" +import { Button } from "@/components/ui/button" +import { DataTableColumnHeader } from "@/components/shared/data-table-column-header" +import { DataTableRowActions } from "@/components/shared/data-table-row-actions" +import { Switch } from "@/components/ui/switch" +import useUpdateWebhookStatus from "@/hooks/update/useUpdateWebhookStatus" +import { Input } from "@/components/ui/input" +import { Archive } from "lucide-react" + +interface WebhookType { + scope: string; + url: string; + endpoint_description: string; + secret: string; + id_webhook_endpoint: string; + active: boolean; +} + +export function useColumns(webhooks: WebhookType[] | undefined, setWebhooks: React.Dispatch>) { + const [copiedState, setCopiedState] = useState<{ [key: string]: boolean }>({}); + const { mutate } = useUpdateWebhookStatus(); + + const disableWebhook = (webhook_id: string, status: boolean) => { + mutate({ + id: webhook_id, + active: status, + }, { + onSuccess: () => { + const index = webhooks!.findIndex(webhook => webhook.id_webhook_endpoint === webhook_id); + if (index !== -1) { + const updatedWebhooks = [...webhooks!]; + updatedWebhooks[index].active = status; + setWebhooks(updatedWebhooks); + } + } + }); + } + + const handleCopy = (token: string) => { + navigator.clipboard.writeText(token); + setCopiedState((prevState) => ({ + ...prevState, + [token]: true, + })); + setTimeout(() => { + setCopiedState((prevState) => ({ + ...prevState, + [token]: false, + })); + }, 2000); // Reset copied state after 2 seconds + }; + + return [ + { + accessorKey: "url", + header: ({ column }) => ( + + ), + cell: ({ row }) => + + {row.getValue("url")} + , + enableSorting: false, + enableHiding: false, + }, + { + accessorKey: "secret", + header: ({ column }) => ( + + ), + cell: ({ row }) => { + const token: string = row.getValue("secret"); + const copied = copiedState[token] || false; + + return ( +
+
+ +
+
handleCopy(token)} + > + + + + + + +

Copy Secret

+
+
+
+
+
+ ); + }, + enableSorting: false, + enableHiding: false, + }, + { + accessorKey: "endpoint_description", + header: ({ column }) => ( + + ), + cell: ({ row }) => + + {row.getValue("endpoint_description")} + , + filterFn: (row, id, value) => { + return value.includes(row.getValue(id)) + }, + enableSorting: false, + enableHiding: false, + }, + { + accessorKey: "scope", + header: ({ column }) => ( + + ), + cell: ({ row }) =>
+ {(row.getValue("scope") as string[]).map((scope) => { + return ( + {scope} + ) + })} +
, + filterFn: (row, id, value) => { + return value.includes(row.getValue(id)) + }, + enableSorting: false, + enableHiding: false, + }, + { + accessorKey: "active", + header: ({ column }) => ( + + ), + cell: ({ row }) =>
+ disableWebhook(row.original.id_webhook_endpoint, !row.getValue('active')) } + /> +
, + filterFn: (row, id, value) => { + return value.includes(row.getValue(id)) + }, + enableSorting: false, + enableHiding: false, + }, + { + id: "actions", + cell: ({ row }) => , + }, + ] as ColumnDef[]; +} diff --git a/apps/client-ts/src/components/Configuration/Webhooks/schema.ts b/apps/client-ts/src/components/Configuration/Webhooks/schema.ts new file mode 100644 index 000000000..af05e863a --- /dev/null +++ b/apps/client-ts/src/components/Configuration/Webhooks/schema.ts @@ -0,0 +1,12 @@ +import { z } from "zod" + +export const webhookSchema = z.object({ + scope: z.string(), + url: z.string(), + endpoint_description: z.string(), + secret: z.string(), + id_webhook_endpoint: z.string(), + active: z.boolean() +}) + +export type Webhook = z.infer \ No newline at end of file diff --git a/apps/client-ts/src/components/Configuration/WebhooksPage.tsx b/apps/client-ts/src/components/Configuration/WebhooksPage.tsx deleted file mode 100644 index bad8d382f..000000000 --- a/apps/client-ts/src/components/Configuration/WebhooksPage.tsx +++ /dev/null @@ -1,94 +0,0 @@ -/* eslint-disable react/jsx-key */ -'use client' - -import { Badge } from "@/components/ui/badge" -import { Skeleton } from "@/components/ui/skeleton"; -import { Switch } from "@/components/ui/switch"; -import useWebhookStatusMutation from "@/hooks/mutations/useWebhookUpdate"; -import { useEffect, useState } from "react"; - -export function WebhooksPage({ - webhooks: initialWebhooks, - isLoading -}: { webhooks: Record[] | undefined; isLoading: boolean }) { - const [webhooks, setWebhooks] = useState(initialWebhooks); - const [showSecret, setShowSecret] = useState>({}); - - const {mutate} = useWebhookStatusMutation(); - const disableWebhook = (webhook_id: string, status: boolean) => { - mutate({ - id: webhook_id, - active: status, - }, { - onSuccess: () => { - // Find the index of the webhook to update - const index = webhooks!.findIndex(webhook => webhook.id_webhook_endpoint === webhook_id); - if (index !== -1) { - // Create a new array with all previous webhooks - const updatedWebhooks = [...webhooks!]; - // Update the specific webhook's active status - updatedWebhooks[index].active = status; - // Set the updated webhooks array to state - setWebhooks(updatedWebhooks); - } - } - }); - } - - useEffect(() => { - setWebhooks(initialWebhooks); - }, [initialWebhooks]); - - return ( -
- {webhooks && webhooks.map((webhook)=>{ - return ( -
- -
-

- {(webhook.scope as string[]).map((scope)=> { - return ({isLoading ? : scope}) - })} -

-

- {isLoading ? : webhook.url} -

-

- {isLoading ? : - webhook.endpoint_description - } -

-

setShowSecret({...showSecret, [webhook.id_webhook_endpoint]: true})}> - - {isLoading ? : - showSecret[webhook.id_webhook_endpoint] ? -

navigator.clipboard.writeText(webhook.secret)}> - -

{webhook.secret}

-
: - <> - -

Reveal Key

- - } - -

-
-
- {isLoading ? : - disableWebhook(webhook.id_webhook_endpoint, !webhook.active)} - /> - } -
-
- ) - })} - -
- ) -} \ No newline at end of file diff --git a/apps/client-ts/src/components/Configuration/authColumns.tsx b/apps/client-ts/src/components/Configuration/authColumns.tsx deleted file mode 100644 index 7d3a96164..000000000 --- a/apps/client-ts/src/components/Configuration/authColumns.tsx +++ /dev/null @@ -1,180 +0,0 @@ -"use client" - -import { ColumnDef } from "@tanstack/react-table" -import Link from 'next/link'; -import { Badge,badgeVariants } from "@/components/ui/badge" -import { Checkbox } from "@/components/ui/checkbox" -import {Pencil2Icon} from '@radix-ui/react-icons' -import { DataTableColumnHeader } from "../shared/data-table-column-header" -import { DataTableRowActions } from "../shared/data-table-row-actions" -import { Mapping } from "./data/authCredentialsSchema" -import { Button } from "@/components/ui/button" -import {Switch} from '@/components/ui/switch' -import { useState } from "react"; -import { - Dialog, - DialogContent, - DialogTrigger, -} from "@/components/ui/dialog" -import { - DropdownMenu, - DropdownMenuCheckboxItem, - DropdownMenuContent, - DropdownMenuItem, - DropdownMenuLabel, - DropdownMenuSeparator, - DropdownMenuTrigger, -} from "@/components/ui/dropdown-menu" -import { - DotsHorizontalIcon, -} from "@radix-ui/react-icons" -import AddAuthCredentialsForm from "./AddAuthCredentialsForm"; -import {getLogoURL,AuthStrategy} from '@panora/shared' -import useUpdateConnectionStrategyMutation from "@/hooks/mutations/useUpdateConnectionStrategy"; -import useDeleteConnectionStrategyMutation from "@/hooks/mutations/useDeleteConnectionStrategy"; - -const UpdateStatusCellComponent = ({row}:{row:any}) => { - const [isDisable,setDisable] = useState(false) - const {mutate} = useUpdateConnectionStrategyMutation() - const onSwitchChange = () => { - setDisable(true) - mutate( - { - id_cs:row.original.id_cs, - updateToggle:true - }, { - onSuccess : () => setDisable(false), - onError : () => setDisable(false) - }) - // console.log("Changed switch") - } - - return ( -
- {/* {row.getValue("activate")==false ? "Deactivated" : "Activated"} */} - onSwitchChange()} disabled={isDisable} value={row.getValue("status")} defaultChecked={row.getValue("status")}/> -
- ) -} - -const ActionCellComponent = ({row}:{row:any}) => { - - const [open,setOpen] = useState(false) - - const handleOpenChange = (open: boolean) => { - setOpen(open) - // form.reset() - }; - - const {mutate} = useDeleteConnectionStrategyMutation() - - const deleteConnectionStrategy = () => { - mutate( - { - id_cs:row.original.id_cs - } - ) - } - - return ( - - - - - - - - Edit - - - deleteConnectionStrategy()}>Delete - - - - - setOpen(false)} performUpdate={true} /> - - - - ) - -} - -export const authColumns: ColumnDef[] = [ - { - // acc: 'provider_name', - // accessorFn: row => `${row.provider_name} ${row.logoPath}`, - accessorKey:'provider_name', - // accessorKey: 'mergeD', - header: ({ column }) => ( - - ), - cell: ({ row }) =>{ - - - return ( -
- - {row.original.provider_name}/ - {row.original.provider_name} - -
- ) - }, - - }, - { - accessorKey: "auth_type", - header: ({ column }) => ( - - ), - cell: ({ row }) => { - - const Auth_Type = AuthStrategy.oauth2===row.getValue("auth_type") ? "OAuth2" : AuthStrategy.api_key===row.getValue("auth_type") ? "API Key" : "Basic Auth" - - return ( -
- {Auth_Type} -
- ) - }, - }, - { - accessorKey: "vertical", - header: ({ column }) => ( - - ), - cell: ({ row }) => { - - - return ( -
- {row.getValue("vertical")} -
- ) - }, - }, - { - accessorKey: "status", - header: ({ column }) => ( - - ), - cell: UpdateStatusCellComponent - }, - - - - { - accessorKey: "action", - header: ({ column }) => ( - - ), - cell: ActionCellComponent - - }, - -] - diff --git a/apps/client-ts/src/components/Configuration/data/authCredentialsSchema.ts b/apps/client-ts/src/components/Configuration/data/authCredentialsSchema.ts deleted file mode 100644 index 489bb1045..000000000 --- a/apps/client-ts/src/components/Configuration/data/authCredentialsSchema.ts +++ /dev/null @@ -1,29 +0,0 @@ -import { AuthStrategy } from "@panora/shared" -import { z } from "zod" - -// We're keeping a simple non-relational schema here. -// IRL, you will have a schema for your data models. -export const mappingSchema = z.object({ - provider_name: z.string(), - auth_type: z.string(), - status: z.boolean(), - id_cs: z.string(), - vertical: z.string(), - type: z.string() - // activate: z.boolean(), - // credentials: z.object({ - // clientID: z.string().optional(), - // clientSecret: z.string().optional(), - // scope: z.string().optional(), - // apiKey: z.string().optional(), - // username: z.string().optional(), - // secret: z.string().optional() - - // }), - // action: z.string(), - // logoPath: z.string(), - // // destination_field: z.string(), - // // data_type: z.string() -}) - -export type Mapping = z.infer \ No newline at end of file diff --git a/apps/client-ts/src/components/Configuration/data/data.tsx b/apps/client-ts/src/components/Configuration/data/data.tsx deleted file mode 100644 index 670860193..000000000 --- a/apps/client-ts/src/components/Configuration/data/data.tsx +++ /dev/null @@ -1,86 +0,0 @@ -import { - ArrowDownIcon, - ArrowRightIcon, - ArrowUpIcon, - CheckCircledIcon, - CircleIcon, - CrossCircledIcon, - QuestionMarkCircledIcon, - StopwatchIcon, - } from "@radix-ui/react-icons" - - export const labels = [ - { - value: "/crm/tasks", - label: "/crm/tasks", - }, - { - value: "/crm/notess", - label: "/crm/notess", - }, - { - value: "/crm/contacts", - label: "/crm/contacts", - }, - ] - - export const labels2 = [ - { - value: "GET", - label: "GET", - }, - { - value: "POST", - label: "POST", - }, - { - value: "GET", - label: "GET", - }, - ] - - export const statuses = [ - { - value: "backlog", - label: "Backlog", - icon: QuestionMarkCircledIcon, - }, - { - value: "todo", - label: "Todo", - icon: CircleIcon, - }, - { - value: "in progress", - label: "In Progress", - icon: StopwatchIcon, - }, - { - value: "done", - label: "Done", - icon: CheckCircledIcon, - }, - { - value: "canceled", - label: "Canceled", - icon: CrossCircledIcon, - }, - ] - - export const priorities = [ - { - label: "Low", - value: "low", - icon: ArrowDownIcon, - }, - { - label: "Medium", - value: "medium", - icon: ArrowRightIcon, - }, - { - label: "High", - value: "high", - icon: ArrowUpIcon, - }, - ] \ No newline at end of file diff --git a/apps/client-ts/src/components/Configuration/data/mappings.ts b/apps/client-ts/src/components/Configuration/data/mappings.ts deleted file mode 100644 index eba75bb9c..000000000 --- a/apps/client-ts/src/components/Configuration/data/mappings.ts +++ /dev/null @@ -1,62 +0,0 @@ -export const MAPPINGS = [ - { - "standard_object": "Contact", - "source_app": "Hubspot", - "status": "defined", - "category": "CRM", - "source_field": "favorite_color", - "destination_field": "", - "data_type": "string", - "date": "Jul 31 2019" - }, - { - "standard_object": "Contact", - "source_app": "Zoho", - "status": "defined", - "category": "CRM", - "source_field": "favorite_team", - "destination_field": "fav_team", - "data_type": "string", - "date": "Jul 31 2019" - }, - { - "standard_object": "Company", - "source_app": "Hubspot", - "status": "defined", - "category": "CRM", - "source_field": "favorite_color", - "destination_field": "fav_color", - "data_type": "string", - "date": "Jul 31 2019" - }, - { - "standard_object": "Ticket", - "source_app": "Slack", - "status": "mapped", - "category": "TICKETING", - "source_field": "favorite_color", - "destination_field": "fav_color", - "data_type": "string", - "date": "Jul 31 2019" - }, - { - "standard_object": "Contact", - "source_app": "Hubspot", - "status": "defined", - "category": "CRM", - "source_field": "favorite_color", - "destination_field": "fav_color", - "data_type": "string", - "date": "Jul 31 2019" - }, - { - "standard_object": "Contact", - "source_app": "Hubspot", - "status": "defined", - "category": "CRM", - "source_field": "favorite_color", - "destination_field": "fav_color", - "data_type": "string", - "date": "Jul 31 2019" - }, -] \ No newline at end of file diff --git a/apps/client-ts/src/components/Configuration/data/seed.ts b/apps/client-ts/src/components/Configuration/data/seed.ts deleted file mode 100644 index b35a5ef17..000000000 --- a/apps/client-ts/src/components/Configuration/data/seed.ts +++ /dev/null @@ -1,20 +0,0 @@ -import fs from "fs" -import path from "path" -import { faker } from "@faker-js/faker" - -import { labels, priorities, statuses } from "./data" - -const tasks = Array.from({ length: 100 }, () => ({ - id: `TASK-${faker.number.int({ min: 1000, max: 9999 })}`, - title: faker.hacker.phrase().replace(/^./, (letter) => letter.toUpperCase()), - status: faker.helpers.arrayElement(statuses).value, - label: faker.helpers.arrayElement(labels).value, - direction: faker.helpers.arrayElement(priorities).value, -})) - -fs.writeFileSync( - path.join(__dirname, "tasks.json"), - JSON.stringify(tasks, null, 2) -) - -console.log("✅ Tasks data generated.") \ No newline at end of file diff --git a/apps/client-ts/src/components/Connection/AddConnectionButton.tsx b/apps/client-ts/src/components/Connection/AddConnectionButton.tsx index 341b18e51..835d876f5 100644 --- a/apps/client-ts/src/components/Connection/AddConnectionButton.tsx +++ b/apps/client-ts/src/components/Connection/AddConnectionButton.tsx @@ -34,11 +34,10 @@ import { PopoverTrigger, } from "@/components/ui/popover" import { PlusCircledIcon } from "@radix-ui/react-icons" -import { cn } from "@/lib/utils" import { useState } from "react" import useOrganisationStore from "@/state/organisationStore" import useProjectStore from "@/state/projectStore" -import useMagicLinkMutation from "@/hooks/mutations/useMagicLinkMutation" +import useCreateMagicLink from "@/hooks/create/useCreateMagicLink" import { zodResolver } from "@hookform/resolvers/zod" import { useForm } from "react-hook-form" import * as z from "zod" @@ -53,7 +52,6 @@ const formSchema = z.object({ message: "linkedUserMail must be at least 2 characters.", }), }) - interface LinkedUserModalObj { open: boolean; import?: boolean; @@ -74,7 +72,7 @@ const AddConnectionButton = ({ const posthog = usePostHog() - const { mutate, isError, error } = useMagicLinkMutation(); + const { mutate, isError, error } = useCreateMagicLink(); const {nameOrg} = useOrganisationStore(); const {idProject} = useProjectStore(); @@ -119,13 +117,10 @@ const AddConnectionButton = ({ @@ -260,7 +255,7 @@ const AddConnectionButton = ({ Cancel - + diff --git a/apps/client-ts/src/components/Connection/ConnectionTable.tsx b/apps/client-ts/src/components/Connection/ConnectionTable.tsx index a271e762e..220130552 100644 --- a/apps/client-ts/src/components/Connection/ConnectionTable.tsx +++ b/apps/client-ts/src/components/Connection/ConnectionTable.tsx @@ -12,7 +12,7 @@ import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, D import { Button } from "../ui/button"; import { PlusCircledIcon } from "@radix-ui/react-icons"; import CopyLinkInput from "./CopyLinkInput"; -import useConnections from "@/hooks/useConnections"; +import useConnections from "@/hooks/get/useConnections"; import { DataTableLoading } from "../shared/data-table-loading"; import { Suspense, useState } from "react"; import AddConnectionButton from "./AddConnectionButton"; @@ -21,7 +21,6 @@ import useMagicLinkStore from "@/state/magicLinkStore"; import useOrganisationStore from "@/state/organisationStore"; import { usePostHog } from 'posthog-js/react' import useProjectStore from "@/state/projectStore"; -import Cookies from 'js-cookie'; export default function ConnectionTable() { diff --git a/apps/client-ts/src/components/Connection/CopyLinkInput.tsx b/apps/client-ts/src/components/Connection/CopyLinkInput.tsx index a3aa77767..3bb7f773b 100644 --- a/apps/client-ts/src/components/Connection/CopyLinkInput.tsx +++ b/apps/client-ts/src/components/Connection/CopyLinkInput.tsx @@ -12,7 +12,6 @@ const CopyLinkInput = () => { const {uniqueLink} = useMagicLinkStore(); - const handleCopy = async () => { try { await navigator.clipboard.writeText(`${config.MAGIC_LINK_DOMAIN}/?uniqueLink=${uniqueLink}`); diff --git a/apps/client-ts/src/components/Connection/columns.tsx b/apps/client-ts/src/components/Connection/columns.tsx index 23fad47b4..a5d6f9fdb 100644 --- a/apps/client-ts/src/components/Connection/columns.tsx +++ b/apps/client-ts/src/components/Connection/columns.tsx @@ -5,9 +5,9 @@ import { ColumnDef } from "@tanstack/react-table" import { Badge } from "@/components/ui/badge" import { Checkbox } from "@/components/ui/checkbox" -import { Connection } from "./data/schema" +import { Connection } from "./schema" import { DataTableColumnHeader } from "./../shared/data-table-column-header" -import React,{ useState } from "react" +import React from "react" import { ClipboardIcon } from '@radix-ui/react-icons' import { toast } from "sonner" import { getLogoURL } from "@panora/shared" diff --git a/apps/client-ts/src/components/Connection/data/connection.ts b/apps/client-ts/src/components/Connection/data/connection.ts deleted file mode 100644 index df86f4189..000000000 --- a/apps/client-ts/src/components/Connection/data/connection.ts +++ /dev/null @@ -1,132 +0,0 @@ -export const CONNECTIONS = [ - { - "linkedUser": "TASK-8782", - "status": "in progress", - "app": "documentation", - "category": "medium", - "date": "", - "organisation": "", - "connectionToken": "", - - }, - { - "linkedUser": "TASK-7878", - "integration": "Try to calculate the EXE feed, maybe it will index the multi-byte pixel!", - "status": "backlog", - "app": "documentation", - "category": "medium", - "date": "", - "organisation": "", - "connectionToken": "", - }, - { - "linkedUser": "TASK-7839", - "integration": "We need to bypass the neural TCP card!", - "status": "todo", - "app": "bug", - "category": "high", - "date": "", - "organisation": "", - "connectionToken": "", - }, - { - "linkedUser": "TASK-5562", - "integration": "The SAS interface is down, bypass the open-source pixel so we can back up the PNG bandwlinkedUserth!", - "status": "backlog", - "app": "feature", - "category": "medium", - "date": "", - "organisation": "", - "connectionToken": "", - }, - { - "linkedUser": "TASK-8686", - "integration": "I'll parse the wireless SSL protocol, that should driver the API panel!", - "status": "canceled", - "app": "feature", - "category": "medium", - "date": "", - "organisation": "", - "connectionToken": "", - }, - { - "linkedUser": "TASK-1280", - "integration": "Use the digital TLS panel, then you can transmit the haptic system!", - "status": "done", - "app": "bug", - "category": "high", - "date": "", - "organisation": "", - "connectionToken": "", - }, - { - "linkedUser": "TASK-7262", - "integration": "The UTF8 application is down, parse the neural bandwlinkedUserth so we can back up the PNG firewall!", - "status": "done", - "app": "feature", - "category": "high", - "date": "", - "organisation": "", - "connectionToken": "", - }, - { - "linkedUser": "TASK-1138", - "integration": "Generating the driver won't do anything, we need to quantify the 1080p SMTP bandwlinkedUserth!", - "status": "in progress", - "app": "feature", - "category": "medium", - "date": "", - "organisation": "", - "connectionToken": "", - }, - { - "linkedUser": "TASK-7184", - "integration": "We need to program the back-end THX pixel!", - "status": "todo", - "app": "feature", - "category": "low", - "date": "", - "organisation": "", - "connectionToken": "", - }, - { - "linkedUser": "TASK-5160", - "integration": "Calculating the bus won't do anything, we need to navigate the back-end JSON protocol!", - "status": "in progress", - "app": "documentation", - "category": "high", - "date": "", - "organisation": "", - "connectionToken": "", - }, - { - "linkedUser": "TASK-5618", - "integration": "Generating the driver won't do anything, we need to index the online SSL application!", - "status": "done", - "app": "documentation", - "category": "medium", - "date": "", - "organisation": "", - "connectionToken": "", - }, - { - "linkedUser": "TASK-6699", - "integration": "I'll transmit the wireless JBOD capacitor, that should hard drive the SSD feed!", - "status": "backlog", - "app": "documentation", - "category": "medium", - "date": "", - "organisation": "", - "connectionToken": "", - }, - { - "linkedUser": "TASK-2858", - "integration": "We need to overrlinkedUsere the online UDP bus!", - "status": "backlog", - "app": "bug", - "category": "medium", - "date": "", - "organisation": "", - "connectionToken": "", - }, -] \ No newline at end of file diff --git a/apps/client-ts/src/components/Connection/data/data.tsx b/apps/client-ts/src/components/Connection/data/data.tsx deleted file mode 100644 index 03743ba86..000000000 --- a/apps/client-ts/src/components/Connection/data/data.tsx +++ /dev/null @@ -1,71 +0,0 @@ -import { - ArrowDownIcon, - ArrowRightIcon, - ArrowUpIcon, - CheckCircledIcon, - CircleIcon, - CrossCircledIcon, - QuestionMarkCircledIcon, - StopwatchIcon, - } from "@radix-ui/react-icons" - - export const labels = [ - { - value: "bug", - label: "Bug", - }, - { - value: "feature", - label: "Feature", - }, - { - value: "documentation", - label: "Documentation", - }, - ] - - export const statuses = [ - { - value: "backlog", - label: "Backlog", - icon: QuestionMarkCircledIcon, - }, - { - value: "todo", - label: "Todo", - icon: CircleIcon, - }, - { - value: "in progress", - label: "In Progress", - icon: StopwatchIcon, - }, - { - value: "done", - label: "Done", - icon: CheckCircledIcon, - }, - { - value: "canceled", - label: "Canceled", - icon: CrossCircledIcon, - }, - ] - - export const priorities = [ - { - label: "Low", - value: "low", - icon: ArrowDownIcon, - }, - { - label: "Medium", - value: "medium", - icon: ArrowRightIcon, - }, - { - label: "High", - value: "high", - icon: ArrowUpIcon, - }, - ] \ No newline at end of file diff --git a/apps/client-ts/src/components/Connection/data/seed.ts b/apps/client-ts/src/components/Connection/data/seed.ts deleted file mode 100644 index b35a5ef17..000000000 --- a/apps/client-ts/src/components/Connection/data/seed.ts +++ /dev/null @@ -1,20 +0,0 @@ -import fs from "fs" -import path from "path" -import { faker } from "@faker-js/faker" - -import { labels, priorities, statuses } from "./data" - -const tasks = Array.from({ length: 100 }, () => ({ - id: `TASK-${faker.number.int({ min: 1000, max: 9999 })}`, - title: faker.hacker.phrase().replace(/^./, (letter) => letter.toUpperCase()), - status: faker.helpers.arrayElement(statuses).value, - label: faker.helpers.arrayElement(labels).value, - direction: faker.helpers.arrayElement(priorities).value, -})) - -fs.writeFileSync( - path.join(__dirname, "tasks.json"), - JSON.stringify(tasks, null, 2) -) - -console.log("✅ Tasks data generated.") \ No newline at end of file diff --git a/apps/client-ts/src/components/Connection/data/schema.ts b/apps/client-ts/src/components/Connection/schema.ts similarity index 100% rename from apps/client-ts/src/components/Connection/data/schema.ts rename to apps/client-ts/src/components/Connection/schema.ts diff --git a/apps/client-ts/src/components/Dashboard/date-range-picker.tsx b/apps/client-ts/src/components/Dashboard/date-range-picker.tsx deleted file mode 100644 index 67b3b4595..000000000 --- a/apps/client-ts/src/components/Dashboard/date-range-picker.tsx +++ /dev/null @@ -1,65 +0,0 @@ -"use client" - -import * as React from "react" -import { CalendarIcon } from "@radix-ui/react-icons" -import { addDays, format } from "date-fns" -import { DateRange } from "react-day-picker" - -import { cn } from "@/lib/utils" -import { Button } from "@/components/ui/button" -import { Calendar } from "@/components/ui/calendar" -import { - Popover, - PopoverContent, - PopoverTrigger, -} from "@/components/ui/popover" - -export function CalendarDateRangePicker({ - className, -}: React.HTMLAttributes) { - const [date, setDate] = React.useState({ - from: new Date(2023, 0, 20), - to: addDays(new Date(2023, 0, 20), 20), - }) - - return ( -
- - - - - - - - -
- ) -} \ No newline at end of file diff --git a/apps/client-ts/src/components/Dashboard/overview.tsx b/apps/client-ts/src/components/Dashboard/overview.tsx deleted file mode 100644 index 980131dc0..000000000 --- a/apps/client-ts/src/components/Dashboard/overview.tsx +++ /dev/null @@ -1,78 +0,0 @@ -"use client" - -import { Bar, BarChart, ResponsiveContainer, XAxis, YAxis } from "recharts" - -const data = [ - { - name: "Jan", - total: Math.floor(Math.random() * 5000) + 1000, - }, - { - name: "Feb", - total: Math.floor(Math.random() * 5000) + 1000, - }, - { - name: "Mar", - total: Math.floor(Math.random() * 5000) + 1000, - }, - { - name: "Apr", - total: Math.floor(Math.random() * 5000) + 1000, - }, - { - name: "May", - total: Math.floor(Math.random() * 5000) + 1000, - }, - { - name: "Jun", - total: Math.floor(Math.random() * 5000) + 1000, - }, - { - name: "Jul", - total: Math.floor(Math.random() * 5000) + 1000, - }, - { - name: "Aug", - total: Math.floor(Math.random() * 5000) + 1000, - }, - { - name: "Sep", - total: Math.floor(Math.random() * 5000) + 1000, - }, - { - name: "Oct", - total: Math.floor(Math.random() * 5000) + 1000, - }, - { - name: "Nov", - total: Math.floor(Math.random() * 5000) + 1000, - }, - { - name: "Dec", - total: Math.floor(Math.random() * 5000) + 1000, - }, -] - -export function Overview() { - return ( - - - - `$${value}`} - /> - - - - ) -} \ No newline at end of file diff --git a/apps/client-ts/src/components/Events/EventsTable.tsx b/apps/client-ts/src/components/Events/EventsTable.tsx index b60993520..920897cdd 100644 --- a/apps/client-ts/src/components/Events/EventsTable.tsx +++ b/apps/client-ts/src/components/Events/EventsTable.tsx @@ -1,17 +1,16 @@ import { columns } from "./columns" import { ApiDataTable } from '../shared/api-data-table'; -import useEvents from "@/hooks/useEvents"; +import useEvents from "@/hooks/get/useEvents"; import { DataTableLoading } from "../shared/data-table-loading"; import { events as Event } from "api"; -import { useEventsCount } from '@/hooks/useEventsCount'; -import { useQueryPagination } from '@/hooks/useQueryPagination'; +import { useEventsCount } from '@/hooks/get/useEventsCount'; +import { useQueryPagination } from '@/hooks/get/useQueryPagination'; import useProjectStore from "@/state/projectStore"; export default function EventsTable() { const { data: eventsCount } = useEventsCount(); const pagination = useQueryPagination({ totalItems: eventsCount }); - const {idProject} = useProjectStore(); const { data: events, @@ -33,9 +32,6 @@ export default function EventsTable() { date: event.timestamp.toLocaleString(), // convert Date to string })); - // Already did it at api level - // const sortedTransformedEvents = transformedEvents?.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime()); - if(isLoading){ return ( @@ -46,7 +42,6 @@ export default function EventsTable() { console.log("error events.."); } - return ( <> {transformedEvents && ( diff --git a/apps/client-ts/src/components/Events/columns.tsx b/apps/client-ts/src/components/Events/columns.tsx index 5f5bfd020..27b8f8d06 100644 --- a/apps/client-ts/src/components/Events/columns.tsx +++ b/apps/client-ts/src/components/Events/columns.tsx @@ -6,7 +6,7 @@ import { Badge } from "@/components/ui/badge" import { Checkbox } from "@/components/ui/checkbox" import { DataTableColumnHeader } from "../shared/data-table-column-header" -import { Event } from "./data/schema" +import { Event } from "./schema" import { getLogoURL } from "@panora/shared" export const columns: ColumnDef[] = [ diff --git a/apps/client-ts/src/components/Events/data/data.tsx b/apps/client-ts/src/components/Events/data/data.tsx deleted file mode 100644 index 670860193..000000000 --- a/apps/client-ts/src/components/Events/data/data.tsx +++ /dev/null @@ -1,86 +0,0 @@ -import { - ArrowDownIcon, - ArrowRightIcon, - ArrowUpIcon, - CheckCircledIcon, - CircleIcon, - CrossCircledIcon, - QuestionMarkCircledIcon, - StopwatchIcon, - } from "@radix-ui/react-icons" - - export const labels = [ - { - value: "/crm/tasks", - label: "/crm/tasks", - }, - { - value: "/crm/notess", - label: "/crm/notess", - }, - { - value: "/crm/contacts", - label: "/crm/contacts", - }, - ] - - export const labels2 = [ - { - value: "GET", - label: "GET", - }, - { - value: "POST", - label: "POST", - }, - { - value: "GET", - label: "GET", - }, - ] - - export const statuses = [ - { - value: "backlog", - label: "Backlog", - icon: QuestionMarkCircledIcon, - }, - { - value: "todo", - label: "Todo", - icon: CircleIcon, - }, - { - value: "in progress", - label: "In Progress", - icon: StopwatchIcon, - }, - { - value: "done", - label: "Done", - icon: CheckCircledIcon, - }, - { - value: "canceled", - label: "Canceled", - icon: CrossCircledIcon, - }, - ] - - export const priorities = [ - { - label: "Low", - value: "low", - icon: ArrowDownIcon, - }, - { - label: "Medium", - value: "medium", - icon: ArrowRightIcon, - }, - { - label: "High", - value: "high", - icon: ArrowUpIcon, - }, - ] \ No newline at end of file diff --git a/apps/client-ts/src/components/Events/data/jobsConst.ts b/apps/client-ts/src/components/Events/data/jobsConst.ts deleted file mode 100644 index bbee2b0f8..000000000 --- a/apps/client-ts/src/components/Events/data/jobsConst.ts +++ /dev/null @@ -1,120 +0,0 @@ -export const JOBS = [ - { - "method": "GET", - "integration": "You can't compress the program without quantifying the open-source SSD pixel!", - "status": "in progress", - "url": "/crm/contacts", - "direction": "medium", - "date": "", - "organisation": "", - - }, - { - "method": "GET", - "integration": "Try to calculate the EXE feed, maybe it will index the multi-byte pixel!", - "status": "backlog", - "url": "/crm/contacts", - "direction": "medium", - "date": "", - "organisation": "", - }, - { - "method": "GET", - "integration": "We need to bypass the neural TCP card!", - "status": "todo", - "url": "/crm/tasks", - "direction": "high", - "date": "", - "organisation": "", - }, - { - "method": "GET", - "integration": "The SAS interface is down, bypass the open-source pixel so we can back up the PNG bandwmethodth!", - "status": "backlog", - "url": "/crm/notess", - "direction": "medium", - "date": "", - "organisation": "", - }, - { - "method": "GET", - "integration": "I'll parse the wireless SSL protocol, that should driver the API panel!", - "status": "canceled", - "url": "/crm/notess", - "direction": "medium", - "date": "", - "organisation": "", - }, - { - "method": "POST", - "integration": "Use the digital TLS panel, then you can transmit the haptic system!", - "status": "done", - "url": "/crm/tasks", - "direction": "high", - "date": "", - "organisation": "", - }, - { - "method": "POST", - "integration": "The UTF8 application is down, parse the neural bandwmethodth so we can back up the PNG firewall!", - "status": "done", - "url": "/crm/notess", - "direction": "high", - "date": "", - "organisation": "", - }, - { - "method": "GET", - "integration": "Generating the driver won't do anything, we need to quantify the 1080p SMTP bandwmethodth!", - "status": "in progress", - "url": "/crm/notess", - "direction": "medium", - "date": "", - "organisation": "", - }, - { - "method": "GET", - "integration": "We need to program the back-end THX pixel!", - "status": "todo", - "url": "/crm/notess", - "direction": "low", - "date": "", - "organisation": "", - }, - { - "method": "POST", - "integration": "Calculating the bus won't do anything, we need to navigate the back-end JSON protocol!", - "status": "in progress", - "url": "/crm/contacts", - "direction": "high", - "date": "", - "organisation": "", - }, - { - "method": "POST", - "integration": "Generating the driver won't do anything, we need to index the online SSL application!", - "status": "done", - "url": "/crm/contacts", - "direction": "medium", - "date": "", - "organisation": "", - }, - { - "method": "GET", - "integration": "I'll transmit the wireless JBOD capacitor, that should hard drive the SSD feed!", - "status": "backlog", - "url": "/crm/contacts", - "direction": "medium", - "date": "", - "organisation": "", - }, - { - "method": "POST", - "integration": "We need to overrmethode the online UDP bus!", - "status": "backlog", - "url": "/crm/tasks", - "direction": "medium", - "date": "", - "organisation": "", - }, -] \ No newline at end of file diff --git a/apps/client-ts/src/components/Events/data/seed.ts b/apps/client-ts/src/components/Events/data/seed.ts deleted file mode 100644 index b35a5ef17..000000000 --- a/apps/client-ts/src/components/Events/data/seed.ts +++ /dev/null @@ -1,20 +0,0 @@ -import fs from "fs" -import path from "path" -import { faker } from "@faker-js/faker" - -import { labels, priorities, statuses } from "./data" - -const tasks = Array.from({ length: 100 }, () => ({ - id: `TASK-${faker.number.int({ min: 1000, max: 9999 })}`, - title: faker.hacker.phrase().replace(/^./, (letter) => letter.toUpperCase()), - status: faker.helpers.arrayElement(statuses).value, - label: faker.helpers.arrayElement(labels).value, - direction: faker.helpers.arrayElement(priorities).value, -})) - -fs.writeFileSync( - path.join(__dirname, "tasks.json"), - JSON.stringify(tasks, null, 2) -) - -console.log("✅ Tasks data generated.") \ No newline at end of file diff --git a/apps/client-ts/src/components/Events/data/schema.ts b/apps/client-ts/src/components/Events/schema.ts similarity index 100% rename from apps/client-ts/src/components/Events/data/schema.ts rename to apps/client-ts/src/components/Events/schema.ts diff --git a/apps/client-ts/src/components/Nav/main-nav-sm.tsx b/apps/client-ts/src/components/Nav/main-nav-sm.tsx index 84c22e3bf..05e097ba6 100644 --- a/apps/client-ts/src/components/Nav/main-nav-sm.tsx +++ b/apps/client-ts/src/components/Nav/main-nav-sm.tsx @@ -22,14 +22,14 @@ export function SmallNav({ const [open, setOpen] = useState(false); const navItemClassName = (itemName: string) => `text-sm border-b font-medium w-full text-left mx-0 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" - } transition-colors`; - - function click(name: string) { - setSelectedItem(name); - onLinkClick(name); - setOpen(false); - } + selectedItem === itemName ? "dark:bg-zinc-800 bg-zinc-200" : "text-muted-foreground" + } transition-colors`; + + function click(name: string) { + setSelectedItem(name); + onLinkClick(name); + setOpen(false); + } return (
diff --git a/apps/client-ts/src/components/Nav/main-nav.tsx b/apps/client-ts/src/components/Nav/main-nav.tsx index e26ed860c..0c477c8c7 100644 --- a/apps/client-ts/src/components/Nav/main-nav.tsx +++ b/apps/client-ts/src/components/Nav/main-nav.tsx @@ -13,14 +13,15 @@ export function MainNav({ }) { const [selectedItem, setSelectedItem] = useState(""); const pathname = usePathname(); + useEffect(() => { setSelectedItem(pathname.substring(1)) }, [pathname]) const navItemClassName = (itemName: string) => `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`; + selectedItem === itemName ? 'bg-accent' : 'transparent' + } transition-colors`; function click(e: MouseEvent, name: string) { e.preventDefault(); diff --git a/apps/client-ts/src/components/Nav/user-nav.tsx b/apps/client-ts/src/components/Nav/user-nav.tsx index 996d0a269..e42590d71 100644 --- a/apps/client-ts/src/components/Nav/user-nav.tsx +++ b/apps/client-ts/src/components/Nav/user-nav.tsx @@ -20,11 +20,10 @@ import Cookies from 'js-cookie'; import useProjectStore from "@/state/projectStore" import { useQueryClient } from '@tanstack/react-query'; - export function UserNav() { const router = useRouter(); const { profile, setProfile } = useProfileStore(); - const { idProject, setIdProject } = useProjectStore(); + const { setIdProject } = useProjectStore(); const queryClient = useQueryClient(); const onLogout = () => { @@ -33,7 +32,6 @@ export function UserNav() { setProfile(null) setIdProject("") queryClient.clear() - } return ( diff --git a/apps/client-ts/src/components/Provider/provider.tsx b/apps/client-ts/src/components/Provider/provider.tsx index 5c3522929..e9e423564 100644 --- a/apps/client-ts/src/components/Provider/provider.tsx +++ b/apps/client-ts/src/components/Provider/provider.tsx @@ -10,7 +10,7 @@ function Provider({ children }: any) { <> - {children} + {children} diff --git a/apps/client-ts/src/components/RootLayout/index.tsx b/apps/client-ts/src/components/RootLayout/index.tsx index b0a1008a6..a54968a2b 100644 --- a/apps/client-ts/src/components/RootLayout/index.tsx +++ b/apps/client-ts/src/components/RootLayout/index.tsx @@ -10,8 +10,8 @@ import { useRouter } from 'next/navigation'; import { cn } from "@/lib/utils"; import useProjectStore from '@/state/projectStore'; import { ThemeToggle } from '@/components/Nav/theme-toggle'; -import useProjects from '@/hooks/useProjects'; -import useRefreshAccessTokenMutation from '@/hooks/mutations/useRefreshAccessTokenMutation'; +import useProjects from '@/hooks/get/useProjects'; +import useRefreshAccessTokenMutation from '@/hooks/create/useRefreshAccessToken'; import { useTheme } from 'next-themes'; export const RootLayout = ({children}:{children:React.ReactNode}) => { diff --git a/apps/client-ts/src/components/shared/api-data-table-pagination.tsx b/apps/client-ts/src/components/shared/api-data-table-pagination.tsx index 5225e774a..0692d4f90 100644 --- a/apps/client-ts/src/components/shared/api-data-table-pagination.tsx +++ b/apps/client-ts/src/components/shared/api-data-table-pagination.tsx @@ -2,7 +2,7 @@ import { ChevronLeftIcon, ChevronRightIcon, DoubleArrowLeftIcon, DoubleArrowRigh import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'; import { Button } from '@/components/ui/button'; -import { type UseQueryPaginationReturn } from '@/hooks/useQueryPagination'; +import { type UseQueryPaginationReturn } from '@/hooks/get/useQueryPagination'; interface DataTablePaginationProps extends UseQueryPaginationReturn { selected: number; diff --git a/apps/client-ts/src/components/shared/api-data-table.tsx b/apps/client-ts/src/components/shared/api-data-table.tsx index 14582ca7e..0608a05ca 100644 --- a/apps/client-ts/src/components/shared/api-data-table.tsx +++ b/apps/client-ts/src/components/shared/api-data-table.tsx @@ -17,7 +17,7 @@ import { ApiDataTablePagination } from './api-data-table-pagination'; import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table'; import { LoadingSpinner } from '../Connection/LoadingSpinner'; -import { type UseQueryPaginationReturn } from '@/hooks/useQueryPagination'; +import { type UseQueryPaginationReturn } from '@/hooks/get/useQueryPagination'; interface DataTableProps extends UseQueryPaginationReturn { columns: ColumnDef[]; diff --git a/apps/client-ts/src/components/shared/data-table-row-actions.tsx b/apps/client-ts/src/components/shared/data-table-row-actions.tsx index b9f7b2075..952079b44 100644 --- a/apps/client-ts/src/components/shared/data-table-row-actions.tsx +++ b/apps/client-ts/src/components/shared/data-table-row-actions.tsx @@ -8,24 +8,39 @@ import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, - DropdownMenuSeparator, DropdownMenuShortcut, - DropdownMenuSub, - DropdownMenuSubContent, - DropdownMenuSubTrigger, DropdownMenuTrigger, } from "@/components/ui/dropdown-menu" - +import useDeleteApiKey from "@/hooks/delete/useDeleteApiKey" +import useDeleteWebhook from "@/hooks/delete/useDeleteWebhook" interface DataTableRowActionsProps { - row: Row + row: Row; + object: "webhook" | "api-key" } export function DataTableRowActions({ row, + object }: DataTableRowActionsProps) { - //const task = taskSchema.parse(row.original) - //console.log(row); + + const {mutate: removeApiKey} = useDeleteApiKey(); + const {mutate: removeWebhook} = useDeleteWebhook(); + + const handleDeletion = () => { + switch(object) { + case 'webhook': + removeWebhook({ + id_webhook: row.original.id_webhook_endpoint + }) + break; + case 'api-key': + removeApiKey({ + id_api_key: row.original.id_api_key + }) + break; + } + } return ( @@ -39,24 +54,7 @@ export function DataTableRowActions({ - Edit - Make a copy - Favorite - - - Labels - - {/* - {labels.map((label) => ( - - {label.label} - - ))} - */} - - - - + Delete ⌘⌫ diff --git a/apps/client-ts/src/components/shared/team-switcher.tsx b/apps/client-ts/src/components/shared/team-switcher.tsx index c4739e467..01533a572 100644 --- a/apps/client-ts/src/components/shared/team-switcher.tsx +++ b/apps/client-ts/src/components/shared/team-switcher.tsx @@ -46,7 +46,7 @@ import { FormLabel, FormMessage, } from "@/components/ui/form" -import useProjectMutation from "@/hooks/mutations/useProjectMutation" +import useProjectMutation from "@/hooks/create/useCreateProject" import { useEffect, useState } from "react" import useProjectStore from "@/state/projectStore" import { zodResolver } from "@hookform/resolvers/zod" @@ -56,7 +56,7 @@ import config from "@/lib/config" import { Skeleton } from "@/components/ui/skeleton"; import useProfileStore from "@/state/profileStore" import { projects as Project } from 'api'; -import useRefreshAccessTokenMutation from "@/hooks/mutations/useRefreshAccessTokenMutation" +import useRefreshAccessTokenMutation from "@/hooks/create/useRefreshAccessToken" const projectFormSchema = z.object({ @@ -126,13 +126,23 @@ export default function TeamSwitcher({ className ,projects}: TeamSwitcherProps) role="combobox" aria-expanded={open} aria-label="Select a team" - className={cn("w-[250px] justify-between", className)} + className={cn("w-[250px] justify-between rounded-xl", className)} > { projects && projects.length > 0 - ? projects.find(p => p.id_project === idProject)?.name || "Selected project not found" - : "No projects found" + ? <> + + p.id_project === idProject)?.name}.png`} + alt={projects.find(p => p.id_project === idProject)?.name} + className="" + /> + SC + + {projects.find(p => p.id_project === idProject)?.name || "Selected project not found"} + : "No projects found" } + @@ -248,10 +258,10 @@ export default function TeamSwitcher({ className ,projects}: TeamSwitcherProps)
- - + diff --git a/apps/client-ts/src/hooks/mutations/useApiKeyMutation.tsx b/apps/client-ts/src/hooks/create/useCreateApiKey.tsx similarity index 96% rename from apps/client-ts/src/hooks/mutations/useApiKeyMutation.tsx rename to apps/client-ts/src/hooks/create/useCreateApiKey.tsx index 2254fa036..d31e401f3 100644 --- a/apps/client-ts/src/hooks/mutations/useApiKeyMutation.tsx +++ b/apps/client-ts/src/hooks/create/useCreateApiKey.tsx @@ -8,9 +8,8 @@ interface IApiKeyDto { userId: string; keyName?: string; } -const useApiKeyMutation = () => { +const useCreateApiKey = () => { const queryClient = useQueryClient(); - const addApiKey = async (data: IApiKeyDto) => { const response = await fetch(`${config.API_URL}/auth/generate-apikey`, { method: 'POST', @@ -64,4 +63,4 @@ const useApiKeyMutation = () => { }); }; -export default useApiKeyMutation; +export default useCreateApiKey; diff --git a/apps/client-ts/src/hooks/mutations/useConnectionStrategy.tsx b/apps/client-ts/src/hooks/create/useCreateConnectionStrategy.tsx similarity index 90% rename from apps/client-ts/src/hooks/mutations/useConnectionStrategy.tsx rename to apps/client-ts/src/hooks/create/useCreateConnectionStrategy.tsx index 12f072aa6..6ef2748cc 100644 --- a/apps/client-ts/src/hooks/mutations/useConnectionStrategy.tsx +++ b/apps/client-ts/src/hooks/create/useCreateConnectionStrategy.tsx @@ -17,10 +17,10 @@ interface IFetchConnectionStrategyDto { } -const useConnectionStrategyMutation = () => { +const useCreateConnectionStrategy = () => { const queryClient = useQueryClient(); - const addConnectionStrategy = async (connectionStrategyData: IConnectionStrategyDto) => { + const add = async (connectionStrategyData: IConnectionStrategyDto) => { const response = await fetch(`${config.API_URL}/connections-strategies/create`, { method: 'POST', body: JSON.stringify(connectionStrategyData), @@ -39,7 +39,7 @@ const useConnectionStrategyMutation = () => { return response.json(); }; return useMutation({ - mutationFn: addConnectionStrategy, + mutationFn: add, onMutate: () => { toast("Connection Strategy is being created !", { description: "", @@ -75,4 +75,4 @@ const useConnectionStrategyMutation = () => { }); }; -export default useConnectionStrategyMutation; +export default useCreateConnectionStrategy; diff --git a/apps/client-ts/src/hooks/mutations/useLinkedUserMutation.tsx b/apps/client-ts/src/hooks/create/useCreateLinkedUser.tsx similarity index 90% rename from apps/client-ts/src/hooks/mutations/useLinkedUserMutation.tsx rename to apps/client-ts/src/hooks/create/useCreateLinkedUser.tsx index 13928bc1d..bc35795ea 100644 --- a/apps/client-ts/src/hooks/mutations/useLinkedUserMutation.tsx +++ b/apps/client-ts/src/hooks/create/useCreateLinkedUser.tsx @@ -6,10 +6,10 @@ interface ILinkedUserDto { alias: string; id_project: string; } -const useLinkedUserMutation = () => { +const useCreateLinkedUser = () => { const queryClient = useQueryClient(); - const addLinkedUser = async (linkedUserData: ILinkedUserDto) => { + const add = async (linkedUserData: ILinkedUserDto) => { const response = await fetch(`${config.API_URL}/linked-users`, { method: 'POST', body: JSON.stringify(linkedUserData), @@ -25,7 +25,7 @@ const useLinkedUserMutation = () => { return response.json(); }; return useMutation({ - mutationFn: addLinkedUser, + mutationFn: add, onMutate: () => { toast("Linked user is being created !", { description: "", @@ -61,4 +61,4 @@ const useLinkedUserMutation = () => { }); }; -export default useLinkedUserMutation; +export default useCreateLinkedUser; diff --git a/apps/client-ts/src/hooks/mutations/useLoginMutation.tsx b/apps/client-ts/src/hooks/create/useCreateLogin.tsx similarity index 89% rename from apps/client-ts/src/hooks/mutations/useLoginMutation.tsx rename to apps/client-ts/src/hooks/create/useCreateLogin.tsx index 39897ca01..64a427e9d 100644 --- a/apps/client-ts/src/hooks/mutations/useLoginMutation.tsx +++ b/apps/client-ts/src/hooks/create/useCreateLogin.tsx @@ -22,11 +22,11 @@ interface ILoginOutputDto { access_token: string } -const useLoginMutation = () => { +const useCreateLogin = () => { const {setProfile} = useProfileStore() - const loginUser = async (userData: ILoginInputDto) => { + const add = async (userData: ILoginInputDto) => { // Fetch the token const response = await fetch(`${config.API_URL}/auth/login`, { method: 'POST', @@ -43,7 +43,7 @@ const useLoginMutation = () => { return response.json(); }; return useMutation({ - mutationFn: loginUser, + mutationFn: add, onMutate: () => { // toast("Logging the user !", { // description: "", @@ -65,8 +65,6 @@ const useLoginMutation = () => { onSuccess: (data : ILoginOutputDto) => { setProfile(data.user); Cookies.set('access_token',data.access_token,{expires:1}); - //console.log("Bearer Token in client Side : ",data.access_token); - toast.success("User has been generated !", { description: "", action: { @@ -80,4 +78,4 @@ const useLoginMutation = () => { }); }; -export default useLoginMutation; +export default useCreateLogin; diff --git a/apps/client-ts/src/hooks/mutations/useMagicLinkMutation.tsx b/apps/client-ts/src/hooks/create/useCreateMagicLink.tsx similarity index 91% rename from apps/client-ts/src/hooks/mutations/useMagicLinkMutation.tsx rename to apps/client-ts/src/hooks/create/useCreateMagicLink.tsx index 0b18d7ed8..abd3a876e 100644 --- a/apps/client-ts/src/hooks/mutations/useMagicLinkMutation.tsx +++ b/apps/client-ts/src/hooks/create/useCreateMagicLink.tsx @@ -11,8 +11,8 @@ interface ILinkDto { id_project: string; } -const useMagicLinkMutation = () => { - const generateLink = async (data: ILinkDto) => { +const useCreateMagicLink = () => { + const add = async (data: ILinkDto) => { const response = await fetch(`${config.API_URL}/magic-links`, { method: 'POST', body: JSON.stringify(data), @@ -31,7 +31,7 @@ const useMagicLinkMutation = () => { const {setUniqueLink} = useMagicLinkStore(); return useMutation({ - mutationFn: generateLink, + mutationFn: add, onMutate: () => { toast("Magic link is being generated !", { description: "", @@ -65,4 +65,4 @@ const useMagicLinkMutation = () => { }); }; -export default useMagicLinkMutation; +export default useCreateMagicLink; diff --git a/apps/client-ts/src/hooks/mutations/useProfileMutation.tsx b/apps/client-ts/src/hooks/create/useCreateProfile.tsx similarity index 92% rename from apps/client-ts/src/hooks/mutations/useProfileMutation.tsx rename to apps/client-ts/src/hooks/create/useCreateProfile.tsx index a3c286066..d4500d569 100644 --- a/apps/client-ts/src/hooks/mutations/useProfileMutation.tsx +++ b/apps/client-ts/src/hooks/create/useCreateProfile.tsx @@ -11,10 +11,10 @@ interface IProfileDto { id_organization?: string } -const useProfileMutation = () => { +const useCreateProfile = () => { const queryClient = useQueryClient(); - const addProfile = async (data: IProfileDto) => { + const add = async (data: IProfileDto) => { const response = await fetch(`${config.API_URL}/auth/users/create`, { method: 'POST', body: JSON.stringify(data), @@ -30,7 +30,7 @@ const useProfileMutation = () => { return response.json(); }; return useMutation({ - mutationFn: addProfile, + mutationFn: add, onMutate: () => { toast("Profile is being created !", { description: "", @@ -70,4 +70,4 @@ const useProfileMutation = () => { }); }; -export default useProfileMutation; +export default useCreateProfile; diff --git a/apps/client-ts/src/hooks/mutations/useProjectMutation.tsx b/apps/client-ts/src/hooks/create/useCreateProject.tsx similarity index 81% rename from apps/client-ts/src/hooks/mutations/useProjectMutation.tsx rename to apps/client-ts/src/hooks/create/useCreateProject.tsx index c146f25c3..94e5fb7fb 100644 --- a/apps/client-ts/src/hooks/mutations/useProjectMutation.tsx +++ b/apps/client-ts/src/hooks/create/useCreateProject.tsx @@ -8,10 +8,10 @@ interface IProDto { id_user: string; } -const useProjectMutation = () => { +const useCreateProject = () => { const queryClient = useQueryClient(); - const addProject = async (data: IProDto) => { + const add = async (data: IProDto) => { const response = await fetch(`${config.API_URL}/projects`, { method: 'POST', body: JSON.stringify(data), @@ -28,7 +28,7 @@ const useProjectMutation = () => { return response.json(); }; return useMutation({ - mutationFn: addProject, + mutationFn: add, onMutate: () => { toast("Project is being created !", { description: "", @@ -48,16 +48,14 @@ const useProjectMutation = () => { }) }, onSuccess: (data) => { - - // console.log(data) - queryClient.setQueryData(['projects'], (oldQueryData = []) => { + queryClient.setQueryData(['projects'], (oldQueryData = []) => { return [...oldQueryData, data]; }); toast("Project has been created !", { description: "", action: { - label: "Close", - onClick: () => console.log("Close"), + label: "Close", + onClick: () => console.log("Close"), }, }) }, @@ -66,4 +64,4 @@ const useProjectMutation = () => { }); }; -export default useProjectMutation; +export default useCreateProject; diff --git a/apps/client-ts/src/hooks/mutations/useCreateUserMutation.tsx b/apps/client-ts/src/hooks/create/useCreateUser.tsx similarity index 89% rename from apps/client-ts/src/hooks/mutations/useCreateUserMutation.tsx rename to apps/client-ts/src/hooks/create/useCreateUser.tsx index c6ff96fa2..719af603a 100644 --- a/apps/client-ts/src/hooks/mutations/useCreateUserMutation.tsx +++ b/apps/client-ts/src/hooks/create/useCreateUser.tsx @@ -10,9 +10,9 @@ interface IUserDto { password_hash: string, id_organisation?: string, } -const useCreateUserMutation = () => { +const useCreateUser = () => { - const addUser = async (userData: IUserDto) => { + const add = async (userData: IUserDto) => { // Fetch the token const response = await fetch(`${config.API_URL}/auth/register`, { method: 'POST', @@ -22,19 +22,14 @@ const useCreateUserMutation = () => { }, }); - - if (!response.ok) { throw new Error("Email already associated with other account!!") } - - - - + return response.json(); }; return useMutation({ - mutationFn: addUser, + mutationFn: add, onMutate: () => { toast("User is being created !", { description: "", @@ -68,4 +63,4 @@ const useCreateUserMutation = () => { }); }; -export default useCreateUserMutation; +export default useCreateUser; diff --git a/apps/client-ts/src/hooks/mutations/useWebhookMutation.tsx b/apps/client-ts/src/hooks/create/useCreateWebhook.tsx similarity index 91% rename from apps/client-ts/src/hooks/mutations/useWebhookMutation.tsx rename to apps/client-ts/src/hooks/create/useCreateWebhook.tsx index f90b9461b..90327d603 100644 --- a/apps/client-ts/src/hooks/mutations/useWebhookMutation.tsx +++ b/apps/client-ts/src/hooks/create/useCreateWebhook.tsx @@ -9,9 +9,9 @@ interface IWebhookDto { id_project: string; scope: string[]; } -const useWebhookMutation = () => { +const useCreateWebhook = () => { const queryClient = useQueryClient(); - const addWebhookEndpoint = async (data: IWebhookDto) => { + const add = async (data: IWebhookDto) => { const response = await fetch(`${config.API_URL}/webhook`, { method: 'POST', body: JSON.stringify(data), @@ -28,7 +28,7 @@ const useWebhookMutation = () => { return response.json(); }; return useMutation({ - mutationFn: addWebhookEndpoint, + mutationFn: add, onMutate: () => { toast("Webhook endpoint has been created !", { description: "", @@ -64,4 +64,4 @@ const useWebhookMutation = () => { }); }; -export default useWebhookMutation; +export default useCreateWebhook; diff --git a/apps/client-ts/src/hooks/mutations/useDefineFieldMutation.tsx b/apps/client-ts/src/hooks/create/useDefineField.tsx similarity index 91% rename from apps/client-ts/src/hooks/mutations/useDefineFieldMutation.tsx rename to apps/client-ts/src/hooks/create/useDefineField.tsx index 9324fcdb9..191c578ca 100644 --- a/apps/client-ts/src/hooks/mutations/useDefineFieldMutation.tsx +++ b/apps/client-ts/src/hooks/create/useDefineField.tsx @@ -10,10 +10,10 @@ interface IDefineTargetFieldDto{ data_type: string; } -const useDefineFieldMutation = () => { +const useDefineField = () => { const queryClient = useQueryClient() - const defineField = async (data: IDefineTargetFieldDto) => { + const define = async (data: IDefineTargetFieldDto) => { const response = await fetch(`${config.API_URL}/field-mappings/define`, { method: 'POST', body: JSON.stringify(data), @@ -30,7 +30,7 @@ const useDefineFieldMutation = () => { return response.json(); }; return useMutation({ - mutationFn: defineField, + mutationFn: define, onMutate: () => { toast("Field mapping is being defined !", { description: "", @@ -66,4 +66,4 @@ const useDefineFieldMutation = () => { }); }; -export default useDefineFieldMutation; +export default useDefineField; diff --git a/apps/client-ts/src/hooks/mutations/useMapFieldMutation.tsx b/apps/client-ts/src/hooks/create/useMapField.tsx similarity index 91% rename from apps/client-ts/src/hooks/mutations/useMapFieldMutation.tsx rename to apps/client-ts/src/hooks/create/useMapField.tsx index 55fd05a77..05b319597 100644 --- a/apps/client-ts/src/hooks/mutations/useMapFieldMutation.tsx +++ b/apps/client-ts/src/hooks/create/useMapField.tsx @@ -10,8 +10,8 @@ interface IMapTargetFieldDto { linked_user_id: string; } -const useMapFieldMutation = () => { - const mapField = async (data: IMapTargetFieldDto) => { +const useMapField = () => { + const map = async (data: IMapTargetFieldDto) => { const response = await fetch(`${config.API_URL}/field-mappings/map`, { method: 'POST', body: JSON.stringify(data), @@ -28,7 +28,7 @@ const useMapFieldMutation = () => { return response.json(); }; return useMutation({ - mutationFn: mapField, + mutationFn: map, onMutate: () => { toast("Field is being mapped !", { description: "", @@ -62,4 +62,4 @@ const useMapFieldMutation = () => { }); }; -export default useMapFieldMutation; +export default useMapField; diff --git a/apps/client-ts/src/hooks/mutations/useRefreshAccessTokenMutation.tsx b/apps/client-ts/src/hooks/create/useRefreshAccessToken.tsx similarity index 80% rename from apps/client-ts/src/hooks/mutations/useRefreshAccessTokenMutation.tsx rename to apps/client-ts/src/hooks/create/useRefreshAccessToken.tsx index 63e87fce7..b711bb00d 100644 --- a/apps/client-ts/src/hooks/mutations/useRefreshAccessTokenMutation.tsx +++ b/apps/client-ts/src/hooks/create/useRefreshAccessToken.tsx @@ -7,7 +7,7 @@ interface IRefreshOutputDto { access_token: string } -const useRefreshAccessTokenMutation = () => { +const useRefreshAccessToken = () => { const refreshAccessToken = async (projectId: string) => { const response = await fetch(`${config.API_URL}/auth/refresh-token`, { method: 'POST', @@ -42,17 +42,10 @@ const useRefreshAccessTokenMutation = () => { onSuccess: (data : IRefreshOutputDto) => { Cookies.remove('access_token'); Cookies.set('access_token', data.access_token, {expires:1}); - /*toast.success("Refresh has been generated !", { - description: "", - action: { - label: "Close", - onClick: () => console.log("Close"), - }, - })*/ }, onSettled: () => { }, }); }; -export default useRefreshAccessTokenMutation; +export default useRefreshAccessToken; diff --git a/apps/client-ts/src/hooks/delete/useDeleteApiKey.tsx b/apps/client-ts/src/hooks/delete/useDeleteApiKey.tsx new file mode 100644 index 000000000..a08e99463 --- /dev/null +++ b/apps/client-ts/src/hooks/delete/useDeleteApiKey.tsx @@ -0,0 +1,65 @@ +import config from '@/lib/config'; +import { useMutation, useQueryClient } from '@tanstack/react-query'; +import { toast } from "sonner" +import { api_keys as ApiKey } from 'api'; +import Cookies from 'js-cookie'; + +interface IApiKeyDto { + id_api_key: string; +} + +const useDeleteApiKey = () => { + const queryClient = useQueryClient(); + + const remove = async (apiKeyData: IApiKeyDto) => { + const response = await fetch(`${config.API_URL}/auth/api-keys/${apiKeyData.id_api_key}`, { + method: 'DELETE', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${Cookies.get('access_token')}`, + }, + }); + + if (!response.ok) { + throw new Error('Failed to delete api key'); + } + return response.json(); + }; + return useMutation({ + mutationFn: remove, + onMutate: () => { + toast("api key is being deleted !", { + description: "", + action: { + label: "Close", + onClick: () => console.log("Close"), + }, + }) + }, + onError: (error) => { + toast("The deleting of api key has failed !", { + description: error as any, + action: { + label: "Close", + onClick: () => console.log("Close"), + }, + }) + }, + onSuccess: (data: ApiKey) => { + queryClient.setQueryData(['api-keys'], (oldQueryData = []) => { + return oldQueryData.filter((api_key) => api_key.id_api_key !== data.id_api_key); + }); + toast("Api Key has been deleted successfully!", { + description: "The api key has been removed from your list.", + action: { + label: "Close", + onClick: () => console.log("Close"), + }, + }); + }, + onSettled: () => { + }, + }); +}; + +export default useDeleteApiKey; diff --git a/apps/client-ts/src/hooks/mutations/useDeleteConnectionStrategy.tsx b/apps/client-ts/src/hooks/delete/useDeleteConnectionStrategy.tsx similarity index 81% rename from apps/client-ts/src/hooks/mutations/useDeleteConnectionStrategy.tsx rename to apps/client-ts/src/hooks/delete/useDeleteConnectionStrategy.tsx index 8e6d91c8e..140b36a32 100644 --- a/apps/client-ts/src/hooks/mutations/useDeleteConnectionStrategy.tsx +++ b/apps/client-ts/src/hooks/delete/useDeleteConnectionStrategy.tsx @@ -6,17 +6,12 @@ import Cookies from 'js-cookie'; interface IDeleteConnectionStrategyDto { id_cs: string - } - -const useDeleteConnectionStrategyMutation = () => { +const useDeleteConnectionStrategy = () => { const queryClient = useQueryClient(); - const addConnectionStrategy = async (connectionStrategyData: IDeleteConnectionStrategyDto) => { - - - console.log(connectionStrategyData.id_cs) + const remove = async (connectionStrategyData: IDeleteConnectionStrategyDto) => { const response = await fetch(`${config.API_URL}/connections-strategies/delete`, { method: 'POST', body: JSON.stringify({id:connectionStrategyData.id_cs}), @@ -31,15 +26,9 @@ const useDeleteConnectionStrategyMutation = () => { } return response.json(); - - - - - - }; return useMutation({ - mutationFn: addConnectionStrategy, + mutationFn: remove, onMutate: () => { toast("Connection Strategy is being deleted !", { description: "", @@ -61,8 +50,7 @@ const useDeleteConnectionStrategyMutation = () => { onSuccess: (data : ConnectionStrategies) => { console.log("After Delete Data Received : ",JSON.stringify(data)) queryClient.setQueryData(['connection-strategies'], (oldQueryData = []) => { - // return [...oldQueryData, data]; - return oldQueryData.filter((CS) => CS.id_connection_strategy!==data.id_connection_strategy) + return oldQueryData.filter((CS) => CS.id_connection_strategy !== data.id_connection_strategy) }); toast("Connection Strategy has been deleted !", { description: "", @@ -77,4 +65,4 @@ const useDeleteConnectionStrategyMutation = () => { }); }; -export default useDeleteConnectionStrategyMutation; +export default useDeleteConnectionStrategy; diff --git a/apps/client-ts/src/hooks/delete/useDeleteWebhook.tsx b/apps/client-ts/src/hooks/delete/useDeleteWebhook.tsx new file mode 100644 index 000000000..a33c643c5 --- /dev/null +++ b/apps/client-ts/src/hooks/delete/useDeleteWebhook.tsx @@ -0,0 +1,65 @@ +import config from '@/lib/config'; +import { useMutation, useQueryClient } from '@tanstack/react-query'; +import { toast } from "sonner" +import { webhook_endpoints as Webhook } from 'api'; +import Cookies from 'js-cookie'; + +interface IWebhookDto { + id_webhook: string; +} + +const useDeleteWebhook = () => { + const queryClient = useQueryClient(); + + const remove = async (webhookData: IWebhookDto) => { + const response = await fetch(`${config.API_URL}/webhook/${webhookData.id_webhook}`, { + method: 'DELETE', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${Cookies.get('access_token')}`, + }, + }); + + if (!response.ok) { + throw new Error('Failed to delete api key'); + } + return response.json(); + }; + return useMutation({ + mutationFn: remove, + onMutate: () => { + toast("api key is being deleted !", { + description: "", + action: { + label: "Close", + onClick: () => console.log("Close"), + }, + }) + }, + onError: (error) => { + toast("The deleting of api key has failed !", { + description: error as any, + action: { + label: "Close", + onClick: () => console.log("Close"), + }, + }) + }, + onSuccess: (data: Webhook) => { + queryClient.setQueryData(['webhooks'], (oldQueryData = []) => { + return oldQueryData.filter((wh) => wh.id_webhook_endpoint !== data.id_webhook_endpoint); + }); + toast("Api Key has been deleted successfully!", { + description: "The api key has been removed from your list.", + action: { + label: "Close", + onClick: () => console.log("Close"), + }, + }); + }, + onSettled: () => { + }, + }); +}; + +export default useDeleteWebhook; diff --git a/apps/client-ts/src/hooks/useApiKeys.tsx b/apps/client-ts/src/hooks/get/useApiKeys.tsx similarity index 100% rename from apps/client-ts/src/hooks/useApiKeys.tsx rename to apps/client-ts/src/hooks/get/useApiKeys.tsx diff --git a/apps/client-ts/src/hooks/useConnectionStrategies.tsx b/apps/client-ts/src/hooks/get/useConnectionStrategies.tsx similarity index 100% rename from apps/client-ts/src/hooks/useConnectionStrategies.tsx rename to apps/client-ts/src/hooks/get/useConnectionStrategies.tsx diff --git a/apps/client-ts/src/hooks/mutations/useConnectionStrategyAuthCredentials.tsx b/apps/client-ts/src/hooks/get/useConnectionStrategyAuthCredentials.tsx similarity index 73% rename from apps/client-ts/src/hooks/mutations/useConnectionStrategyAuthCredentials.tsx rename to apps/client-ts/src/hooks/get/useConnectionStrategyAuthCredentials.tsx index 5af11a757..31a0190ab 100644 --- a/apps/client-ts/src/hooks/mutations/useConnectionStrategyAuthCredentials.tsx +++ b/apps/client-ts/src/hooks/get/useConnectionStrategyAuthCredentials.tsx @@ -3,17 +3,12 @@ import { useMutation, useQueryClient } from '@tanstack/react-query'; import { toast } from "sonner" import Cookies from 'js-cookie'; -interface IFetchedData { - authValues:string[] - } - interface IGetCSCredentialsData { - type?:string, - attributes:string[] - } - + type?:string, + attributes:string[] +} -const useConnectionStrategyAuthCredentialsMutation = () => { +const useConnectionStrategyAuthCredentials = () => { const getCSCredentials = async (data : IGetCSCredentialsData): Promise => { const response = await fetch(`${config.API_URL}/connections-strategies/credentials`,{ method: 'POST', @@ -41,14 +36,11 @@ const useConnectionStrategyAuthCredentialsMutation = () => { }) }, onSuccess: (data) => { - // queryClient.setQueryData(['connection-strategies'], (oldQueryData = []) => { - // return [...oldQueryData, data]; - // }); - return data + return data }, onSettled: () => { }, }); }; -export default useConnectionStrategyAuthCredentialsMutation; +export default useConnectionStrategyAuthCredentials; diff --git a/apps/client-ts/src/hooks/useConnections.tsx b/apps/client-ts/src/hooks/get/useConnections.tsx similarity index 100% rename from apps/client-ts/src/hooks/useConnections.tsx rename to apps/client-ts/src/hooks/get/useConnections.tsx diff --git a/apps/client-ts/src/hooks/useEvents.tsx b/apps/client-ts/src/hooks/get/useEvents.tsx similarity index 100% rename from apps/client-ts/src/hooks/useEvents.tsx rename to apps/client-ts/src/hooks/get/useEvents.tsx diff --git a/apps/client-ts/src/hooks/useEventsCount.tsx b/apps/client-ts/src/hooks/get/useEventsCount.tsx similarity index 100% rename from apps/client-ts/src/hooks/useEventsCount.tsx rename to apps/client-ts/src/hooks/get/useEventsCount.tsx diff --git a/apps/client-ts/src/hooks/get/useFieldMappings.tsx b/apps/client-ts/src/hooks/get/useFieldMappings.tsx new file mode 100644 index 000000000..d6cb88f54 --- /dev/null +++ b/apps/client-ts/src/hooks/get/useFieldMappings.tsx @@ -0,0 +1,26 @@ +import config from '@/lib/config'; +import { useQuery } from '@tanstack/react-query'; +import { attribute as Attribute } from 'api'; +import Cookies from 'js-cookie'; + +const useFieldMappings = () => { + return useQuery({ + queryKey: ['mappings'], + queryFn: async (): Promise => { + const response = await fetch(`${config.API_URL}/field-mappings/attribute`, + { + method: 'GET', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `Bearer ${Cookies.get('access_token')}`, + }, + }); + if (!response.ok) { + throw new Error('Network response was not ok'); + } + return response.json(); + }}); + +}; + +export default useFieldMappings; diff --git a/apps/client-ts/src/hooks/useLinkedUsers.tsx b/apps/client-ts/src/hooks/get/useLinkedUsers.tsx similarity index 100% rename from apps/client-ts/src/hooks/useLinkedUsers.tsx rename to apps/client-ts/src/hooks/get/useLinkedUsers.tsx diff --git a/apps/client-ts/src/hooks/useProjects.tsx b/apps/client-ts/src/hooks/get/useProjects.tsx similarity index 100% rename from apps/client-ts/src/hooks/useProjects.tsx rename to apps/client-ts/src/hooks/get/useProjects.tsx diff --git a/apps/client-ts/src/hooks/useProviderProperties.tsx b/apps/client-ts/src/hooks/get/useProviderProperties.tsx similarity index 100% rename from apps/client-ts/src/hooks/useProviderProperties.tsx rename to apps/client-ts/src/hooks/get/useProviderProperties.tsx diff --git a/apps/client-ts/src/hooks/useQueryPagination.tsx b/apps/client-ts/src/hooks/get/useQueryPagination.tsx similarity index 100% rename from apps/client-ts/src/hooks/useQueryPagination.tsx rename to apps/client-ts/src/hooks/get/useQueryPagination.tsx diff --git a/apps/client-ts/src/hooks/mutations/useFetchUserMutation.tsx b/apps/client-ts/src/hooks/get/useUser.tsx similarity index 83% rename from apps/client-ts/src/hooks/mutations/useFetchUserMutation.tsx rename to apps/client-ts/src/hooks/get/useUser.tsx index 51a5ac22b..352dffcf2 100644 --- a/apps/client-ts/src/hooks/mutations/useFetchUserMutation.tsx +++ b/apps/client-ts/src/hooks/get/useUser.tsx @@ -2,7 +2,6 @@ import config from '@/lib/config'; import { useMutation, useQueryClient } from '@tanstack/react-query'; import { toast } from "sonner" import useProfileStore from '@/state/profileStore'; -import { projects as Project } from 'api'; import Cookies from 'js-cookie'; @@ -12,14 +11,12 @@ type IUserDto = { first_name: string; last_name: string; id_organization?: string; - } - - -const useFetchUserMutation = () => { +} +const useUser = () => { const {setProfile} = useProfileStore() - const verifyUser = async (cookie : string | undefined) => { + const getUser = async (cookie : string | undefined) => { // Fetch the token const response = await fetch(`${config.API_URL}/auth/profile`, { method: 'GET', @@ -37,7 +34,7 @@ const useFetchUserMutation = () => { return response.json(); }; return useMutation({ - mutationFn: verifyUser, + mutationFn: getUser, onMutate: () => { // toast("Fetching the user !", { // description: "", @@ -58,11 +55,7 @@ const useFetchUserMutation = () => { }) }, onSuccess: (data : IUserDto) => { - setProfile(data); - // Cookies.set('access_token',data.access_token,{expires:1}); - // console.log("Bearer Token in client Side : ",data.access_token); - toast.success("User has been fetched !", { description: "", action: { @@ -76,4 +69,4 @@ const useFetchUserMutation = () => { }); }; -export default useFetchUserMutation; +export default useUser; diff --git a/apps/client-ts/src/hooks/useWebhooks.tsx b/apps/client-ts/src/hooks/get/useWebhooks.tsx similarity index 100% rename from apps/client-ts/src/hooks/useWebhooks.tsx rename to apps/client-ts/src/hooks/get/useWebhooks.tsx diff --git a/apps/client-ts/src/hooks/mutations/useUpdateConnectionStrategy.tsx b/apps/client-ts/src/hooks/update/useUpdateConnectionStrategy.tsx similarity index 84% rename from apps/client-ts/src/hooks/mutations/useUpdateConnectionStrategy.tsx rename to apps/client-ts/src/hooks/update/useUpdateConnectionStrategy.tsx index f0012fcf7..15c6b3a9f 100644 --- a/apps/client-ts/src/hooks/mutations/useUpdateConnectionStrategy.tsx +++ b/apps/client-ts/src/hooks/update/useUpdateConnectionStrategy.tsx @@ -15,13 +15,11 @@ interface IUpdateConnectionStrategyDto { } -const useUpdateConnectionStrategyMutation = () => { +const useUpdateWebhook = () => { const queryClient = useQueryClient(); - const addConnectionStrategy = async (connectionStrategyData: IUpdateConnectionStrategyDto) => { - - if(connectionStrategyData.updateToggle) - { + const update = async (connectionStrategyData: IUpdateConnectionStrategyDto) => { + if(connectionStrategyData.updateToggle) { console.log(connectionStrategyData.id_cs) const response = await fetch(`${config.API_URL}/connections-strategies/toggle`, { method: 'POST', @@ -35,12 +33,8 @@ const useUpdateConnectionStrategyMutation = () => { if (!response.ok) { throw new Error('Failed to toggle cs'); } - return response.json(); - - } - else - { + } else { const response = await fetch(`${config.API_URL}/connections-strategies/update`, { method: 'POST', body: JSON.stringify({ @@ -60,18 +54,11 @@ const useUpdateConnectionStrategyMutation = () => { } return response.json(); - } - - - - // console.log(response.status) - - }; return useMutation({ - mutationFn: addConnectionStrategy, + mutationFn: update, onMutate: () => { toast("Connection Strategy is being updated !", { description: "", @@ -92,8 +79,7 @@ const useUpdateConnectionStrategyMutation = () => { }, onSuccess: (data : ConnectionStrategies) => { queryClient.setQueryData(['connection-strategies'], (oldQueryData = []) => { - // return [...oldQueryData, data]; - return oldQueryData.map((CS) => CS.id_connection_strategy===data.id_connection_strategy ? data : CS) + return oldQueryData.map((CS) => CS.id_connection_strategy === data.id_connection_strategy ? data : CS) }); toast("Connection Strategy has been updated !", { description: "", @@ -108,4 +94,4 @@ const useUpdateConnectionStrategyMutation = () => { }); }; -export default useUpdateConnectionStrategyMutation; +export default useUpdateWebhook; diff --git a/apps/client-ts/src/hooks/mutations/useWebhookUpdate.tsx b/apps/client-ts/src/hooks/update/useUpdateWebhookStatus.tsx similarity index 83% rename from apps/client-ts/src/hooks/mutations/useWebhookUpdate.tsx rename to apps/client-ts/src/hooks/update/useUpdateWebhookStatus.tsx index df3d9eaa6..d6cafebbc 100644 --- a/apps/client-ts/src/hooks/mutations/useWebhookUpdate.tsx +++ b/apps/client-ts/src/hooks/update/useUpdateWebhookStatus.tsx @@ -7,8 +7,8 @@ interface IWebhookUpdateDto { id: string; active: boolean; } -const useWebhookStatusMutation = () => { - const updateStatusWebhookEndpoint = async (data: IWebhookUpdateDto) => { +const useUpdateWebhookStatus = () => { + const update = async (data: IWebhookUpdateDto) => { const response = await fetch(`${config.API_URL}/webhook/${data.id}`, { method: 'PUT', body: JSON.stringify({active: data.active}), @@ -25,7 +25,7 @@ const useWebhookStatusMutation = () => { return response.json(); }; return useMutation({ - mutationFn: updateStatusWebhookEndpoint, + mutationFn: update, onError: (error) => { toast("Webhook endpoint update has failed !", { description: error as any, @@ -38,4 +38,4 @@ const useWebhookStatusMutation = () => { }); }; -export default useWebhookStatusMutation; +export default useUpdateWebhookStatus; diff --git a/apps/client-ts/src/hooks/useFieldMappings.tsx b/apps/client-ts/src/hooks/useFieldMappings.tsx deleted file mode 100644 index b9145809e..000000000 --- a/apps/client-ts/src/hooks/useFieldMappings.tsx +++ /dev/null @@ -1,24 +0,0 @@ -import config from '@/lib/config'; -import { useQuery } from '@tanstack/react-query'; -import { attribute as Attribute } from 'api'; -import Cookies from 'js-cookie'; - -const useFieldMappings = () => { - return useQuery({queryKey: ['mappings'], queryFn: async (): Promise => { - const response = await fetch(`${config.API_URL}/field-mappings/attribute`, - { - method: 'GET', - headers: { - 'Content-Type': 'application/json', - 'Authorization': `Bearer ${Cookies.get('access_token')}`, - }, - }); - if (!response.ok) { - throw new Error('Network response was not ok'); - } - return response.json(); - }}); - -}; - -export default useFieldMappings; diff --git a/packages/api/src/@core/auth/auth.controller.ts b/packages/api/src/@core/auth/auth.controller.ts index c432bcab6..25e0c085a 100644 --- a/packages/api/src/@core/auth/auth.controller.ts +++ b/packages/api/src/@core/auth/auth.controller.ts @@ -5,6 +5,8 @@ import { Get, UseGuards, Request, + Delete, + Param, } from '@nestjs/common'; import { CreateUserDto } from './dto/create-user.dto'; import { AuthService } from './auth.service'; @@ -65,6 +67,14 @@ export class AuthController { return this.authService.getApiKeys(id_project); } + @ApiOperation({ operationId: 'deleteApiKey', summary: 'Delete API Keys' }) + @ApiResponse({ status: 201 }) + @Delete('api-keys/:id') + @UseGuards(JwtAuthGuard) + async deleteApiKey(@Param('id') apiKeyId: string) { + return await this.authService.deleteApiKey(apiKeyId); + } + @ApiOperation({ operationId: 'generateApiKey', summary: 'Create API Key' }) @ApiBody({ type: ApiKeyDto }) @ApiResponse({ status: 201 }) diff --git a/packages/api/src/@core/auth/auth.service.ts b/packages/api/src/@core/auth/auth.service.ts index f238941c6..47906ea6a 100644 --- a/packages/api/src/@core/auth/auth.service.ts +++ b/packages/api/src/@core/auth/auth.service.ts @@ -106,12 +106,11 @@ export class AuthService { const proj = await this.prisma.projects.create({ data: { id_project: uuidv4(), - name: "Project 1", - sync_mode: "", - id_user: user_.id_user - } - }) - this.logger.log("Proj data after registr is "+ JSON.stringify(proj)) + name: 'Project 1', + sync_mode: '', + id_user: user_.id_user, + }, + }); return user_; } catch (error) { console.log(error); @@ -132,7 +131,7 @@ export class AuthService { id_user: foundUser.id_user, }, }); - this.logger.log("Project found (login) is "+ JSON.stringify(project)) + this.logger.log('Project found (login) is ' + JSON.stringify(project)); if (!foundUser) { throw new UnauthorizedException('user does not exist!'); @@ -270,6 +269,14 @@ export class AuthService { } } + async deleteApiKey(apiKeyId: string) { + return await this.prisma.api_keys.delete({ + where: { + id_api_key: apiKeyId, + }, + }); + } + async validateApiKey(apiKey: string): Promise { try { // Decode the JWT to verify if it's valid and get the payload diff --git a/packages/api/src/@core/webhook/webhook.controller.ts b/packages/api/src/@core/webhook/webhook.controller.ts index e69098116..175ea5c06 100644 --- a/packages/api/src/@core/webhook/webhook.controller.ts +++ b/packages/api/src/@core/webhook/webhook.controller.ts @@ -7,6 +7,7 @@ import { Param, UseGuards, Request, + Delete, } from '@nestjs/common'; import { LoggerService } from '@@core/logger/logger.service'; import { ApiBody, ApiResponse, ApiTags, ApiOperation } from '@nestjs/swagger'; @@ -36,6 +37,14 @@ export class WebhookController { return this.webhookService.getWebhookEndpoints(id_project); } + @ApiOperation({ operationId: 'deleteWebhook', summary: 'Delete Webhook' }) + @ApiResponse({ status: 201 }) + @Delete(':id') + @UseGuards(JwtAuthGuard) + async deleteWebhook(@Param('id') whId: string) { + return await this.webhookService.deleteWebhook(whId); + } + @ApiOperation({ operationId: 'updateWebhookStatus', summary: 'Update webhook status', diff --git a/packages/api/src/@core/webhook/webhook.service.ts b/packages/api/src/@core/webhook/webhook.service.ts index c6d189f13..3404157f8 100644 --- a/packages/api/src/@core/webhook/webhook.service.ts +++ b/packages/api/src/@core/webhook/webhook.service.ts @@ -67,6 +67,14 @@ export class WebhookService { } } + async deleteWebhook(whId: string) { + return await this.prisma.webhook_endpoints.delete({ + where: { + id_webhook_endpoint: whId, + }, + }); + } + async handleWebhook( data: any, eventType: string, diff --git a/packages/api/swagger/swagger-spec.json b/packages/api/swagger/swagger-spec.json index dc902ba47..346277443 100644 --- a/packages/api/swagger/swagger-spec.json +++ b/packages/api/swagger/swagger-spec.json @@ -162,6 +162,33 @@ ] } }, + "/auth/api-keys/{id}": { + "delete": { + "operationId": "deleteApiKey", + "summary": "Delete API Keys", + "parameters": [ + { + "name": "id", + "required": true, + "in": "path", + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "" + }, + "201": { + "description": "" + } + }, + "tags": [ + "auth" + ] + } + }, "/auth/generate-apikey": { "post": { "operationId": "generateApiKey", @@ -377,6 +404,31 @@ } }, "/webhook/{id}": { + "delete": { + "operationId": "deleteWebhook", + "summary": "Delete Webhook", + "parameters": [ + { + "name": "id", + "required": true, + "in": "path", + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "" + }, + "201": { + "description": "" + } + }, + "tags": [ + "webhook" + ] + }, "put": { "operationId": "updateWebhookStatus", "summary": "Update webhook status",