Files
supabase/apps/studio/components/interfaces/Support/AIAssistantOption.tsx
Joshen Lim 6b7c8116f3 Chore/projects pagination part 05 (#39350)
* CmdK OrgProjectSwitcher to swap useProjectsQuery with useProjectsInfiniteQuery

* Remove usage of useProjectsQuery in ProjectDropdown

* Remove usage of useProjectsQuery in NotificationsPopover

* Remove usage of useProjectsQuery in NotificationsFilter

* Remove usage of useProjectsQuery from LoadingState

* Clean

* Remove usage of getProjects from org-ai-details and fix missing key props in AIOnboarding

* Remove useAutoProjectsPrefetch from org/[slug]/index

* Fix TS  + clean up

* Clean

* Remove usage of useProjectsQuery in NewOrgForm

* Remove usage of useProjectsQuery in SupportForm -> AIAssistantOption

* Remove usage of useProjectsQuery in PlanUpdateSidePanel

* Remove usage of useProjectsQuery in NoProjectsOnPaidPlan

* Remove useProjectsQuery in IntegrationPanels

* Remove useProjectsQuery from IntegrationPanels 2

* Remove useProjectsQuery from IntegrationConnection

* Remove console log

* Small change
2025-10-09 12:26:54 +08:00

101 lines
3.9 KiB
TypeScript

import { AnimatePresence, motion } from 'framer-motion'
import { MessageSquare } from 'lucide-react'
import Link from 'next/link'
import { useCallback, useEffect, useState } from 'react'
import { useSendEventMutation } from 'data/telemetry/send-event-mutation'
import { Button } from 'ui'
interface AIAssistantOptionProps {
projectRef: string
organizationSlug: string
isCondensed?: boolean
}
export const AIAssistantOption = ({
projectRef,
organizationSlug,
isCondensed = false,
}: AIAssistantOptionProps) => {
const { mutate: sendEvent } = useSendEventMutation()
const [isVisible, setIsVisible] = useState(isCondensed ? true : false)
useEffect(() => {
const timer = setTimeout(() => setIsVisible(true), 800)
return () => clearTimeout(timer)
}, [])
const onAiAssistantClicked = useCallback(() => {
sendEvent({
action: 'ai_assistant_in_support_form_clicked',
groups: {
project: projectRef === 'no-project' ? undefined : projectRef,
organization: organizationSlug,
},
})
}, [projectRef, organizationSlug, sendEvent])
if (!organizationSlug || organizationSlug === 'no-org') {
return null
}
// If no specific project selected, use the wildcard route
const aiLink = `/project/${projectRef !== 'no-project' ? projectRef : '_'}?aiAssistantPanelOpen=true&slug=${organizationSlug}`
return (
<AnimatePresence initial={false}>
{isVisible && (
<motion.div
initial={{ height: 0, opacity: 0 }}
animate={{ height: 'auto', opacity: 1 }}
exit={{ height: 0, opacity: 0 }}
className="w-full overflow-hidden border rounded-md relative"
>
<div className={`flex flex-col xl:flex-row ${isCondensed ? 'py-4 px-5' : 'py-8 px-10'}`}>
<div className="flex flex-col gap-3 z-[2] flex-shrink-0 w-full">
<div>
<p className="text-sm text-foreground">Try the AI Assistant</p>
<p className="text-sm text-foreground-lighter">
Ask the AI assistant to help you with your support issue
</p>
</div>
<div>
<Link href={aiLink} onClick={onAiAssistantClicked}>
<Button size="tiny" type="default">
Ask AI assistant
</Button>
</Link>
</div>
</div>
{!isCondensed && (
<div className="absolute z-[1] scale-75 -right-24 top-0">
<div className="relative grow flex flex-col gap-3 w-[400px]">
<div className="flex items-start gap-3 pl-12">
<div className="w-8 h-8 rounded-full bg-background-surface-300 flex items-center justify-center">
<MessageSquare size={16} className="text-foreground-lighter" />
</div>
<div className="flex-1 bg-background-surface-200 rounded-lg p-4 max-w-[280px]">
<p className="text-sm text-foreground-lighter">
Hi! I'm your AI assistant. How can I help you today?
</p>
</div>
</div>
<div className="flex items-start justify-end gap-3 pr-10">
<div className="bg-background-surface-200 rounded-lg p-4 max-w-[280px]">
<p className="text-sm text-foreground-lighter">
I can help you with database queries, API endpoints, or any other technical
questions you might have.
</p>
</div>
</div>
</div>
<div className="absolute -inset-2 bg-gradient-to-l from-transparent via-background-200 via-[95%] to-background-200 to-[100%] z-[1]" />
</div>
)}
</div>
</motion.div>
)}
</AnimatePresence>
)
}