From 2dc22cc40b98ebcb07e2c12e0e57bea8132c8940 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 24 Dec 2025 16:54:34 -0600 Subject: [PATCH] Add SyncStepError component --- src/components/git-sync/steps/SyncStep.tsx | 184 +----------------- .../git-sync/steps/SyncStepError.tsx | 145 ++++++++++++++ 2 files changed, 155 insertions(+), 174 deletions(-) create mode 100644 src/components/git-sync/steps/SyncStepError.tsx diff --git a/src/components/git-sync/steps/SyncStep.tsx b/src/components/git-sync/steps/SyncStep.tsx index 08d58e1b..f3a5dad3 100644 --- a/src/components/git-sync/steps/SyncStep.tsx +++ b/src/components/git-sync/steps/SyncStep.tsx @@ -1,10 +1,8 @@ -import { Errors as GitErrors } from 'isomorphic-git'; import { useState, useCallback } from 'react'; -import { Zap, Copy, Check, RefreshCw, EllipsisVertical, CloudOff, ExternalLink, ChevronDown, ArrowDown, ArrowUp, X, AlertTriangle } from 'lucide-react'; +import { Zap, Copy, Check, RefreshCw, EllipsisVertical, CloudOff, ExternalLink, ChevronDown, ArrowDown, ArrowUp, AlertTriangle } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; -import { Alert, AlertDescription } from '@/components/ui/alert'; import { DropdownMenu, DropdownMenuContent, @@ -22,6 +20,7 @@ import { AlertDialogTitle, } from '@/components/ui/alert-dialog'; import { ExternalFavicon } from '@/components/ExternalFavicon'; +import { SyncStepError } from './SyncStepError'; import { useGitStatus } from '@/hooks/useGitStatus'; import { useGitSettings } from '@/hooks/useGitSettings'; import { useGit } from '@/hooks/useGit'; @@ -260,177 +259,7 @@ export function SyncStep({ projectId }: StepProps) { } }; - const renderForcePullButton = () => ( - - ); - // Render special error UI based on error type - const renderError = () => { - if (!error) return null; - - // MergeNotSupportedError - offer force pull - if (error instanceof GitErrors.MergeNotSupportedError) { - return ( - -
-
- - Cannot merge changes automatically. Your local changes conflict with the remote repository. - - -
- {renderForcePullButton()} -
-
- ); - } - - // FastForwardError - offer force push or force pull - if (error instanceof GitErrors.FastForwardError) { - return ( - - -
-
- - Cannot fast-forward. The remote has changes that conflict with your local commits. - - -
- -
-
- ); - } - - // PushRejectedError - remote has changes - if (error instanceof GitErrors.PushRejectedError) { - return ( - - -
-
- - Push rejected. The remote repository has changes you don't have locally. Try pulling first. - - -
-
- - {renderForcePullButton()} -
-
-
- ); - } - - // HTTP errors - if (error instanceof GitErrors.HttpError) { - let message: string; - - switch (error.data.statusCode) { - case 401: - message = 'Authentication failed. Please check your credentials.'; - break; - case 403: - message = 'Access forbidden. You do not have permission to access this repository.'; - break; - default: - message = `HTTP Error: ${error.data.statusCode} ${error.data.statusMessage}`; - } - - return ( - - -
- - {message} - - -
-
- ); - } - - // Generic error fallback - return ( - - -
- {error.message} - -
-
- ); - }; if (!originRemote) { return null; @@ -491,7 +320,14 @@ export function SyncStep({ projectId }: StepProps) { - {renderError()} + {error && ( + setError(null)} + onForcePull={() => setShowForcePullDialog(true)} + onPull={handlePull} + /> + )}
diff --git a/src/components/git-sync/steps/SyncStepError.tsx b/src/components/git-sync/steps/SyncStepError.tsx new file mode 100644 index 00000000..6978a11b --- /dev/null +++ b/src/components/git-sync/steps/SyncStepError.tsx @@ -0,0 +1,145 @@ +import { Errors as GitErrors } from 'isomorphic-git'; +import { AlertTriangle, X, ArrowDown } from 'lucide-react'; +import { Button } from '@/components/ui/button'; +import { Alert, AlertDescription } from '@/components/ui/alert'; + +interface SyncStepErrorProps { + error: Error; + onDismiss: () => void; + onForcePull: () => void; + onPull: () => void; +} + +export function SyncStepError({ error, onDismiss, onForcePull, onPull }: SyncStepErrorProps) { + const renderForcePullButton = () => ( + + ); + + const renderDismissButton = () => ( + + ); + + // MergeNotSupportedError - offer force pull + if (error instanceof GitErrors.MergeNotSupportedError) { + return ( + +
+
+ + Cannot merge changes automatically. Your local changes conflict with the remote repository. + + {renderDismissButton()} +
+ {renderForcePullButton()} +
+
+ ); + } + + // FastForwardError - offer force pull + if (error instanceof GitErrors.FastForwardError) { + return ( + + +
+
+ + Cannot fast-forward. The remote has changes that conflict with your local commits. + + {renderDismissButton()} +
+ {renderForcePullButton()} +
+
+ ); + } + + // PushRejectedError - remote has changes + if (error instanceof GitErrors.PushRejectedError) { + return ( + + +
+
+ + Push rejected. The remote repository has changes you don't have locally. Try pulling first. + + {renderDismissButton()} +
+
+ + {renderForcePullButton()} +
+
+
+ ); + } + + // HTTP errors + if (error instanceof GitErrors.HttpError) { + let message: string; + + switch (error.data.statusCode) { + case 401: + message = 'Authentication failed. Please check your credentials.'; + break; + case 403: + message = 'Access forbidden. You do not have permission to access this repository.'; + break; + default: + message = `HTTP Error: ${error.data.statusCode} ${error.data.statusMessage}`; + } + + return ( + + +
+ + {message} + + {renderDismissButton()} +
+
+ ); + } + + // Generic error fallback + return ( + + +
+ {error.message} + {renderDismissButton()} +
+
+ ); +}