From 6393e9fa755f8bbc244773499e0639a20efb5581 Mon Sep 17 00:00:00 2001 From: NasSharaf Date: Mon, 22 Sep 2025 23:32:25 -0400 Subject: [PATCH] removed useOnboarding hook and used store.ts instead, modified all dependencies accordingly --- .../src/components/onboarding/Onboarding.tsx | 2 +- .../onboarding/OnboardingDialog.tsx | 243 +++++++++++++----- .../onboarding/OnboardingSidebar.tsx | 85 ++++-- .../configure-step/disable_configure-step.tsx | 68 ----- .../onboarding/connect-step/connect-step.tsx | 12 +- .../connect-step/disabled_connect-step.tsx | 156 ----------- .../connect-step/repository-list.tsx | 68 +++-- .../onboarding/connect-step/template-list.tsx | 27 +- .../onboarding/deploy-step/deploy-step.tsx | 17 +- .../deploy-step/disabled_deploy-step.tsx | 42 --- .../src/components/onboarding/store.ts | 78 ++++-- .../onboarding/success-step/success-step.tsx | 4 +- .../components/onboarding/useOnboarding.ts | 120 --------- 13 files changed, 380 insertions(+), 542 deletions(-) delete mode 100644 apps/deploy-fe/src/components/onboarding/configure-step/disable_configure-step.tsx delete mode 100644 apps/deploy-fe/src/components/onboarding/connect-step/disabled_connect-step.tsx delete mode 100644 apps/deploy-fe/src/components/onboarding/deploy-step/disabled_deploy-step.tsx delete mode 100644 apps/deploy-fe/src/components/onboarding/useOnboarding.ts diff --git a/apps/deploy-fe/src/components/onboarding/Onboarding.tsx b/apps/deploy-fe/src/components/onboarding/Onboarding.tsx index c7af0e5..089face 100644 --- a/apps/deploy-fe/src/components/onboarding/Onboarding.tsx +++ b/apps/deploy-fe/src/components/onboarding/Onboarding.tsx @@ -10,7 +10,7 @@ import { ConfigureStep } from '@/components/onboarding/configure-step' import { ConnectStep } from '@/components/onboarding/connect-step' import { DeployStep } from '@/components/onboarding/deploy-step' -import { useOnboarding } from '@/components/onboarding/useOnboarding' +import { useOnboarding } from '@/components/onboarding/store' import { ScrollArea } from '@workspace/ui/components/scroll-area' import { SidebarNav } from './sidebar' diff --git a/apps/deploy-fe/src/components/onboarding/OnboardingDialog.tsx b/apps/deploy-fe/src/components/onboarding/OnboardingDialog.tsx index 7c5d4e6..f5fe23c 100644 --- a/apps/deploy-fe/src/components/onboarding/OnboardingDialog.tsx +++ b/apps/deploy-fe/src/components/onboarding/OnboardingDialog.tsx @@ -241,16 +241,26 @@ // export default OnboardingDialog 'use client' -import { useState } from 'react' -import { X, Github } from 'lucide-react' -import { Button } from '@workspace/ui/components/button' -import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@workspace/ui/components/select' -import { useOnboarding } from '@/components/onboarding/useOnboarding' import { ScrollableRepoList } from '@/components/onboarding/connect-step/repository-list' import { TemplateList } from '@/components/onboarding/connect-step/template-list' +import { useOnboarding } from '@/components/onboarding/store' import { useRepoData } from '@/hooks/useRepoData' -import { Dialog, DialogContent, DialogTitle } from '@workspace/ui/components/dialog' import { VisuallyHidden } from '@radix-ui/react-visually-hidden' +import { Button } from '@workspace/ui/components/button' +import { + Dialog, + DialogContent, + DialogTitle +} from '@workspace/ui/components/dialog' +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue +} from '@workspace/ui/components/select' +import { Github, X } from 'lucide-react' +import { useState } from 'react' interface OnboardingDialogProps { trigger?: React.ReactNode @@ -269,18 +279,21 @@ const OnboardingDialog: React.FC = ({ defaultOpen = false, onClose }) => { - const { nextStep, setFormData, formData, currentStep, previousStep } = useOnboarding() - const [selectedRepo, setSelectedRepo] = useState(formData.githubRepo || '') + const { nextStep, setFormData, formData, currentStep, previousStep } = + useOnboarding() + const [selectedRepo, setSelectedRepo] = useState( + formData.githubRepo || '' + ) const [isImportMode, setIsImportMode] = useState(true) const [isOpen, setIsOpen] = useState(defaultOpen) const { repoData: repositories, isLoading } = useRepoData('') - + // Handle repository selection const handleRepoSelect = (repo: string) => { setSelectedRepo(repo) setFormData({ githubRepo: repo }) } - + // Handle mode toggle between import and template const toggleMode = (mode: 'import' | 'template') => { setIsImportMode(mode === 'import') @@ -293,7 +306,7 @@ const OnboardingDialog: React.FC = ({ onClose() } } - + return ( {trigger && trigger} @@ -301,25 +314,48 @@ const OnboardingDialog: React.FC = ({ Onboarding - +
{/* Left sidebar with steps */}
{/* Laconic logo */}
- - + + LACONIC
- + {/* Steps */}
{/* Connect step */}
-
- +
+ @@ -327,16 +363,40 @@ const OnboardingDialog: React.FC = ({
-

Connect

-

Connect and import a GitHub repo

+

+ Connect +

+

+ Connect and import a GitHub repo +

- + {/* Configure step */}
-
- +
+ @@ -344,59 +404,110 @@ const OnboardingDialog: React.FC = ({
-

Configure

-

Define the deployment type

+

+ Configure +

+

+ Define the deployment type +

- + {/* Deploy step */}
-
- - +
+ +
-

Deploy

-

Review and confirm deployment

+

+ Deploy +

+

+ Review and confirm deployment +

- + {/* Background shape (decorative) */}
- + {/* Main content */}
{/* Close button */} - - + {currentStep === 'connect' && (
{/* Connect icon */}
- +
- + {/* Connect header */} -

Connect

+

+ Connect +

Connect and import a GitHub repo or start from a template

- + {/* Git account selector */}
- + {/* Mode buttons */}
- + {/* Repository or template list */} {isImportMode ? (
@@ -445,11 +556,11 @@ const OnboardingDialog: React.FC = ({ {}} />
)} - + {/* Navigation buttons */}
-
-
)} - + {currentStep === 'configure' && (
{/* Configure content will go here */}
-

Configure

+

+ Configure +

Define your deployment configuration

- +
Configure step content will be implemented here
- + {/* Navigation buttons */}
-
-
)} - + {currentStep === 'deploy' && (
{/* Deploy content will go here */}
-

Deploy

+

+ Deploy +

Review and confirm your deployment

- +
Deploy step content will be implemented here
- + {/* Navigation buttons */}
-
-
@@ -552,4 +665,4 @@ const OnboardingDialog: React.FC = ({ ) } -export default OnboardingDialog \ No newline at end of file +export default OnboardingDialog diff --git a/apps/deploy-fe/src/components/onboarding/OnboardingSidebar.tsx b/apps/deploy-fe/src/components/onboarding/OnboardingSidebar.tsx index 837e809..184ac6c 100644 --- a/apps/deploy-fe/src/components/onboarding/OnboardingSidebar.tsx +++ b/apps/deploy-fe/src/components/onboarding/OnboardingSidebar.tsx @@ -1,7 +1,7 @@ 'use client' -import { GitBranch, Settings, Box } from 'lucide-react' -import type { Step } from '@/components/onboarding/useOnboarding' +import type { Step } from '@/components/onboarding/types' +import { Box, GitBranch, Settings } from 'lucide-react' interface OnboardingSidebarProps { currentStep: Step @@ -12,58 +12,101 @@ export function OnboardingSidebar({ currentStep }: OnboardingSidebarProps) {
{/* Laconic logo */}
- - + + LACONIC
- + {/* Steps */}
{/* Connect step */}
-
- +
+
-

Connect

-

Connect and import a GitHub repo

+

+ Connect +

+

+ Connect and import a GitHub repo +

- + {/* Configure step */}
-
- +
+
-

Configure

-

Define the deployment type

+

+ Configure +

+

+ Define the deployment type +

- + {/* Deploy step */}
-
- +
+
-

Deploy

-

Review and confirm deployment

+

+ Deploy +

+

+ Review and confirm deployment +

- + {/* Background shape (decorative) */}
) -} \ No newline at end of file +} diff --git a/apps/deploy-fe/src/components/onboarding/configure-step/disable_configure-step.tsx b/apps/deploy-fe/src/components/onboarding/configure-step/disable_configure-step.tsx deleted file mode 100644 index 98566b3..0000000 --- a/apps/deploy-fe/src/components/onboarding/configure-step/disable_configure-step.tsx +++ /dev/null @@ -1,68 +0,0 @@ -import { FileCog } from 'lucide-react' -import { useState } from 'react' -import { useOnboarding } from '../store' - -/** - * Second step in the onboarding flow - * Handles deployment configuration and environment setup - * - * Features: - * - Deployment type selection (auction/LRN) - * - Environment variable configuration - * - Account selection - * - * @component - */ -export function ConfigureStep() { - const { formData, setFormData } = useOnboarding() - const [activeTab, setActiveTab] = useState<'create-auction' | 'deployer-lrn'>( - 'create-auction' - ) - const [environments, setEnvironments] = useState({ - production: false, - preview: false, - development: false - }) - - // const handleEnvironmentChange = (env: keyof typeof environments) => { - // setEnvironments((prev) => ({ - // ...prev, - // [env]: !prev[env], - // })) - // setFormData({ - // environmentVars: { - // ...formData.environmentVars, - // [env]: !environments[env], - // }, - // }) - // } - - return ( -
-
-
-
- {/* Header section with icon and description */} -
- - -
-

- Configure -

-

- Set the deployer LRN for a single deployment or by creating a - deployer auction for multiple deployments -

-
-
- Content sections will be placed here: 1. Deployment type tabs - (auction/LRN) 2. Configuration forms 3. Environment variables 4. - Account selection ...content here/ - {/* */} -
-
-
-
- ) -} diff --git a/apps/deploy-fe/src/components/onboarding/connect-step/connect-step.tsx b/apps/deploy-fe/src/components/onboarding/connect-step/connect-step.tsx index 5e33ce9..c42ad6d 100644 --- a/apps/deploy-fe/src/components/onboarding/connect-step/connect-step.tsx +++ b/apps/deploy-fe/src/components/onboarding/connect-step/connect-step.tsx @@ -73,12 +73,18 @@ export function ConnectStep() { } = useAuthStatus() // Repository data - const { repoData: repositories, isLoading: isLoadingRepos, error: repoError } = useRepoData('') - + const { + repoData: repositories, + isLoading: isLoadingRepos, + error: repoError + } = useRepoData('') + // Debug repository data useEffect(() => { console.log('🔍 ConnectStep: Repository data changed:', { - repositories: repositories ? `Array with ${Array.isArray(repositories) ? repositories.length : 'not array'} items` : 'null', + repositories: repositories + ? `Array with ${Array.isArray(repositories) ? repositories.length : 'not array'} items` + : 'null', isLoadingRepos, repoError, isFullyAuthenticated diff --git a/apps/deploy-fe/src/components/onboarding/connect-step/disabled_connect-step.tsx b/apps/deploy-fe/src/components/onboarding/connect-step/disabled_connect-step.tsx deleted file mode 100644 index 3019ed4..0000000 --- a/apps/deploy-fe/src/components/onboarding/connect-step/disabled_connect-step.tsx +++ /dev/null @@ -1,156 +0,0 @@ -// 'use client' - -// import { Button } from '@workspace/ui/components/button' -// import { useState } from 'react' -// import { useOnboarding } from '../store' - -// type ConnectState = 'initial' | 'repository-select' | 'template-select' - -// /** -// * First step in the onboarding flow -// * Handles GitHub connection and repository selection -// * -// * States: -// * - initial: Shows GitHub connect button -// * - repository-select: Shows list of repositories -// * - template-select: Shows available templates -// * -// * @component -// */ -// export function ConnectStep() { -// const [connectState, setConnectState] = useState('initial') -// const [projectName, setProjectName] = useState('') -// const { setFormData, nextStep } = useOnboarding() - -// const handleConnect = () => { -// setConnectState('repository-select') -// } - -// return ( -//
-// {/* \ */} -// {connectState === 'initial' ? ( -//
-//

-// Connect to GitHub -//

-//

-// Connect your GitHub account to get started -//

-//
-// ) : ( -// // {}} /> -// <>...connect goes here -// )} -//
-// ) -// } - -'use client' -// src/components/onboarding/connect-step/connect-step.tsx -import { useState } from 'react' -import { useRepoData } from '@/hooks/useRepoData' -import { useOnboarding } from '@/components/onboarding/useOnboarding' -import { ScrollableRepoList } from '@/components/onboarding/connect-step/repository-list' -import { TemplateList } from '@/components/onboarding/connect-step/template-list' -import { StepHeader } from '@/components/onboarding/common/step-header' -import { Button } from '@workspace/ui/components/button' -import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@workspace/ui/components/select' -import { GitBranch } from 'lucide-react' - -export const ConnectStep = () => { - const { setFormData, formData, nextStep } = useOnboarding() - const [selectedRepo, setSelectedRepo] = useState(formData.githubRepo || '') - const [isImportMode, setIsImportMode] = useState(true) - const { repoData: repositories, isLoading } = useRepoData('') - - // Handle repository selection - const handleRepoSelect = (repo: string) => { - setSelectedRepo(repo) - setFormData({ githubRepo: repo }) - } - - // Handle mode toggle between import and template - const toggleMode = (mode: 'import' | 'template') => { - setIsImportMode(mode === 'import') - } - - return ( -
-
- {/* Connect icon */} -
-
- -
-
- - {/* Connect header */} - } - /> - - {/* Git account selector */} - - - {/* Mode buttons */} -
- - -
- - {/* Repository list or template list */} - {isImportMode ? ( - - ) : ( - {}} /> - )} - - {/* Navigation buttons */} -
- - -
-
-
- ) -} diff --git a/apps/deploy-fe/src/components/onboarding/connect-step/repository-list.tsx b/apps/deploy-fe/src/components/onboarding/connect-step/repository-list.tsx index f4add3b..e6d7071 100644 --- a/apps/deploy-fe/src/components/onboarding/connect-step/repository-list.tsx +++ b/apps/deploy-fe/src/components/onboarding/connect-step/repository-list.tsx @@ -49,16 +49,16 @@ import { Github } from 'lucide-react' interface Repository { - id: string | number; - full_name: string; - html_url?: string; + id: string | number + full_name: string + html_url?: string } interface ScrollableRepoListProps { - repositories: Repository[]; - isLoading: boolean; - onSelect: (repoFullName: string) => void; - selectedRepo: string; + repositories: Repository[] + isLoading: boolean + onSelect: (repoFullName: string) => void + selectedRepo: string } export function ScrollableRepoList({ @@ -72,14 +72,30 @@ export function ScrollableRepoList({ return (
- - - + + + Loading repositories...
- ); + ) } if (!repositories || repositories.length === 0) { @@ -89,29 +105,31 @@ export function ScrollableRepoList({ No repositories found. Make sure your GitHub account is connected.
- ); + ) } // Generate mock repositories if needed for testing - const repoList = repositories.length > 0 ? repositories : - Array.from({ length: 15 }, (_, i) => ({ - id: `mock-${i}`, - full_name: `git-account/repo-name-${i + 1}` - })); + const repoList = + repositories.length > 0 + ? repositories + : Array.from({ length: 15 }, (_, i) => ({ + id: `mock-${i}`, + full_name: `git-account/repo-name-${i + 1}` + })) return (
{/* Ensure we have a fixed height container with scrolling */} -
{repoList.map((repo, index) => ( -
{repo.full_name}
-
- 5 minutes ago -
+
5 minutes ago
))}
- ); -} \ No newline at end of file + ) +} diff --git a/apps/deploy-fe/src/components/onboarding/connect-step/template-list.tsx b/apps/deploy-fe/src/components/onboarding/connect-step/template-list.tsx index 0c8eb4b..8a9f36f 100644 --- a/apps/deploy-fe/src/components/onboarding/connect-step/template-list.tsx +++ b/apps/deploy-fe/src/components/onboarding/connect-step/template-list.tsx @@ -66,18 +66,21 @@ import { Box, Layout } from 'lucide-react' interface Template { - id: string; - name: string; - description: string; - icon: React.ReactNode; + id: string + name: string + description: string + icon: React.ReactNode } interface TemplateListProps { - onSelect: (templateId: string) => void; - selectedTemplate?: string; + onSelect: (templateId: string) => void + selectedTemplate?: string } -export const TemplateList = ({ onSelect, selectedTemplate }: TemplateListProps) => { +export const TemplateList = ({ + onSelect, + selectedTemplate +}: TemplateListProps) => { // Mock templates data - in a real app, this would come from an API const templates: Template[] = [ { @@ -98,7 +101,7 @@ export const TemplateList = ({ onSelect, selectedTemplate }: TemplateListProps) description: 'Simple static site with HTML, CSS, and JavaScript', icon: } - ]; + ] return (
@@ -116,11 +119,13 @@ export const TemplateList = ({ onSelect, selectedTemplate }: TemplateListProps)
{template.name}
-
{template.description}
+
+ {template.description} +
))}
- ); -}; \ No newline at end of file + ) +} diff --git a/apps/deploy-fe/src/components/onboarding/deploy-step/deploy-step.tsx b/apps/deploy-fe/src/components/onboarding/deploy-step/deploy-step.tsx index 5c404e8..0cedfc6 100644 --- a/apps/deploy-fe/src/components/onboarding/deploy-step/deploy-step.tsx +++ b/apps/deploy-fe/src/components/onboarding/deploy-step/deploy-step.tsx @@ -1,9 +1,10 @@ // src/components/onboarding/deploy-step/deploy-step.tsx 'use client' -import { useOnboarding } from '@/components/onboarding/useOnboarding' +import { useOnboarding } from '@/components/onboarding/store' import { useWallet } from '@/context/WalletContext' import { useDeployment } from '@/hooks/useDeployment' +import { useDirectTemplateDeployment } from '@/hooks/useDirectTemplateDeployment' import { useTemplateDeployment } from '@/hooks/useTemplate' import { Alert, AlertDescription } from '@workspace/ui/components/alert' import { Badge } from '@workspace/ui/components/badge' @@ -44,7 +45,7 @@ export function DeployStep() { useTemplateDeployment() // Determine deployment type and get the right deploying state - const isTemplateMode = formData.deploymentMode === 'template' + const isTemplateMode = formData.template ? true : false const isDeploying = isTemplateMode ? isTemplateDeploying : isRepoDeploying // Handle hydration mismatch by waiting for mount @@ -132,11 +133,17 @@ export function DeployStep() { throw new Error('Missing required template deployment data') } + if (!formData.template.repoFullName) { + throw new Error('Template repository information is missing') + } + const config = { template: { - ...formData.template, - id: formData.template?.id || '', - icon: formData.template?.icon || '' + id: formData.template.id, + name: formData.template.name, + icon: formData.template.icon || '', + repoFullName: formData.template.repoFullName, + description: formData.template.description || '' }, projectName: formData.projectName, organizationSlug: formData.selectedOrg, diff --git a/apps/deploy-fe/src/components/onboarding/deploy-step/disabled_deploy-step.tsx b/apps/deploy-fe/src/components/onboarding/deploy-step/disabled_deploy-step.tsx deleted file mode 100644 index 9fa7161..0000000 --- a/apps/deploy-fe/src/components/onboarding/deploy-step/disabled_deploy-step.tsx +++ /dev/null @@ -1,42 +0,0 @@ -'use client' - -import { useOnboarding } from '../store' - -/** - * Final step in the onboarding flow - * Displays deployment summary and triggers deployment - * - * Features: - * - Configuration summary - * - Repository display - * - Deploy action - * - * @component - */ -export function DeployStep() { - useOnboarding() - - return ( -
-
-
-
- {/* Header section */} -
-
-

