import { Code, Table2 } from 'lucide-react' import { useRouter } from 'next/router' import { useCallback, useMemo, useState } from 'react' import { useParams } from 'common' import { FRAMEWORKS } from 'components/interfaces/Connect/Connect.constants' import { useSendEventMutation } from 'data/telemetry/send-event-mutation' import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization' import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject' import { BASE_PATH } from 'lib/constants' import { useAiAssistantStateSnapshot } from 'state/ai-assistant-state' import { Button, Card, CardContent, ToggleGroup, ToggleGroupItem } from 'ui' import { FrameworkSelector } from './FrameworkSelector' import { GettingStarted } from './GettingStarted' import { GettingStartedAction, GettingStartedState, GettingStartedStep, } from './GettingStarted.types' import { DEFAULT_FRAMEWORK_KEY, getCodeWorkflowSteps, getNoCodeWorkflowSteps, } from './GettingStarted.utils' import { useGettingStartedProgress } from './useGettingStartedProgress' interface GettingStartedSectionProps { value: GettingStartedState onChange: (v: GettingStartedState) => void } export function GettingStartedSection({ value, onChange }: GettingStartedSectionProps) { const router = useRouter() const { ref } = useParams() const { data: project } = useSelectedProjectQuery() const { data: organization } = useSelectedOrganizationQuery() const { mutate: sendEvent } = useSendEventMutation() const aiSnap = useAiAssistantStateSnapshot() const [selectedFramework, setSelectedFramework] = useState(DEFAULT_FRAMEWORK_KEY) const workflow: 'no-code' | 'code' | null = value === 'code' || value === 'no-code' ? value : null const [previousWorkflow, setPreviousWorkflow] = useState<'no-code' | 'code' | null>(null) const statuses = useGettingStartedProgress() const openAiChat = useCallback( (name: string, initialInput: string) => aiSnap.newChat({ name, open: true, initialInput }), [aiSnap] ) const openConnect = useCallback(() => { router.push( { pathname: router.pathname, query: { ...router.query, showConnect: true, connectTab: 'frameworks', framework: selectedFramework, }, }, undefined, { shallow: true } ) }, [router, selectedFramework]) const connectActions: GettingStartedAction[] = useMemo( () => [ { label: 'Framework selector', component: ( ), }, { label: 'Connect', variant: 'primary', onClick: openConnect, }, ], [openConnect, selectedFramework] ) const codeSteps: GettingStartedStep[] = useMemo( () => getCodeWorkflowSteps({ ref, openAiChat, connectActions, statuses, }), [connectActions, openAiChat, ref, statuses] ) const noCodeSteps: GettingStartedStep[] = useMemo( () => getNoCodeWorkflowSteps({ ref, openAiChat, connectActions, statuses, }), [connectActions, openAiChat, ref, statuses] ) const steps = workflow === 'code' ? codeSteps : workflow === 'no-code' ? noCodeSteps : [] return (

Getting started

{ if (v) { const newWorkflow = v as 'no-code' | 'code' setPreviousWorkflow(workflow) onChange(newWorkflow) sendEvent({ action: 'home_getting_started_workflow_clicked', properties: { workflow: newWorkflow === 'no-code' ? 'no_code' : 'code', is_switch: previousWorkflow !== null, }, groups: { project: project?.ref || '', organization: organization?.slug || '', }, }) } }} > No-code Code
{steps.length === 0 ? (
Supabase Grafana Supabase Grafana

Choose a preferred workflow

With Supabase, you have the flexibility to adopt a workflow that works for you. You can do everything via the dashboard, or manage your entire project within your own codebase.

) : ( { if (workflow) { sendEvent({ action: 'home_getting_started_step_clicked', properties: { workflow: workflow === 'no-code' ? 'no_code' : 'code', step_number: stepIndex + 1, step_title: stepTitle, action_type: actionType, was_completed: wasCompleted, }, groups: { project: project?.ref || '', organization: organization?.slug || '', }, }) } }} /> )}
) }