Skip to content

Commit

Permalink
Merge pull request #11 from anoopkarnik/main
Browse files Browse the repository at this point in the history
Corrected docker container ... redirect
  • Loading branch information
anoopkarnik authored Sep 3, 2024
2 parents dd3e102 + 61e8e8f commit fdc8ca6
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 27 deletions.
6 changes: 0 additions & 6 deletions apps/dashboard-app/app/(dashboard)/connections/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import Connections from './_components/Connections'
import { useSession } from 'next-auth/react';
import { getUserInfo } from '../../actions/connections/user-connections';
import { onNotionConnection } from '../../actions/connections/notion-connections';
import { onOpenAIConnection } from '../../actions/connections/openai-connections';
import { onYoutubeConnection } from '../../actions/connections/youtube-connections';
import { useToast } from '../../../hooks/useToast';

Expand Down Expand Up @@ -49,10 +48,6 @@ const PlannerPage = () => {
response = await onNotionConnection({access_token,workspace_id,workspace_icon,workspace_name,database_id,userId})
connectionsContext.setNotionNode(response.result)
}
if (type === 'OpenAI'){
response = await onOpenAIConnection({apiKey,userId})
connectionsContext.setOpenAINode(response.result)
}
if (type === 'Youtube'){
response = await onYoutubeConnection({access_token,refresh_token,scopes,userId})
}
Expand Down Expand Up @@ -127,7 +122,6 @@ const PlannerPage = () => {
<TabsContent value='Connections'>
<Connections/>
</TabsContent>

</Tabs>
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { createConnection, getConnectionByAPIKey, getConnectionsByUserAndType } from '@repo/prisma-db/repo/connection'


export const onOpenAIConnection = async ({apiKey,userId}:any) => {
export const createOpenAIConnection = async ({apiKey,userId}:any) => {
if(!apiKey) return {error: "API Key not present in the query"}
const openai_connected = await getConnectionByAPIKey(apiKey)
if (openai_connected) return {success: "OpenAI Connection already exists"}
Expand Down
27 changes: 22 additions & 5 deletions apps/dashboard-app/components/AddConnectionModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,42 @@ import { FormControl, FormField, FormItem, FormLabel } from '@repo/ui/molecules/
import { Input } from '@repo/ui/atoms/shadcn/Input'
import { Button } from '@repo/ui/atoms/shadcn/Button'
import { useRouter } from 'next/navigation';
import { useToast } from '../hooks/useToast';


type Props = {
callback_url: string
addConnection: any,
formElements: {
name: string
label: string
placeholder: string
type: string
}[]
}[],
userId: string | undefined
}

const AddConnectionsModal = ({callback_url,formElements}:Props) => {
const AddConnectionsModal = ({addConnection,formElements,userId}:Props) => {
const form = useForm()
const router = useRouter();
const {toast} = useToast();

const onSubmit = (data:any) => {
const apiKey = data.apiKey; // Assuming apiKey is a form field
const redirectUrl = `${callback_url}?apiKey=${apiKey}`;
router.push(redirectUrl);
const response = addConnection({userId,apiKey});
if (response?.success){
toast({
title: "Success",
description: response?.success,
variant: "default"
})
}
else if (response?.error){
toast({
title: "Error",
description: response?.error,
variant: "destructive"
})
}
}

return (
Expand Down
45 changes: 30 additions & 15 deletions apps/dashboard-app/components/ConnectionCard.tsx
Original file line number Diff line number Diff line change
@@ -1,29 +1,40 @@
import React, { use, useEffect, useState } from 'react'
'use client'
import React, { useEffect, useState } from 'react'

import { set } from 'date-fns'
import { Card, CardDescription, CardHeader, CardTitle } from '@repo/ui/molecules/shadcn/Card'
import Image from 'next/image'
import Link from 'next/link'
import { Button } from '@repo/ui/atoms/shadcn/Button'

import { Dialog,DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from '@repo/ui/molecules/shadcn/Dialog'
import AddConnectionsModal from './AddConnectionModal'
import { useSession } from 'next-auth/react'
import { createOpenAIConnection } from '../app/actions/connections/openai-connections'
import { useRouter } from 'next/navigation'


const ConnectionCard = ({connection}:any) => {

const [appType, setAppType] = useState(connection.title)
const [callbackUrl, setCallbackUrl] = useState('')
const [oauthUrl, setOauthUrl] = useState('')
const [oauthUrl, setOauthUrl] = useState('')
const session = useSession();
const user = session?.data?.user
const router = useRouter()

useEffect(() => {
setAppType(connection.title)
const addConnection = async ({apiKey}:any) => {
if (connection.title === 'OpenAI'){
setCallbackUrl(process.env.NEXT_PUBLIC_URL+'/api/callback/openai')
setOauthUrl('')
const response = await createOpenAIConnection({apiKey,userId:user?.id})
location.reload()
}
else if (connection.title === 'Notion'){
setCallbackUrl('')
router.push('/connections/notion')
}
}

useEffect(() => {
setAppType(connection.title)
if (connection.title === 'Notion'){
setOauthUrl(process.env.NEXT_PUBLIC_NOTION_OAUTH_URL as string)
}
else if (connection.title === 'Youtube'){
Expand All @@ -32,6 +43,12 @@ const ConnectionCard = ({connection}:any) => {
}
},[connection.title])

const handleConnect = () => {
if (oauthUrl) {
router.push(oauthUrl)
}
}

return (
<Card className="flex flex-col items-center justify-between ">
<CardHeader className="flex flex-col items-center justify-center gap-2">
Expand Down Expand Up @@ -59,16 +76,14 @@ const ConnectionCard = ({connection}:any) => {
</DialogTitle>
<DialogDescription className='py-4 '>{connection.description}</DialogDescription>
</DialogHeader>
<AddConnectionsModal formElements={connection.formElements || []} callback_url={callbackUrl}/>
<AddConnectionsModal formElements={connection.formElements || []} addConnection={addConnection} userId={user?.id}/>
</DialogContent>
</Dialog>
):(
<div className=''>
<Link href={oauthUrl || ''}>
<Button size="lg" >
Connect
</Button>
</Link>
<div className=''>
<Button size="lg" onClick={handleConnect}>
Connect
</Button>
</div>)}
</div>}
{!connection.published &&
Expand Down

0 comments on commit fdc8ca6

Please sign in to comment.