Skip to content

Commit 7b231d8

Browse files
committed
✨ Add GitHub configuration check and conditional rendering in Repository component
1 parent 4e4c494 commit 7b231d8

File tree

1 file changed

+47
-11
lines changed

1 file changed

+47
-11
lines changed

src/components/repositories/Repository.tsx

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,12 @@ import type { SyncRepoRequest, SyncRepoResponse } from "@/types/sync";
2727
import { OwnerCombobox, OrganizationCombobox } from "./RepositoryComboboxes";
2828
import type { RetryRepoRequest, RetryRepoResponse } from "@/types/retry";
2929
import AddRepositoryDialog from "./AddRepositoryDialog";
30+
import type { ConfigApiResponse } from "@/types/config";
3031

3132
export default function Repository() {
3233
const [repositories, setRepositories] = useState<Repository[]>([]);
3334
const [isLoading, setIsLoading] = useState(true);
35+
const [isGitHubConfigured, setIsGitHubConfigured] = useState<boolean>(true);
3436
const { user } = useAuth();
3537
const { filter, setFilter } = useFilterParams({
3638
searchTerm: "",
@@ -76,8 +78,27 @@ export default function Repository() {
7678
const fetchRepositories = useCallback(async () => {
7779
if (!user) return;
7880

79-
setIsLoading(true);
81+
// First, check if GitHub is configured by fetching the user's config
8082
try {
83+
const configResponse = await apiRequest<ConfigApiResponse>(
84+
`/config?userId=${user.id}`,
85+
{
86+
method: "GET",
87+
}
88+
);
89+
90+
// Check if GitHub credentials are configured
91+
if (!configResponse?.githubConfig?.username || !configResponse?.githubConfig?.token) {
92+
setIsLoading(false);
93+
setIsGitHubConfigured(false);
94+
// Don't show error toast for unconfigured GitHub - just return silently
95+
return false;
96+
}
97+
98+
// GitHub is configured
99+
setIsGitHubConfigured(true);
100+
setIsLoading(true);
101+
81102
const response = await apiRequest<RepositoryApiResponse>(
82103
`/github/repositories?userId=${user.id}`,
83104
{
@@ -436,16 +457,31 @@ export default function Repository() {
436457
</Button>
437458
</div>
438459

439-
<RepositoryTable
440-
repositories={repositories}
441-
isLoading={isLoading || !connected}
442-
filter={filter}
443-
setFilter={setFilter}
444-
onMirror={handleMirrorRepo}
445-
onSync={handleSyncRepo}
446-
onRetry={handleRetryRepoAction}
447-
loadingRepoIds={loadingRepoIds}
448-
/>
460+
{!isGitHubConfigured ? (
461+
<div className="flex flex-col items-center justify-center p-8 border border-dashed rounded-md">
462+
<h3 className="text-xl font-semibold mb-2">GitHub Not Configured</h3>
463+
<p className="text-muted-foreground text-center mb-4">
464+
You need to configure your GitHub credentials before you can fetch and mirror repositories.
465+
</p>
466+
<Button
467+
variant="default"
468+
onClick={() => window.location.href = "/config"}
469+
>
470+
Go to Configuration
471+
</Button>
472+
</div>
473+
) : (
474+
<RepositoryTable
475+
repositories={repositories}
476+
isLoading={isLoading || !connected}
477+
filter={filter}
478+
setFilter={setFilter}
479+
onMirror={handleMirrorRepo}
480+
onSync={handleSyncRepo}
481+
onRetry={handleRetryRepoAction}
482+
loadingRepoIds={loadingRepoIds}
483+
/>
484+
)}
449485

450486
<AddRepositoryDialog
451487
onAddRepository={handleAddRepository}

0 commit comments

Comments
 (0)