diff --git a/app/projects/[id]/github/page.tsx b/app/projects/[id]/github/page.tsx new file mode 100644 index 0000000..d3fb898 --- /dev/null +++ b/app/projects/[id]/github/page.tsx @@ -0,0 +1,184 @@ +'use client'; + +import { useState } from 'react'; +import { ExternalLink, Github, Loader2, RefreshCw } from 'lucide-react'; +import { useParams, useRouter } from 'next/navigation'; +import { toast } from 'sonner'; + +import { ConfigLayout } from '@/components/config/config-layout'; +import SettingsDialog from '@/components/dialog/settings-dialog'; +import { Button } from '@/components/ui/button'; +import { useProject } from '@/hooks/use-project'; +import { commitChanges, initializeRepo } from '@/lib/services/repoService'; + +export default function GithubPage() { + const params = useParams(); + const projectId = params.id as string; + const router = useRouter(); + + const { data: project, isLoading: projectLoading } = useProject(projectId); + + const [isInitializing, setIsInitializing] = useState(false); + const [isCommitting, setIsCommitting] = useState(false); + const [showSettings, setShowSettings] = useState(false); + + // Create a new repository on GitHub + const handleInitialize = async () => { + if (project?.githubRepo || isInitializing) return; + + setIsInitializing(true); + try { + const result = await initializeRepo(projectId); + if (result.success) { + toast.success(result.message); + router.refresh(); + } else { + if (result.code === 'GITHUB_NOT_BOUND') { + toast.error('Please connect your GitHub account first'); + setShowSettings(true); + } else { + toast.error(result.message); + } + } + } catch (_error) { + toast.error('An unexpected error occurred'); + } finally { + setIsInitializing(false); + } + }; + + // Commit changes to the repository and push to GitHub + const handleCommit = async () => { + if (isCommitting) return; + + setIsCommitting(true); + try { + const result = await commitChanges(projectId); + if (result.success) { + toast.success(result.message); + } else { + if (result.code === 'GITHUB_NOT_BOUND') { + toast.error('Please connect your GitHub account first'); + setShowSettings(true); + } else { + toast.error(result.message); + } + } + } catch (_error) { + toast.error('Failed to commit changes'); + } finally { + setIsCommitting(false); + } + }; + + return ( + +
+ {/* Connection Status Section */} +
+ {/* Visual Header */} +
+
+ +
+
+

+ {project?.githubRepo ? 'Connected to GitHub' : 'GitHub Repository'} +

+

+ {project?.githubRepo + ? 'Your project is currently active and synced with a remote GitHub repository. You can push your latest changes below.' + : 'Initialize a new repository to start tracking changes. This will create a private repository in your GitHub account and push the initial code.'} +

+
+
+ + {/* Actions */} +
+ {project?.githubRepo ? ( +
+
+ Repository URL + + {project.githubRepo} + + +
+ +
+ + +
+
+ ) : ( + + )} +
+
+ + {/* Global Settings Link */} +
+
+

GitHub Account Settings

+

Manage your global GitHub connection and personal access tokens.

+
+ +
+ + +
+
+ ); +} diff --git a/components/home-page.tsx b/components/home-page.tsx index 208fef5..2abd0e3 100644 --- a/components/home-page.tsx +++ b/components/home-page.tsx @@ -139,7 +139,7 @@ export function HomePage() { > {getButtonText()} - +