Deploy

-

- Your deployment is configured and ready to go! -

-
-
- Content sections will be placed here: 1. Repository info card 2. - Configuration summary 3. Deploy button - {/* ...content here */} - {/* */} -
-
-
-
- ) -} diff --git a/apps/deploy-fe/src/components/onboarding/store.ts b/apps/deploy-fe/src/components/onboarding/store.ts index 28b605a..0e4b165 100644 --- a/apps/deploy-fe/src/components/onboarding/store.ts +++ b/apps/deploy-fe/src/components/onboarding/store.ts @@ -7,6 +7,7 @@ 'use client' import { create } from 'zustand' +import { persist, createJSONStorage } from 'zustand/middleware' import type { OnboardingFormData, Step } from './types' /** @@ -31,7 +32,7 @@ export interface OnboardingState { } /** Order of steps in the onboarding flow */ -const STEP_ORDER: Step[] = ['connect', 'configure', 'deploy'] +const STEP_ORDER: Step[] = ['connect', 'configure', 'deploy', 'success'] /** Initial form data values */ const initialFormData: OnboardingFormData = { @@ -64,25 +65,58 @@ const initialFormData: OnboardingFormData = { * const { currentStep, formData, nextStep } = useOnboarding() * ``` */ -export const useOnboarding = create((set) => ({ - currentStep: 'connect', - formData: initialFormData, - setCurrentStep: (step) => set({ currentStep: step }), - setFormData: (data) => - set((state) => ({ - formData: { ...state.formData, ...data } - })), - nextStep: () => - set((state) => { - const currentIndex = STEP_ORDER.indexOf(state.currentStep) - const nextStep = STEP_ORDER[currentIndex + 1] - return nextStep ? { currentStep: nextStep } : state +export const useOnboarding = create()( + persist( + (set) => ({ + currentStep: 'connect', + formData: initialFormData, + + setCurrentStep: (step) => set({ currentStep: step }), + + setFormData: (data) => { + set((state) => { + const newFormData = { ...state.formData, ...data } + + // Keep organizationSlug and selectedOrg in sync + if (data.organizationSlug && !data.selectedOrg) { + newFormData.selectedOrg = data.organizationSlug + } + if (data.selectedOrg && !data.organizationSlug) { + newFormData.organizationSlug = data.selectedOrg + } + + console.log('Store: Setting form data:', data) + console.log('Store: New state:', newFormData) + + return { formData: newFormData } + }) + }, + + nextStep: () => + set((state) => { + const currentIndex = STEP_ORDER.indexOf(state.currentStep) + const nextStep = STEP_ORDER[currentIndex + 1] + return nextStep ? { currentStep: nextStep } : state + }), + + previousStep: () => + set((state) => { + const currentIndex = STEP_ORDER.indexOf(state.currentStep) + const previousStep = STEP_ORDER[currentIndex - 1] + return previousStep ? { currentStep: previousStep } : state + }), + + resetOnboarding: () => { + set({ currentStep: 'connect', formData: initialFormData }) + } }), - previousStep: () => - set((state) => { - const currentIndex = STEP_ORDER.indexOf(state.currentStep) - const previousStep = STEP_ORDER[currentIndex - 1] - return previousStep ? { currentStep: previousStep } : state - }), - resetOnboarding: () => set({ currentStep: 'connect', formData: initialFormData }) -})) + { + name: 'laconic-onboarding', + storage: createJSONStorage(() => localStorage), + // Only persist formData, not currentStep + partialize: (state) => ({ + formData: state.formData + }) + } + ) +) \ No newline at end of file diff --git a/apps/deploy-fe/src/components/onboarding/success-step/success-step.tsx b/apps/deploy-fe/src/components/onboarding/success-step/success-step.tsx index 73eb428..7d3a1e5 100644 --- a/apps/deploy-fe/src/components/onboarding/success-step/success-step.tsx +++ b/apps/deploy-fe/src/components/onboarding/success-step/success-step.tsx @@ -24,8 +24,8 @@ export function SuccessStep() { const repoName = formData.githubRepo ? formData.githubRepo.split('/').pop() : formData.repoName - ? formData.repoName.split('/').pop() - : formData.projectName || 'project' + ? formData.repoName.split('/').pop() + : formData.projectName || 'project' const deploymentUrl = `https://${repoName}.laconic.deploy` // Default deployment URL const projectId = formData.projectId || formData.deploymentId || 'unknown-id' // Use projectId first, fallback to deploymentId diff --git a/apps/deploy-fe/src/components/onboarding/useOnboarding.ts b/apps/deploy-fe/src/components/onboarding/useOnboarding.ts deleted file mode 100644 index 585cd1d..0000000 --- a/apps/deploy-fe/src/components/onboarding/useOnboarding.ts +++ /dev/null @@ -1,120 +0,0 @@ -// src/components/onboarding/useOnboarding.ts -import { useState } from 'react' -import type { - OnboardingFormData} from '@/types' - -// Step type for navigation -export type Step = 'connect' | 'configure' | 'deploy' | 'success' - -// Initial form data -const initialFormData: OnboardingFormData = { - // Step 1: Connect - githubRepo: undefined, - template: undefined, - projectName: undefined, - deploymentMode: undefined, - - // Step 2: Configure - selectedLrn: undefined, - selectedOrg: undefined, // Add this property - environmentVariables: [], // Use array type - deploymentType: undefined, // Add missing properties - deployerCount: undefined, - maxPrice: undefined, - - // Step 3: Deploy - deploymentId: undefined, - repositoryUrl: undefined, - deploymentUrl: undefined, // Add missing property - projectId: undefined // Add missing property -} - -export function useOnboarding() { - const [formData, setFormData] = useState(initialFormData) - const [currentStep, setCurrentStep] = useState('connect') - - // Update form data (partial update) - const updateFormData = (updates: Partial) => { - setFormData(prev => ({ ...prev, ...updates })) - } - - // Reset form data - const resetFormData = () => { - setFormData(initialFormData) - setCurrentStep('connect') - } - - // Step navigation - const nextStep = () => { - switch (currentStep) { - case 'connect': - setCurrentStep('configure') - break - case 'configure': - setCurrentStep('deploy') - break - case 'deploy': - setCurrentStep('success') - break - } - } - - const previousStep = () => { - switch (currentStep) { - case 'configure': - setCurrentStep('connect') - break - case 'deploy': - setCurrentStep('configure') - break - case 'success': - setCurrentStep('deploy') - break - } - } - - // Validation helpers - const validateStep1 = () => { - if (formData.deploymentMode === 'template') { - return !!(formData.template && formData.projectName) - } - return !!formData.githubRepo - } - - const validateStep2 = () => { - return !!(formData.selectedLrn && formData.selectedOrg) - } - - const validateStep3 = () => { - return !!formData.deploymentId - } - - return { - // Data - formData, - currentStep, - - // Actions - setFormData: updateFormData, - setCurrentStep, - resetFormData, - resetOnboarding: resetFormData, // Alias for compatibility - nextStep, - previousStep, - - // Validation - validateStep1, - validateStep2, - validateStep3, - - // Store-like interface for compatibility - getState: () => ({ - formData, - currentStep, - nextStep, - previousStep, - setFormData: updateFormData, - resetFormData - }) - } -} \ No newline at end of file