Add SettingsLayout

This commit is contained in:
Alex Gleason committed 2025-09-13 15:22:08 -05:00
1 parent a87df5d0aa
commit bb47f36a35
5 files changed
+741 -518

No files matched your search

+244 -239
View File
@@ -3,13 +3,12 @@ import { Check, Bot, ArrowLeft } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Card, CardContent } from '@/components/ui/card';
import { Separator } from '@/components/ui/separator';
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 { useIsMobile } from '@/hooks/useIsMobile';
import { useNavigate } from 'react-router-dom';
import type { AIConnection } from '@/contexts/AISettingsContext';
@@ -74,6 +73,7 @@ const PRESET_PROVIDERS: PresetProvider[] = [
export function AISettings() {
const { settings, addProvider, removeProvider, updateProvider } = useAISettings();
const isMobile = useIsMobile();
const navigate = useNavigate();
const [customProviderName, setCustomProviderName] = useState('');
const [customBaseURL, setCustomBaseURL] = useState('');
@@ -137,254 +137,259 @@ export function AISettings() {
const availablePresets = PRESET_PROVIDERS.filter(preset => !configuredProviderIds.includes(preset.id));
return (
<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="p-6 space-y-6">
{isMobile && (
<div className="space-y-3">
<Button
variant="ghost"
size="sm"
onClick={() => navigate('/settings')}
className="h-8 w-auto px-2 -ml-2"
>
<ArrowLeft className="h-4 w-4 mr-2" />
Back to Settings
</Button>
<div className="space-y-2">
<h1 className="text-2xl font-bold flex items-center gap-3">
<Bot className="h-6 w-6 text-primary" />
AI Settings
</h1>
<p className="text-muted-foreground">
Configure AI providers by adding your API keys. Settings are automatically saved and stored locally in your browser.
</p>
</div>
</div>
)}
<div className="space-y-6">
{/* Configured Providers */}
{configuredProviderIds.length > 0 && (
<div className="space-y-3">
<h4 className="text-sm font-medium">Configured Providers</h4>
<Accordion type="multiple" className="w-full space-y-2">
{configuredProviderIds.map((providerId) => {
const preset = PRESET_PROVIDERS.find(p => p.id === providerId);
const provider = settings.providers[providerId];
const isCustom = !preset;
{!isMobile && (
<div className="space-y-2">
<h1 className="text-2xl font-bold flex items-center gap-3">
<Bot className="h-6 w-6 text-primary" />
AI Settings
</h1>
<p className="text-muted-foreground">
Configure AI providers by adding your API keys. Settings are automatically saved and stored locally in your browser.
</p>
</div>
)}
return (
<AccordionItem key={providerId} value={providerId} className="border rounded-lg">
<AccordionTrigger className="px-4 py-3 hover:no-underline">
<div className="flex items-center justify-between w-full mr-3">
<div className="flex items-center gap-2">
<span className="font-medium">
{preset?.name || providerId}
</span>
{isCustom && <Badge variant="outline">Custom</Badge>}
</div>
<Button
variant="ghost"
size="sm"
onClick={(e) => {
e.stopPropagation();
handleRemoveProvider(providerId);
}}
className="h-8 w-8 p-0 text-muted-foreground hover:text-destructive"
>
<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 className="space-y-6">
{/* Configured Providers */}
{configuredProviderIds.length > 0 && (
<div className="space-y-3">
<h4 className="text-sm font-medium">Configured Providers</h4>
<Accordion type="multiple" className="w-full space-y-2">
{configuredProviderIds.map((providerId) => {
const preset = PRESET_PROVIDERS.find(p => p.id === providerId);
const provider = settings.providers[providerId];
const isCustom = !preset;
return (
<AccordionItem key={providerId} value={providerId} className="border rounded-lg">
<AccordionTrigger className="px-4 py-3 hover:no-underline">
<div className="flex items-center justify-between w-full mr-3">
<div className="flex items-center gap-2">
<span className="font-medium">
{preset?.name || providerId}
</span>
{isCustom && <Badge variant="outline">Custom</Badge>}
</div>
</AccordionTrigger>
<AccordionContent className="px-4 pb-4">
<div className="space-y-3">
<div className="grid gap-2">
<Label htmlFor={`${providerId}-baseURL`}>Base URL</Label>
<Input
id={`${providerId}-baseURL`}
placeholder="https://api.example.com/v1"
value={provider?.baseURL || ''}
onChange={(e) => handleUpdateProvider(providerId, { baseURL: e.target.value })}
/>
</div>
<div className="grid gap-2">
<Label htmlFor={`${providerId}-auth`}>Authentication</Label>
<Select
value={provider?.nostr ? 'nostr' : 'api-key'}
onValueChange={(value: 'api-key' | 'nostr') => handleUpdateProvider(providerId, {
nostr: value === 'nostr' || undefined,
apiKey: value === 'nostr' ? undefined : provider?.apiKey
})}
>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="api-key">API Key</SelectItem>
<SelectItem value="nostr">Nostr</SelectItem>
</SelectContent>
</Select>
</div>
{!provider?.nostr && (
<div className="grid gap-2">
<Label htmlFor={`${providerId}-apiKey`}>API Key</Label>
<Input
id={`${providerId}-apiKey`}
type="password"
placeholder="Enter your API key"
value={provider?.apiKey || ''}
onChange={(e) => handleUpdateProvider(providerId, { apiKey: e.target.value })}
/>
</div>
)}
</div>
</AccordionContent>
</AccordionItem>
);
})}
</Accordion>
</div>
)}
{configuredProviderIds.length > 0 && availablePresets.length > 0 && <Separator />}
{/* Available Preset Providers */}
{availablePresets.length > 0 && (
<div className="space-y-3">
<h4 className="text-sm font-medium">Add Provider</h4>
<div className="grid grid-cols-1 md:grid-cols-2 gap-3">
{availablePresets.map((preset) => (
<Card key={preset.id}>
<CardContent className="p-4 space-y-3">
<div className="flex items-center justify-between">
<h5 className="font-medium">{preset.name}</h5>
{preset.apiKeysURL && (
<button
type="button"
className="text-xs text-muted-foreground underline hover:text-foreground"
onClick={() => window.open(preset.apiKeysURL, '_blank')}
>
Get API key
</button>
)}
</div>
<div className="flex gap-2">
{!preset.nostr && (
<Input
placeholder="Enter your API key"
type="password"
className="flex-1"
value={presetApiKeys[preset.id] || ''}
onChange={(e) => setPresetApiKeys(prev => ({
...prev,
[preset.id]: e.target.value,
}))}
onKeyDown={(e) => {
if (e.key === 'Enter' && presetApiKeys[preset.id]?.trim()) {
handleAddPresetProvider(preset);
}
}}
/>
)}
<Button
onClick={() => handleAddPresetProvider(preset)}
disabled={!!preset.apiKeysURL && !presetApiKeys[preset.id]?.trim()}
variant="ghost"
size="sm"
onClick={(e) => {
e.stopPropagation();
handleRemoveProvider(providerId);
}}
className="h-8 w-8 p-0 text-muted-foreground hover:text-destructive"
>
Add
<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>
</CardContent>
</Card>
))}
</div>
</div>
)}
{availablePresets.length > 0 && <Separator />}
{/* Custom Provider */}
<div className="space-y-3">
<h4 className="text-sm font-medium">Add Custom Provider</h4>
<Card>
<CardContent className="p-4 space-y-3">
<div className="grid gap-2">
<Label htmlFor="custom-name">Provider Name</Label>
<Input
id="custom-name"
placeholder="e.g., my-custom-api"
value={customProviderName}
onChange={(e) => setCustomProviderName(e.target.value)}
/>
</div>
<div className="grid gap-2">
<Label htmlFor="custom-baseurl">Base URL</Label>
<Input
id="custom-baseurl"
placeholder="https://api.example.com/v1"
value={customBaseURL}
onChange={(e) => setCustomBaseURL(e.target.value)}
/>
</div>
<div className="grid gap-2">
<Label htmlFor="custom-auth">Authentication</Label>
<Select
value={customAuthMethod}
onValueChange={(value: 'api-key' | 'nostr') => {
setCustomAuthMethod(value);
if (value === 'nostr') {
setCustomApiKey(''); // Clear API key when switching to Nostr auth
}
}}
>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="api-key">API Key</SelectItem>
<SelectItem value="nostr">Nostr</SelectItem>
</SelectContent>
</Select>
</div>
{customAuthMethod === 'api-key' && (
<div className="grid gap-2">
<Label htmlFor="custom-apikey">API Key</Label>
<Input
id="custom-apikey"
type="password"
placeholder="Enter your API key (optional)"
value={customApiKey}
onChange={(e) => setCustomApiKey(e.target.value)}
/>
</div>
)}
<Button
onClick={handleAddCustomProvider}
disabled={
!customProviderName.trim() ||
!customBaseURL.trim() ||
customProviderName.trim() in settings.providers
}
size="sm"
className="gap-2"
>
<Check className="h-4 w-4" />
Add Custom Provider
</Button>
{customProviderName.trim() in settings.providers && (
<p className="text-sm text-destructive">
Provider with this name already exists
</p>
)}
</CardContent>
</Card>
</AccordionTrigger>
<AccordionContent className="px-4 pb-4">
<div className="space-y-3">
<div className="grid gap-2">
<Label htmlFor={`${providerId}-baseURL`}>Base URL</Label>
<Input
id={`${providerId}-baseURL`}
placeholder="https://api.example.com/v1"
value={provider?.baseURL || ''}
onChange={(e) => handleUpdateProvider(providerId, { baseURL: e.target.value })}
/>
</div>
<div className="grid gap-2">
<Label htmlFor={`${providerId}-auth`}>Authentication</Label>
<Select
value={provider?.nostr ? 'nostr' : 'api-key'}
onValueChange={(value: 'api-key' | 'nostr') => handleUpdateProvider(providerId, {
nostr: value === 'nostr' || undefined,
apiKey: value === 'nostr' ? undefined : provider?.apiKey
})}
>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="api-key">API Key</SelectItem>
<SelectItem value="nostr">Nostr</SelectItem>
</SelectContent>
</Select>
</div>
{!provider?.nostr && (
<div className="grid gap-2">
<Label htmlFor={`${providerId}-apiKey`}>API Key</Label>
<Input
id={`${providerId}-apiKey`}
type="password"
placeholder="Enter your API key"
value={provider?.apiKey || ''}
onChange={(e) => handleUpdateProvider(providerId, { apiKey: e.target.value })}
/>
</div>
)}
</div>
</AccordionContent>
</AccordionItem>
);
})}
</Accordion>
</div>
)}
{configuredProviderIds.length > 0 && availablePresets.length > 0 && <Separator />}
{/* Available Preset Providers */}
{availablePresets.length > 0 && (
<div className="space-y-3">
<h4 className="text-sm font-medium">Add Provider</h4>
<div className="grid grid-cols-1 md:grid-cols-2 gap-3">
{availablePresets.map((preset) => (
<div key={preset.id} className="border rounded-lg p-4 space-y-3">
<div className="flex items-center justify-between">
<h5 className="font-medium">{preset.name}</h5>
{preset.apiKeysURL && (
<button
type="button"
className="text-xs text-muted-foreground underline hover:text-foreground"
onClick={() => window.open(preset.apiKeysURL, '_blank')}
>
Get API key
</button>
)}
</div>
<div className="flex gap-2">
{!preset.nostr && (
<Input
placeholder="Enter your API key"
type="password"
className="flex-1"
value={presetApiKeys[preset.id] || ''}
onChange={(e) => setPresetApiKeys(prev => ({
...prev,
[preset.id]: e.target.value,
}))}
onKeyDown={(e) => {
if (e.key === 'Enter' && presetApiKeys[preset.id]?.trim()) {
handleAddPresetProvider(preset);
}
}}
/>
)}
<Button
onClick={() => handleAddPresetProvider(preset)}
disabled={!!preset.apiKeysURL && !presetApiKeys[preset.id]?.trim()}
size="sm"
>
Add
</Button>
</div>
</div>
))}
</div>
</CardContent>
</Card>
</div>
)}
{availablePresets.length > 0 && <Separator />}
{/* Custom Provider */}
<div className="space-y-3">
<h4 className="text-sm font-medium">Add Custom Provider</h4>
<div className="border rounded-lg p-4 space-y-3">
<div className="grid gap-2">
<Label htmlFor="custom-name">Provider Name</Label>
<Input
id="custom-name"
placeholder="e.g., my-custom-api"
value={customProviderName}
onChange={(e) => setCustomProviderName(e.target.value)}
/>
</div>
<div className="grid gap-2">
<Label htmlFor="custom-baseurl">Base URL</Label>
<Input
id="custom-baseurl"
placeholder="https://api.example.com/v1"
value={customBaseURL}
onChange={(e) => setCustomBaseURL(e.target.value)}
/>
</div>
<div className="grid gap-2">
<Label htmlFor="custom-auth">Authentication</Label>
<Select
value={customAuthMethod}
onValueChange={(value: 'api-key' | 'nostr') => {
setCustomAuthMethod(value);
if (value === 'nostr') {
setCustomApiKey(''); // Clear API key when switching to Nostr auth
}
}}
>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="api-key">API Key</SelectItem>
<SelectItem value="nostr">Nostr</SelectItem>
</SelectContent>
</Select>
</div>
{customAuthMethod === 'api-key' && (
<div className="grid gap-2">
<Label htmlFor="custom-apikey">API Key</Label>
<Input
id="custom-apikey"
type="password"
placeholder="Enter your API key (optional)"
value={customApiKey}
onChange={(e) => setCustomApiKey(e.target.value)}
/>
</div>
)}
<Button
onClick={handleAddCustomProvider}
disabled={
!customProviderName.trim() ||
!customBaseURL.trim() ||
customProviderName.trim() in settings.providers
}
size="sm"
className="gap-2"
>
<Check className="h-4 w-4" />
Add Custom Provider
</Button>
{customProviderName.trim() in settings.providers && (
<p className="text-sm text-destructive">
Provider with this name already exists
</p>
)}
</div>
</div>
</div>
</AppLayout>
</div>
);
}
+218 -213
View File
@@ -3,12 +3,11 @@ import { Check, GitBranch, ArrowLeft } from 'lucide-react';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { Label } from '@/components/ui/label';
import { Card, CardContent } from '@/components/ui/card';
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 { useIsMobile } from '@/hooks/useIsMobile';
import { useNavigate } from 'react-router-dom';
import type { GitCredential } from '@/contexts/GitSettingsContext';
@@ -39,6 +38,7 @@ const PRESET_PROVIDERS: PresetProvider[] = [
export function GitSettings() {
const { settings, addCredential, removeCredential, updateCredential } = useGitSettings();
const isMobile = useIsMobile();
const navigate = useNavigate();
const [customOrigin, setCustomOrigin] = useState('');
const [customUsername, setCustomUsername] = useState('');
@@ -95,220 +95,225 @@ export function GitSettings() {
const availablePresets = PRESET_PROVIDERS.filter(preset => !configuredOrigins.includes(preset.origin));
return (
<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">
{/* Configured Credentials */}
{configuredOrigins.length > 0 && (
<div className="space-y-3">
<h4 className="text-sm font-medium">Configured Credentials</h4>
<Accordion type="multiple" className="w-full space-y-2">
{configuredOrigins.map((origin) => {
const preset = PRESET_PROVIDERS.find(p => p.origin === origin);
const credential = settings.credentials[origin];
const isCustom = !preset;
return (
<AccordionItem key={origin} value={origin} className="border rounded-lg">
<AccordionTrigger className="px-4 py-3 hover:no-underline">
<div className="flex items-center justify-between w-full mr-3">
<div className="flex items-center gap-2">
<span className="font-medium">
{preset?.name || new URL(origin).hostname}
</span>
{isCustom && <Badge variant="outline">Custom</Badge>}
</div>
<button
type="button"
onClick={(e) => {
e.stopPropagation();
handleRemoveCredential(origin);
}}
className="h-8 w-8 p-0 text-muted-foreground hover:text-destructive rounded-md hover:bg-accent"
>
<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>
<AccordionContent className="px-4 pb-4">
<div className="space-y-3">
<div className="grid gap-2">
<Label htmlFor={`${origin}-origin`}>Origin</Label>
<Input
id={`${origin}-origin`}
placeholder="https://github.com"
value={origin}
disabled
className="bg-muted"
/>
</div>
<div className="grid gap-2">
<Label htmlFor={`${origin}-username`}>Username</Label>
<Input
id={`${origin}-username`}
placeholder="git"
value={credential?.username || ''}
onChange={(e) => handleUpdateCredential(origin, { username: e.target.value })}
/>
</div>
<div className="grid gap-2">
<Label htmlFor={`${origin}-password`}>Password</Label>
<Input
id={`${origin}-password`}
type="password"
placeholder="Enter your password/token"
value={credential?.password || ''}
onChange={(e) => handleUpdateCredential(origin, { password: e.target.value })}
/>
</div>
</div>
</AccordionContent>
</AccordionItem>
);
})}
</Accordion>
</div>
)}
{configuredOrigins.length > 0 && availablePresets.length > 0 && <Separator />}
{/* Available Preset Providers */}
{availablePresets.length > 0 && (
<div className="space-y-3">
<h4 className="text-sm font-medium">Add Provider</h4>
<div className="grid grid-cols-1 md:grid-cols-2 gap-3">
{availablePresets.map((preset) => (
<Card key={preset.id}>
<CardContent className="p-4 space-y-3">
<div className="flex items-center justify-between">
<h5 className="font-medium">{preset.name}</h5>
{preset.tokenURL && (
<button
type="button"
className="text-xs text-muted-foreground underline hover:text-foreground"
onClick={() => window.open(preset.tokenURL, '_blank')}
>
Get token
</button>
)}
</div>
<div className="flex gap-2">
<Input
placeholder="Enter your token"
type="password"
className="flex-1"
value={presetTokens[preset.id] || ''}
onChange={(e) => setPresetTokens(prev => ({
...prev,
[preset.id]: e.target.value,
}))}
onKeyDown={(e) => {
if (e.key === 'Enter' && presetTokens[preset.id]?.trim()) {
handleAddPresetProvider(preset);
}
}}
/>
<Button
onClick={() => handleAddPresetProvider(preset)}
disabled={!presetTokens[preset.id]?.trim()}
size="sm"
>
Add
</Button>
</div>
</CardContent>
</Card>
))}
</div>
</div>
)}
{availablePresets.length > 0 && <Separator />}
{/* Custom Provider */}
<div className="space-y-3">
<h4 className="text-sm font-medium">Add Custom Provider</h4>
<Card>
<CardContent className="p-4 space-y-3">
<div className="grid gap-2">
<Label htmlFor="custom-origin">Origin</Label>
<Input
id="custom-origin"
placeholder="https://git.example.com"
value={customOrigin}
onChange={(e) => setCustomOrigin(e.target.value)}
/>
</div>
<div className="grid gap-2">
<Label htmlFor="custom-username">Username</Label>
<Input
id="custom-username"
placeholder="git"
value={customUsername}
onChange={(e) => setCustomUsername(e.target.value)}
/>
</div>
<div className="grid gap-2">
<Label htmlFor="custom-password">Password</Label>
<Input
id="custom-password"
type="password"
placeholder="Enter your password/token"
value={customPassword}
onChange={(e) => setCustomPassword(e.target.value)}
/>
</div>
<Button
onClick={handleAddCustomProvider}
disabled={
!customOrigin.trim() ||
!customUsername.trim() ||
!customPassword.trim() ||
customOrigin.trim() in settings.credentials
}
size="sm"
className="gap-2"
>
<Check className="h-4 w-4" />
Add Custom Provider
</Button>
{customOrigin.trim() in settings.credentials && (
<p className="text-sm text-destructive">
Credentials for this origin already exist
</p>
)}
</CardContent>
</Card>
<div className="p-6 space-y-6">
{isMobile && (
<div className="space-y-3">
<Button
variant="ghost"
size="sm"
onClick={() => navigate('/settings')}
className="h-8 w-auto px-2 -ml-2"
>
<ArrowLeft className="h-4 w-4 mr-2" />
Back to Settings
</Button>
<div className="space-y-2">
<h1 className="text-2xl font-bold flex items-center gap-3">
<GitBranch className="h-6 w-6 text-primary" />
Git Settings
</h1>
<p className="text-muted-foreground">
Configure Git credentials for HTTP authentication. Settings are automatically saved and stored locally in your browser.
</p>
</div>
</div>
)}
{!isMobile && (
<div className="space-y-2">
<h1 className="text-2xl font-bold flex items-center gap-3">
<GitBranch className="h-6 w-6 text-primary" />
Git Settings
</h1>
<p className="text-muted-foreground">
Configure Git credentials for HTTP authentication. Settings are automatically saved and stored locally in your browser.
</p>
</div>
)}
<div className="space-y-6">
{/* Configured Credentials */}
{configuredOrigins.length > 0 && (
<div className="space-y-3">
<h4 className="text-sm font-medium">Configured Credentials</h4>
<Accordion type="multiple" className="w-full space-y-2">
{configuredOrigins.map((origin) => {
const preset = PRESET_PROVIDERS.find(p => p.origin === origin);
const credential = settings.credentials[origin];
const isCustom = !preset;
return (
<AccordionItem key={origin} value={origin} className="border rounded-lg">
<AccordionTrigger className="px-4 py-3 hover:no-underline">
<div className="flex items-center justify-between w-full mr-3">
<div className="flex items-center gap-2">
<span className="font-medium">
{preset?.name || new URL(origin).hostname}
</span>
{isCustom && <Badge variant="outline">Custom</Badge>}
</div>
<button
type="button"
onClick={(e) => {
e.stopPropagation();
handleRemoveCredential(origin);
}}
className="h-8 w-8 p-0 text-muted-foreground hover:text-destructive rounded-md hover:bg-accent"
>
<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>
<AccordionContent className="px-4 pb-4">
<div className="space-y-3">
<div className="grid gap-2">
<Label htmlFor={`${origin}-origin`}>Origin</Label>
<Input
id={`${origin}-origin`}
placeholder="https://github.com"
value={origin}
disabled
className="bg-muted"
/>
</div>
<div className="grid gap-2">
<Label htmlFor={`${origin}-username`}>Username</Label>
<Input
id={`${origin}-username`}
placeholder="git"
value={credential?.username || ''}
onChange={(e) => handleUpdateCredential(origin, { username: e.target.value })}
/>
</div>
<div className="grid gap-2">
<Label htmlFor={`${origin}-password`}>Password</Label>
<Input
id={`${origin}-password`}
type="password"
placeholder="Enter your password/token"
value={credential?.password || ''}
onChange={(e) => handleUpdateCredential(origin, { password: e.target.value })}
/>
</div>
</div>
</AccordionContent>
</AccordionItem>
);
})}
</Accordion>
</div>
)}
{configuredOrigins.length > 0 && availablePresets.length > 0 && <Separator />}
{/* Available Preset Providers */}
{availablePresets.length > 0 && (
<div className="space-y-3">
<h4 className="text-sm font-medium">Add Provider</h4>
<div className="grid grid-cols-1 md:grid-cols-2 gap-3">
{availablePresets.map((preset) => (
<div key={preset.id} className="border rounded-lg p-4 space-y-3">
<div className="flex items-center justify-between">
<h5 className="font-medium">{preset.name}</h5>
{preset.tokenURL && (
<button
type="button"
className="text-xs text-muted-foreground underline hover:text-foreground"
onClick={() => window.open(preset.tokenURL, '_blank')}
>
Get token
</button>
)}
</div>
<div className="flex gap-2">
<Input
placeholder="Enter your token"
type="password"
className="flex-1"
value={presetTokens[preset.id] || ''}
onChange={(e) => setPresetTokens(prev => ({
...prev,
[preset.id]: e.target.value,
}))}
onKeyDown={(e) => {
if (e.key === 'Enter' && presetTokens[preset.id]?.trim()) {
handleAddPresetProvider(preset);
}
}}
/>
<Button
onClick={() => handleAddPresetProvider(preset)}
disabled={!presetTokens[preset.id]?.trim()}
size="sm"
>
Add
</Button>
</div>
</div>
))}
</div>
</CardContent>
</Card>
</div>
)}
{availablePresets.length > 0 && <Separator />}
{/* Custom Provider */}
<div className="space-y-3">
<h4 className="text-sm font-medium">Add Custom Provider</h4>
<div className="border rounded-lg p-4 space-y-3">
<div className="grid gap-2">
<Label htmlFor="custom-origin">Origin</Label>
<Input
id="custom-origin"
placeholder="https://git.example.com"
value={customOrigin}
onChange={(e) => setCustomOrigin(e.target.value)}
/>
</div>
<div className="grid gap-2">
<Label htmlFor="custom-username">Username</Label>
<Input
id="custom-username"
placeholder="git"
value={customUsername}
onChange={(e) => setCustomUsername(e.target.value)}
/>
</div>
<div className="grid gap-2">
<Label htmlFor="custom-password">Password</Label>
<Input
id="custom-password"
type="password"
placeholder="Enter your password/token"
value={customPassword}
onChange={(e) => setCustomPassword(e.target.value)}
/>
</div>
<Button
onClick={handleAddCustomProvider}
disabled={
!customOrigin.trim() ||
!customUsername.trim() ||
!customPassword.trim() ||
customOrigin.trim() in settings.credentials
}
size="sm"
className="gap-2"
>
<Check className="h-4 w-4" />
Add Custom Provider
</Button>
{customOrigin.trim() in settings.credentials && (
<p className="text-sm text-destructive">
Credentials for this origin already exist
</p>
)}
</div>
</div>
</div>
</AppLayout>
</div>
);
}
+57 -63
View File
@@ -1,72 +1,66 @@
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';
import { Bot, GitBranch } from 'lucide-react';
import { useIsMobile } from '@/hooks/useIsMobile';
interface SettingsItem {
id: string;
title: string;
description: string;
icon: React.ComponentType<{ className?: string }>;
href: string;
}
const settingsItems: SettingsItem[] = [
{
id: 'ai',
title: 'AI Settings',
description: 'Configure AI providers and API keys',
icon: Bot,
href: '/settings/ai',
},
{
id: 'git',
title: 'Git Settings',
description: 'Configure Git credentials for HTTP authentication',
icon: GitBranch,
href: '/settings/git',
},
];
export function Settings() {
const navigate = useNavigate();
const isMobile = useIsMobile();
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>
if (isMobile) {
return (
<div className="p-6 space-y-4">
<div className="space-y-2">
<h2 className="text-xl font-bold">Settings</h2>
<p className="text-muted-foreground">
Manage your application settings and preferences.
</p>
</div>
<div className="space-y-3">
{settingsItems.map((item) => {
const Icon = item.icon;
return (
<div
key={item.id}
className="flex items-center gap-3 p-4 rounded-lg border hover:border-primary/20 hover:bg-primary/5 cursor-pointer transition-colors"
onClick={() => navigate(item.href)}
>
<Icon className="h-5 w-5 text-primary flex-shrink-0" />
<div className="flex-1 min-w-0">
<div className="font-medium">{item.title}</div>
<div className="text-sm text-muted-foreground">{item.description}</div>
</div>
</div>
);
})}
</div>
</div>
</AppLayout>
);
);
}
}
export default Settings;