mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Add dedicated settings pages
This commit is contained in:
8 files changed
+170
-293
No files matched your search
@@ -4,6 +4,9 @@ import { SessionMonitor } from "./components/SessionMonitor";
|
||||
|
||||
import Index from "./pages/Index";
|
||||
import Clone from "./pages/Clone";
|
||||
import Settings from "./pages/Settings";
|
||||
import AISettings from "./pages/AISettings";
|
||||
import GitSettings from "./pages/GitSettings";
|
||||
import { NIP19Page } from "./pages/NIP19Page";
|
||||
import NotFound from "./pages/NotFound";
|
||||
import { ProjectView } from "./pages/ProjectView";
|
||||
@@ -16,6 +19,9 @@ export function AppRouter() {
|
||||
<Routes>
|
||||
<Route path="/" element={<Index />} />
|
||||
<Route path="/clone" element={<Clone />} />
|
||||
<Route path="/settings" element={<Settings />} />
|
||||
<Route path="/settings/ai" element={<AISettings />} />
|
||||
<Route path="/settings/git" element={<GitSettings />} />
|
||||
<Route path="/project/:projectId" element={<ProjectView />} />
|
||||
{/* NIP-19 route for npub1, note1, naddr1, nevent1, nprofile1 */}
|
||||
<Route path="/:nip19" element={<NIP19Page />} />
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useState } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import {
|
||||
Dialog,
|
||||
@@ -40,7 +41,7 @@ import { useFS } from '@/hooks/useFS';
|
||||
import { useToast } from '@/hooks/useToast';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { findCredentialsForRepo, getOriginDisplayName } from '@/lib/gitCredentials';
|
||||
import { GitSettingsDialog } from './GitSettingsDialog';
|
||||
|
||||
import git from 'isomorphic-git';
|
||||
import http from 'isomorphic-git/http/web';
|
||||
|
||||
@@ -56,7 +57,7 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog
|
||||
const [isPulling, setIsPulling] = useState(false);
|
||||
const [pushResult, setPushResult] = useState<string | null>(null);
|
||||
const [pullResult, setPullResult] = useState<string | null>(null);
|
||||
const [showGitSettings, setShowGitSettings] = useState(false);
|
||||
const navigate = useNavigate();
|
||||
|
||||
const { data: gitStatus, refetch: refetchGitStatus } = useGitStatus(projectId);
|
||||
const { settings } = useGitSettings();
|
||||
@@ -382,7 +383,7 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => setShowGitSettings(true)}
|
||||
onClick={() => navigate('/settings/git')}
|
||||
className="h-7 gap-1 text-xs"
|
||||
>
|
||||
<Settings className="h-3 w-3" />
|
||||
@@ -427,7 +428,7 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog
|
||||
No credentials configured for {originDisplayName}.
|
||||
Push/pull operations may fail for private repositories.{' '}
|
||||
<button
|
||||
onClick={() => setShowGitSettings(true)}
|
||||
onClick={() => navigate('/settings/git')}
|
||||
className="underline hover:no-underline font-medium"
|
||||
>
|
||||
Configure credentials
|
||||
@@ -556,12 +557,6 @@ export function GitDialog({ projectId, children, open, onOpenChange }: GitDialog
|
||||
)}
|
||||
</div>
|
||||
</ScrollArea>
|
||||
|
||||
{/* Git Settings Dialog */}
|
||||
<GitSettingsDialog
|
||||
open={showGitSettings}
|
||||
onOpenChange={setShowGitSettings}
|
||||
/>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
);
|
||||
|
||||
@@ -1,139 +0,0 @@
|
||||
import { describe, it, expect, beforeEach } from 'vitest';
|
||||
import { render, screen, fireEvent, waitFor } from '@testing-library/react';
|
||||
import { TestApp } from '@/test/TestApp';
|
||||
import { GitSettingsDialog } from './GitSettingsDialog';
|
||||
|
||||
describe('GitSettingsDialog', () => {
|
||||
beforeEach(() => {
|
||||
localStorage.clear();
|
||||
});
|
||||
|
||||
it('renders the dialog with trigger button', () => {
|
||||
render(
|
||||
<TestApp>
|
||||
<GitSettingsDialog />
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
expect(screen.getByRole('button', { name: /git settings/i })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('opens dialog when trigger is clicked', async () => {
|
||||
render(
|
||||
<TestApp>
|
||||
<GitSettingsDialog />
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
fireEvent.click(screen.getByRole('button', { name: /git settings/i }));
|
||||
|
||||
await waitFor(() => {
|
||||
expect(screen.getByRole('dialog')).toBeInTheDocument();
|
||||
expect(screen.getByRole('heading', { name: 'Git Settings' })).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it('shows preset providers (GitHub and GitLab)', async () => {
|
||||
render(
|
||||
<TestApp>
|
||||
<GitSettingsDialog open={true} />
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
expect(screen.getByText('GitHub')).toBeInTheDocument();
|
||||
expect(screen.getByText('GitLab')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('can add a preset provider with token', async () => {
|
||||
render(
|
||||
<TestApp>
|
||||
<GitSettingsDialog open={true} />
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
// Find GitHub token input and add button
|
||||
const tokenInputs = screen.getAllByPlaceholderText('Enter your token');
|
||||
const addButtons = screen.getAllByText('Add');
|
||||
|
||||
// Assuming GitHub is the first preset
|
||||
const githubTokenInput = tokenInputs[0];
|
||||
const githubAddButton = addButtons[0];
|
||||
|
||||
expect(githubTokenInput).toBeInTheDocument();
|
||||
expect(githubAddButton).toBeInTheDocument();
|
||||
|
||||
fireEvent.change(githubTokenInput, { target: { value: 'test-token' } });
|
||||
fireEvent.click(githubAddButton);
|
||||
|
||||
// Check that the provider was added to configured providers
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('Configured Credentials')).toBeInTheDocument();
|
||||
}, { timeout: 3000 });
|
||||
});
|
||||
|
||||
it('can add custom provider', async () => {
|
||||
render(
|
||||
<TestApp>
|
||||
<GitSettingsDialog open={true} />
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
// Fill custom provider form
|
||||
const originInput = screen.getByLabelText(/origin/i);
|
||||
const usernameInput = screen.getByLabelText(/username/i);
|
||||
const passwordInput = screen.getByLabelText(/password/i);
|
||||
const addCustomButton = screen.getByRole('button', { name: /add custom provider/i });
|
||||
|
||||
fireEvent.change(originInput, { target: { value: 'https://git.example.com' } });
|
||||
fireEvent.change(usernameInput, { target: { value: 'testuser' } });
|
||||
fireEvent.change(passwordInput, { target: { value: 'testpass' } });
|
||||
|
||||
expect(addCustomButton).not.toBeDisabled();
|
||||
fireEvent.click(addCustomButton);
|
||||
|
||||
// Check that the provider was added
|
||||
await waitFor(() => {
|
||||
expect(screen.getByText('Configured Credentials')).toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
it('shows red dot when not configured', () => {
|
||||
render(
|
||||
<TestApp>
|
||||
<GitSettingsDialog />
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
// Check for red dot indicator
|
||||
const redDot = document.querySelector('.bg-red-500');
|
||||
expect(redDot).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it('validates custom provider form', () => {
|
||||
render(
|
||||
<TestApp>
|
||||
<GitSettingsDialog open={true} />
|
||||
</TestApp>
|
||||
);
|
||||
|
||||
const addCustomButton = screen.getByRole('button', { name: /add custom provider/i });
|
||||
|
||||
// Button should be disabled when form is empty
|
||||
expect(addCustomButton).toBeDisabled();
|
||||
|
||||
// Fill only origin
|
||||
const originInput = screen.getByLabelText(/origin/i);
|
||||
fireEvent.change(originInput, { target: { value: 'https://git.example.com' } });
|
||||
expect(addCustomButton).toBeDisabled();
|
||||
|
||||
// Fill origin and username
|
||||
const usernameInput = screen.getByLabelText(/username/i);
|
||||
fireEvent.change(usernameInput, { target: { value: 'testuser' } });
|
||||
expect(addCustomButton).toBeDisabled();
|
||||
|
||||
// Fill all fields
|
||||
const passwordInput = screen.getByLabelText(/password/i);
|
||||
fireEvent.change(passwordInput, { target: { value: 'testpass' } });
|
||||
expect(addCustomButton).not.toBeDisabled();
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import { useState, useMemo } from 'react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import { Check, ChevronDown, Edit3, RefreshCw, AlertCircle, Settings } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Input } from '@/components/ui/input';
|
||||
@@ -8,7 +9,6 @@ import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { useAISettings } from '@/hooks/useAISettings';
|
||||
import { useProviderModels } from '@/hooks/useProviderModels';
|
||||
import { cn } from '@/lib/utils';
|
||||
import { AISettingsDialog } from '@/components/ai/AISettingsDialog';
|
||||
|
||||
interface ModelSelectorProps {
|
||||
value: string;
|
||||
@@ -28,9 +28,9 @@ export function ModelSelector({
|
||||
const [open, setOpen] = useState(false);
|
||||
const [isCustomInput, setIsCustomInput] = useState(false);
|
||||
const [customValue, setCustomValue] = useState('');
|
||||
const [settingsOpen, setSettingsOpen] = useState(false);
|
||||
const { settings, addRecentlyUsedModel, isConfigured } = useAISettings();
|
||||
const { models, isLoading, error, refetch } = useProviderModels();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const recentlyUsedModels = useMemo(() => settings.recentlyUsedModels || [], [settings.recentlyUsedModels]);
|
||||
|
||||
@@ -58,7 +58,7 @@ export function ModelSelector({
|
||||
}
|
||||
|
||||
if (selectedValue === '__manage_providers__') {
|
||||
setSettingsOpen(true);
|
||||
navigate('/settings/ai');
|
||||
setOpen(false);
|
||||
return;
|
||||
}
|
||||
@@ -112,12 +112,7 @@ export function ModelSelector({
|
||||
}
|
||||
|
||||
return (
|
||||
<>
|
||||
<AISettingsDialog
|
||||
open={settingsOpen}
|
||||
onOpenChange={setSettingsOpen}
|
||||
/>
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<Popover open={open} onOpenChange={setOpen}>
|
||||
<PopoverTrigger asChild>
|
||||
<Button
|
||||
variant="ghost"
|
||||
@@ -257,6 +252,5 @@ export function ModelSelector({
|
||||
</Command>
|
||||
</PopoverContent>
|
||||
</Popover>
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -6,8 +6,6 @@ import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from '@/components/ui/dropdown-menu';
|
||||
import { LoginArea } from '@/components/auth/LoginArea';
|
||||
import { StarButton } from '@/components/StarButton';
|
||||
import { AISettingsDialog } from '@/components/ai/AISettingsDialog';
|
||||
import { GitSettingsDialog } from '@/components/GitSettingsDialog';
|
||||
import { useProjectsManager } from '@/hooks/useProjectsManager';
|
||||
import { useProjectSessionStatus } from '@/hooks/useProjectSessionStatus';
|
||||
import { useLocalStorage } from '@/hooks/useLocalStorage';
|
||||
@@ -91,8 +89,6 @@ export function ProjectSidebar({
|
||||
const [projects, setProjects] = useState<Project[]>([]);
|
||||
const [isLoading, setIsLoading] = useState(true);
|
||||
const [isExporting, setIsExporting] = useState(false);
|
||||
const [aiSettingsOpen, setAISettingsOpen] = useState(false);
|
||||
const [gitSettingsOpen, setGitSettingsOpen] = useState(false);
|
||||
const [favorites] = useLocalStorage<string[]>('project-favorites', []);
|
||||
const projectsManager = useProjectsManager();
|
||||
const navigate = useNavigate();
|
||||
@@ -249,19 +245,11 @@ export function ProjectSidebar({
|
||||
</DropdownMenuItem>
|
||||
|
||||
<DropdownMenuItem
|
||||
onClick={() => setAISettingsOpen(true)}
|
||||
onClick={() => navigate('/settings')}
|
||||
className="flex items-center gap-2 w-full"
|
||||
>
|
||||
<Settings className="h-4 w-4" />
|
||||
AI Settings
|
||||
</DropdownMenuItem>
|
||||
|
||||
<DropdownMenuItem
|
||||
onClick={() => setGitSettingsOpen(true)}
|
||||
className="flex items-center gap-2 w-full"
|
||||
>
|
||||
<GitBranch className="h-4 w-4" />
|
||||
Git Settings
|
||||
Settings
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
@@ -318,18 +306,6 @@ export function ProjectSidebar({
|
||||
<div className="p-4 border-t border-sidebar-border bg-gradient-to-r from-primary/5 to-accent/5 mt-auto">
|
||||
<LoginArea className="w-full" />
|
||||
</div>
|
||||
|
||||
{/* AI Settings Dialog */}
|
||||
<AISettingsDialog
|
||||
open={aiSettingsOpen}
|
||||
onOpenChange={setAISettingsOpen}
|
||||
/>
|
||||
|
||||
{/* Git Settings Dialog */}
|
||||
<GitSettingsDialog
|
||||
open={gitSettingsOpen}
|
||||
onOpenChange={setGitSettingsOpen}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -1,7 +1,6 @@
|
||||
import { useState } from 'react';
|
||||
import { Settings, Trash2, Check } from 'lucide-react';
|
||||
import { Check, Bot, ArrowLeft } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Card, CardContent } from '@/components/ui/card';
|
||||
@@ -10,6 +9,8 @@ import { Badge } from '@/components/ui/badge';
|
||||
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||
import { useAISettings } from '@/hooks/useAISettings';
|
||||
import { AppLayout } from '@/components/AppLayout';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import type { AIConnection } from '@/contexts/AISettingsContext';
|
||||
|
||||
interface PresetProvider {
|
||||
@@ -71,33 +72,15 @@ const PRESET_PROVIDERS: PresetProvider[] = [
|
||||
},
|
||||
];
|
||||
|
||||
interface AISettingsDialogProps {
|
||||
open?: boolean;
|
||||
onOpenChange?: (open: boolean) => void;
|
||||
}
|
||||
|
||||
export function AISettingsDialog({ open: controlledOpen, onOpenChange }: AISettingsDialogProps = {}) {
|
||||
const { settings, addProvider, removeProvider, updateProvider, isConfigured } = useAISettings();
|
||||
const [internalOpen, setInternalOpen] = useState(false);
|
||||
|
||||
// Use controlled or internal state
|
||||
const open = controlledOpen !== undefined ? controlledOpen : internalOpen;
|
||||
const setOpen = onOpenChange || setInternalOpen;
|
||||
export function AISettings() {
|
||||
const { settings, addProvider, removeProvider, updateProvider } = useAISettings();
|
||||
const navigate = useNavigate();
|
||||
const [customProviderName, setCustomProviderName] = useState('');
|
||||
const [customBaseURL, setCustomBaseURL] = useState('');
|
||||
const [customApiKey, setCustomApiKey] = useState('');
|
||||
const [customAuthMethod, setCustomAuthMethod] = useState<'api-key' | 'nostr'>('api-key');
|
||||
const [presetApiKeys, setPresetApiKeys] = useState<Record<string, string>>({});
|
||||
|
||||
const handleCancel = () => {
|
||||
setCustomProviderName('');
|
||||
setCustomBaseURL('');
|
||||
setCustomApiKey('');
|
||||
setCustomAuthMethod('api-key');
|
||||
setPresetApiKeys({});
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
const handleAddPresetProvider = (preset: PresetProvider) => {
|
||||
const apiKey = presetApiKeys[preset.id] as string | undefined;
|
||||
|
||||
@@ -154,28 +137,31 @@ export function AISettingsDialog({ open: controlledOpen, onOpenChange }: AISetti
|
||||
const availablePresets = PRESET_PROVIDERS.filter(preset => !configuredProviderIds.includes(preset.id));
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
{/* Only show trigger if not controlled externally */}
|
||||
{controlledOpen === undefined && (
|
||||
<DialogTrigger asChild>
|
||||
<Button variant="ghost" size="sm" className="gap-2">
|
||||
<Settings className="h-4 w-4" />
|
||||
AI Settings
|
||||
{!isConfigured && (
|
||||
<span className="ml-1 h-2 w-2 rounded-full bg-red-500" />
|
||||
)}
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
)}
|
||||
<DialogContent className="sm:max-w-[700px] max-h-[80vh] overflow-y-auto">
|
||||
<DialogHeader>
|
||||
<DialogTitle>AI Settings</DialogTitle>
|
||||
<DialogDescription>
|
||||
Configure AI providers by adding your API keys. Settings are automatically saved and stored locally in your browser.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<AppLayout title="AI Settings" showSidebar={true}>
|
||||
<div className="max-w-4xl mx-auto">
|
||||
<Card className="bg-white">
|
||||
<CardContent className="p-6 space-y-6">
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-3">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => navigate('/settings')}
|
||||
className="h-8 w-8 p-0"
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
</Button>
|
||||
<h1 className="text-3xl font-bold tracking-tight flex items-center gap-3">
|
||||
<Bot className="h-8 w-8 text-primary" />
|
||||
AI Settings
|
||||
</h1>
|
||||
</div>
|
||||
<p className="text-muted-foreground ml-11">
|
||||
Configure AI providers by adding your API keys. Settings are automatically saved and stored locally in your browser.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="space-y-6 py-4">
|
||||
<div className="space-y-6">
|
||||
{/* Configured Providers */}
|
||||
{configuredProviderIds.length > 0 && (
|
||||
<div className="space-y-3">
|
||||
@@ -205,7 +191,9 @@ export function AISettingsDialog({ open: controlledOpen, onOpenChange }: AISetti
|
||||
}}
|
||||
className="h-8 w-8 p-0 text-muted-foreground hover:text-destructive"
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
<svg className="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
|
||||
</svg>
|
||||
</Button>
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
@@ -392,14 +380,12 @@ export function AISettingsDialog({ open: controlledOpen, onOpenChange }: AISetti
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end">
|
||||
<Button variant="outline" onClick={handleCancel}>
|
||||
Close
|
||||
</Button>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</AppLayout>
|
||||
);
|
||||
}
|
||||
|
||||
export default AISettings;
|
||||
@@ -1,7 +1,6 @@
|
||||
import { useState } from 'react';
|
||||
import { GitBranch, Trash2, Check } from 'lucide-react';
|
||||
import { Check, GitBranch, ArrowLeft } from 'lucide-react';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle, DialogTrigger } from '@/components/ui/dialog';
|
||||
import { Input } from '@/components/ui/input';
|
||||
import { Label } from '@/components/ui/label';
|
||||
import { Card, CardContent } from '@/components/ui/card';
|
||||
@@ -9,6 +8,8 @@ import { Separator } from '@/components/ui/separator';
|
||||
import { Badge } from '@/components/ui/badge';
|
||||
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion';
|
||||
import { useGitSettings } from '@/hooks/useGitSettings';
|
||||
import { AppLayout } from '@/components/AppLayout';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
import type { GitCredential } from '@/contexts/GitSettingsContext';
|
||||
|
||||
interface PresetProvider {
|
||||
@@ -36,31 +37,14 @@ const PRESET_PROVIDERS: PresetProvider[] = [
|
||||
},
|
||||
];
|
||||
|
||||
interface GitSettingsDialogProps {
|
||||
open?: boolean;
|
||||
onOpenChange?: (open: boolean) => void;
|
||||
}
|
||||
|
||||
export function GitSettingsDialog({ open: controlledOpen, onOpenChange }: GitSettingsDialogProps = {}) {
|
||||
const { settings, addCredential, removeCredential, updateCredential, isConfigured } = useGitSettings();
|
||||
const [internalOpen, setInternalOpen] = useState(false);
|
||||
|
||||
// Use controlled or internal state
|
||||
const open = controlledOpen !== undefined ? controlledOpen : internalOpen;
|
||||
const setOpen = onOpenChange || setInternalOpen;
|
||||
export function GitSettings() {
|
||||
const { settings, addCredential, removeCredential, updateCredential } = useGitSettings();
|
||||
const navigate = useNavigate();
|
||||
const [customOrigin, setCustomOrigin] = useState('');
|
||||
const [customUsername, setCustomUsername] = useState('');
|
||||
const [customPassword, setCustomPassword] = useState('');
|
||||
const [presetTokens, setPresetTokens] = useState<Record<string, string>>({});
|
||||
|
||||
const handleCancel = () => {
|
||||
setCustomOrigin('');
|
||||
setCustomUsername('');
|
||||
setCustomPassword('');
|
||||
setPresetTokens({});
|
||||
setOpen(false);
|
||||
};
|
||||
|
||||
const handleAddPresetProvider = (preset: PresetProvider) => {
|
||||
const token = presetTokens[preset.id] as string | undefined;
|
||||
|
||||
@@ -111,28 +95,31 @@ export function GitSettingsDialog({ open: controlledOpen, onOpenChange }: GitSet
|
||||
const availablePresets = PRESET_PROVIDERS.filter(preset => !configuredOrigins.includes(preset.origin));
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={setOpen}>
|
||||
{/* Only show trigger if not controlled externally */}
|
||||
{controlledOpen === undefined && (
|
||||
<DialogTrigger asChild>
|
||||
<Button variant="ghost" size="sm" className="gap-2">
|
||||
<GitBranch className="h-4 w-4" />
|
||||
Git Settings
|
||||
{!isConfigured && (
|
||||
<span className="ml-1 h-2 w-2 rounded-full bg-red-500" />
|
||||
)}
|
||||
</Button>
|
||||
</DialogTrigger>
|
||||
)}
|
||||
<DialogContent className="sm:max-w-[700px] max-h-[80vh] overflow-y-auto">
|
||||
<DialogHeader>
|
||||
<DialogTitle>Git Settings</DialogTitle>
|
||||
<DialogDescription>
|
||||
Configure Git credentials for HTTP authentication. Settings are automatically saved and stored locally in your browser.
|
||||
</DialogDescription>
|
||||
</DialogHeader>
|
||||
<AppLayout title="Git Settings" showSidebar={true}>
|
||||
<div className="max-w-4xl mx-auto">
|
||||
<Card className="bg-white">
|
||||
<CardContent className="p-6 space-y-6">
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-3">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => navigate('/settings')}
|
||||
className="h-8 w-8 p-0"
|
||||
>
|
||||
<ArrowLeft className="h-4 w-4" />
|
||||
</Button>
|
||||
<h1 className="text-3xl font-bold tracking-tight flex items-center gap-3">
|
||||
<GitBranch className="h-8 w-8 text-primary" />
|
||||
Git Settings
|
||||
</h1>
|
||||
</div>
|
||||
<p className="text-muted-foreground ml-11">
|
||||
Configure Git credentials for HTTP authentication. Settings are automatically saved and stored locally in your browser.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="space-y-6 py-4">
|
||||
<div className="space-y-6">
|
||||
{/* Configured Credentials */}
|
||||
{configuredOrigins.length > 0 && (
|
||||
<div className="space-y-3">
|
||||
@@ -161,7 +148,9 @@ export function GitSettingsDialog({ open: controlledOpen, onOpenChange }: GitSet
|
||||
}}
|
||||
className="h-8 w-8 p-0 text-muted-foreground hover:text-destructive rounded-md hover:bg-accent"
|
||||
>
|
||||
<Trash2 className="h-4 w-4" />
|
||||
<svg className="h-4 w-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
|
||||
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
@@ -315,14 +304,12 @@ export function GitSettingsDialog({ open: controlledOpen, onOpenChange }: GitSet
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-end">
|
||||
<Button variant="outline" onClick={handleCancel}>
|
||||
Close
|
||||
</Button>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</AppLayout>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export default GitSettings;
|
||||
@@ -0,0 +1,72 @@
|
||||
import { AppLayout } from '@/components/AppLayout';
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
|
||||
import { Button } from '@/components/ui/button';
|
||||
import { Settings as SettingsIcon, Bot, GitBranch } from 'lucide-react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
export function Settings() {
|
||||
const navigate = useNavigate();
|
||||
|
||||
const settingsItems = [
|
||||
{
|
||||
title: 'AI Settings',
|
||||
description: 'Configure AI providers and API keys',
|
||||
icon: Bot,
|
||||
href: '/settings/ai',
|
||||
},
|
||||
{
|
||||
title: 'Git Settings',
|
||||
description: 'Configure Git credentials for HTTP authentication',
|
||||
icon: GitBranch,
|
||||
href: '/settings/git',
|
||||
},
|
||||
];
|
||||
|
||||
return (
|
||||
<AppLayout title="Settings" showSidebar={true}>
|
||||
<div className="max-w-4xl mx-auto">
|
||||
<Card className="bg-white">
|
||||
<CardContent className="p-6 space-y-6">
|
||||
<div className="space-y-2">
|
||||
<h1 className="text-3xl font-bold tracking-tight flex items-center gap-3">
|
||||
<SettingsIcon className="h-8 w-8 text-primary" />
|
||||
Settings
|
||||
</h1>
|
||||
<p className="text-muted-foreground">
|
||||
Manage your application settings and preferences.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="grid gap-4 md:grid-cols-2">
|
||||
{settingsItems.map((item) => {
|
||||
const Icon = item.icon;
|
||||
return (
|
||||
<Card
|
||||
key={item.href}
|
||||
className="cursor-pointer transition-all hover:shadow-md hover:scale-[1.02] hover:border-primary/20"
|
||||
onClick={() => navigate(item.href)}
|
||||
>
|
||||
<CardHeader className="pb-3">
|
||||
<CardTitle className="flex items-center gap-3">
|
||||
<Icon className="h-5 w-5 text-primary" />
|
||||
{item.title}
|
||||
</CardTitle>
|
||||
<CardDescription>{item.description}</CardDescription>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<Button variant="outline" className="w-full">
|
||||
Configure
|
||||
</Button>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</div>
|
||||
</AppLayout>
|
||||
);
|
||||
}
|
||||
|
||||
export default Settings;
|
||||
Reference in new issue
Block a user