mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-05 16:23:36 +00:00
Add loading skeletons to settings pages
This commit is contained in:
3 files changed
+1162
-1072
No files matched your search
+405
-377
@@ -33,6 +33,7 @@ import { CreditsBadge } from '@/components/CreditsBadge';
|
||||
import { CreditsDialog } from '@/components/CreditsDialog';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||
import { Separator } from '@/components/ui/separator';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { useAISettings } from '@/hooks/useAISettings';
|
||||
import { useIsMobile } from '@/hooks/useIsMobile';
|
||||
import { useCurrentUser } from '@/hooks/useCurrentUser';
|
||||
@@ -202,7 +203,7 @@ function generateIdFromName(name: string): string {
|
||||
|
||||
export function AISettings() {
|
||||
const { t } = useTranslation();
|
||||
const { settings, updateSettings, setProvider, removeProvider, setProviders } = useAISettings();
|
||||
const { settings, updateSettings, setProvider, removeProvider, setProviders, isLoading } = useAISettings();
|
||||
const isMobile = useIsMobile();
|
||||
const navigate = useNavigate();
|
||||
const { user } = useCurrentUser();
|
||||
@@ -387,395 +388,422 @@ export function AISettings() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="space-y-6">
|
||||
{/* Configured Providers */}
|
||||
{settings.providers.length > 0 && (
|
||||
{isLoading ? (
|
||||
<div className="space-y-6">
|
||||
{/* Loading skeleton for configured providers */}
|
||||
<div className="space-y-3">
|
||||
<h4 className="text-sm font-medium">{t('configuredProviders')}</h4>
|
||||
<DndContext
|
||||
sensors={sensors}
|
||||
collisionDetection={closestCenter}
|
||||
onDragEnd={handleDragEnd}
|
||||
>
|
||||
<SortableContext
|
||||
items={settings.providers.map(p => p.id)}
|
||||
strategy={verticalListSortingStrategy}
|
||||
>
|
||||
<Accordion type="multiple" className="w-full space-y-2">
|
||||
{settings.providers.map((provider) => {
|
||||
const preset = AI_PROVIDER_PRESETS.find(p => p.id === provider.id);
|
||||
|
||||
return (
|
||||
<SortableProviderItem
|
||||
key={provider.id}
|
||||
provider={provider}
|
||||
preset={preset}
|
||||
onRemove={handleRemoveProvider}
|
||||
onSetProvider={handleSetProvider}
|
||||
onOpenCreditsDialog={handleOpenCreditsDialog}
|
||||
showDragHandle={settings.providers.length > 1}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</Accordion>
|
||||
</SortableContext>
|
||||
</DndContext>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Available Preset Providers */}
|
||||
{availablePresets.length > 0 && (
|
||||
<div className="space-y-3">
|
||||
<h4 className="text-sm font-medium">{t('addProvider')}</h4>
|
||||
<div className="grid grid-cols-[repeat(auto-fit,minmax(min(280px,100%),1fr))] gap-3">
|
||||
{availablePresets.map((preset) => {
|
||||
const isNostrPreset = preset.nostr;
|
||||
const isLoggedIntoNostr = !!user;
|
||||
const showNostrLoginRequired = isNostrPreset && !isLoggedIntoNostr;
|
||||
|
||||
return (
|
||||
<Card key={preset.id}>
|
||||
<CardContent className="p-4 space-y-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<ExternalFavicon
|
||||
url={preset.baseURL}
|
||||
size={16}
|
||||
fallback={<Bot size={16} />}
|
||||
/>
|
||||
<h5 className="font-medium">{preset.name}</h5>
|
||||
</div>
|
||||
|
||||
{showNostrLoginRequired ? (
|
||||
<div className="space-y-2">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t('loginToNostrRequired')}
|
||||
</p>
|
||||
<Button
|
||||
asChild
|
||||
className="w-full"
|
||||
>
|
||||
<Link to="/settings/nostr">
|
||||
{t('goToNostrSettings')}
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
<div className="flex gap-2">
|
||||
{!preset.nostr && (
|
||||
<ExternalInput
|
||||
type="password"
|
||||
className="flex-1"
|
||||
placeholder={preset.id === "routstr" ? t('enterCashuToken') : t('enterApiKey')}
|
||||
value={presetApiKeys[preset.id] || ''}
|
||||
onChange={(e) => setPresetApiKeys(prev => ({
|
||||
...prev,
|
||||
[preset.id]: e.target.value,
|
||||
}))}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' &&
|
||||
presetApiKeys[preset.id]?.trim() &&
|
||||
presetTermsAgreements[preset.id]) {
|
||||
handleAddPresetProvider(preset);
|
||||
}
|
||||
}}
|
||||
url={preset.apiKeysURL}
|
||||
urlTitle="Get Key"
|
||||
/>
|
||||
)}
|
||||
<Button
|
||||
onClick={() => handleAddPresetProvider(preset)}
|
||||
disabled={
|
||||
!presetTermsAgreements[preset.id] ||
|
||||
(!!preset.apiKeysURL && !presetApiKeys[preset.id]?.trim())
|
||||
}
|
||||
className={preset.nostr ? "w-full" : "h-10 px-4 ml-auto"}
|
||||
>
|
||||
{t('add')}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Terms of Service Agreement */}
|
||||
<div className="flex items-center gap-1.5">
|
||||
<Checkbox
|
||||
id={`agree-terms-${preset.id}`}
|
||||
checked={presetTermsAgreements[preset.id] || false}
|
||||
onCheckedChange={(checked) => setPresetTermsAgreements(prev => ({
|
||||
...prev,
|
||||
[preset.id]: checked === true,
|
||||
}))}
|
||||
className="size-3 [&_svg]:size-3"
|
||||
/>
|
||||
<label
|
||||
htmlFor={`agree-terms-${preset.id}`}
|
||||
className="text-xs text-muted-foreground leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 cursor-pointer"
|
||||
>
|
||||
{t('agreeToTermsOfService', { providerName: preset.name })}{' '}
|
||||
{preset.tosURL ? (
|
||||
<a
|
||||
href={preset.tosURL}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="text-muted-foreground underline hover:text-foreground hover:no-underline"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{t('termsOfService')}
|
||||
</a>
|
||||
) : (
|
||||
t('termsOfService')
|
||||
)}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
})}
|
||||
<Skeleton className="h-4 w-40" />
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-16 w-full rounded-lg" />
|
||||
<Skeleton className="h-16 w-full rounded-lg" />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Custom Provider */}
|
||||
<div className="space-y-3">
|
||||
<Accordion type="single" collapsible className="w-full">
|
||||
<AccordionItem value="custom-provider">
|
||||
<AccordionTrigger className="px-4 py-3 hover:no-underline">
|
||||
<div className="flex items-center gap-2">
|
||||
<Plus className="h-4 w-4" />
|
||||
<h4 className="text-sm font-medium">{t('addCustomProvider')}</h4>
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-4 pb-4">
|
||||
<div className="space-y-3">
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-name">
|
||||
{t('name')} <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="custom-name"
|
||||
placeholder="e.g., My Custom API"
|
||||
value={customProviderName}
|
||||
onChange={(e) => {
|
||||
const newName = e.target.value;
|
||||
setCustomProviderName(newName);
|
||||
{/* Loading skeleton for add provider section */}
|
||||
<div className="space-y-3">
|
||||
<Skeleton className="h-4 w-32" />
|
||||
<div className="grid grid-cols-[repeat(auto-fit,minmax(min(280px,100%),1fr))] gap-3">
|
||||
<Skeleton className="h-32 w-full rounded-lg" />
|
||||
<Skeleton className="h-32 w-full rounded-lg" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
// Auto-generate ID from name if ID hasn't been manually edited
|
||||
if (!customIdManuallyEdited) {
|
||||
setCustomProviderId(generateIdFromName(newName));
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-id">
|
||||
{t('id')} <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="custom-id"
|
||||
placeholder="e.g., my-custom-api"
|
||||
value={customProviderId}
|
||||
onChange={(e) => {
|
||||
setCustomProviderId(e.target.value);
|
||||
setCustomIdManuallyEdited(true);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-baseurl">
|
||||
{t('baseUrl')} <span className="text-destructive">*</span>
|
||||
</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">{t('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">{t('apiKey')}</SelectItem>
|
||||
<SelectItem value="nostr">Nostr</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
{customAuthMethod === 'api-key' && (
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-apikey">{t('apiKey')}</Label>
|
||||
<PasswordInput
|
||||
id="custom-apikey"
|
||||
placeholder={t('enterApiKey') + ' (optional)'}
|
||||
value={customApiKey}
|
||||
onChange={(e) => setCustomApiKey(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex items-center gap-2">
|
||||
<Checkbox
|
||||
id="custom-proxy"
|
||||
checked={customProxy}
|
||||
onCheckedChange={(checked) => setCustomProxy(checked === true)}
|
||||
/>
|
||||
<Label htmlFor="custom-proxy" className="cursor-pointer">
|
||||
{t('useCorsProxy')}
|
||||
</Label>
|
||||
</div>
|
||||
<Button
|
||||
onClick={handleAddCustomProvider}
|
||||
disabled={
|
||||
!customProviderName.trim() ||
|
||||
!customProviderId.trim() ||
|
||||
!customBaseURL.trim() ||
|
||||
settings.providers.some(p => p.id === customProviderId.trim())
|
||||
}
|
||||
className="gap-2 ml-auto"
|
||||
>
|
||||
<Check className="h-4 w-4" />
|
||||
{t('addCustomProviderButton')}
|
||||
</Button>
|
||||
{settings.providers.some(p => p.id === customProviderId.trim()) && (
|
||||
<p className="text-sm text-destructive">
|
||||
{t('providerExists')}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
{/* Loading skeleton for custom provider */}
|
||||
<div className="space-y-3">
|
||||
<Skeleton className="h-16 w-full rounded-lg" />
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-6">
|
||||
{/* Configured Providers */}
|
||||
{settings.providers.length > 0 && (
|
||||
<div className="space-y-3">
|
||||
<h4 className="text-sm font-medium">{t('configuredProviders')}</h4>
|
||||
<DndContext
|
||||
sensors={sensors}
|
||||
collisionDetection={closestCenter}
|
||||
onDragEnd={handleDragEnd}
|
||||
>
|
||||
<SortableContext
|
||||
items={settings.providers.map(p => p.id)}
|
||||
strategy={verticalListSortingStrategy}
|
||||
>
|
||||
<Accordion type="multiple" className="w-full space-y-2">
|
||||
{settings.providers.map((provider) => {
|
||||
const preset = AI_PROVIDER_PRESETS.find(p => p.id === provider.id);
|
||||
|
||||
{/* Advanced Settings */}
|
||||
<div className="space-y-4">
|
||||
<Separator className="my-6" />
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowAdvanced(!showAdvanced)}
|
||||
className="flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground transition-colors"
|
||||
>
|
||||
<span>{t('advanced')}</span>
|
||||
<ChevronDown
|
||||
className={`h-4 w-4 transition-transform ${showAdvanced ? 'rotate-180' : ''}`}
|
||||
/>
|
||||
</button>
|
||||
|
||||
{showAdvanced && (
|
||||
<div className="space-y-6">
|
||||
{/* Image Model Configuration */}
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Bot className="h-5 w-5 text-primary" />
|
||||
<h3 className="text-lg font-semibold">{t('imageModel')}</h3>
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t('imageModelDescription')}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<ModelInput
|
||||
value={settings.imageModel || ''}
|
||||
onChange={(value) => updateSettings({ imageModel: value || undefined })}
|
||||
className="flex-1"
|
||||
modelFilter={imageModelFilter}
|
||||
/>
|
||||
{settings.imageModel && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => updateSettings({ imageModel: undefined })}
|
||||
className="h-10 px-3"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<Separator />
|
||||
|
||||
{/* Project Templates Section */}
|
||||
<ProjectTemplatesSection />
|
||||
<Separator />
|
||||
|
||||
{/* MCP Servers Section */}
|
||||
<MCPServersSection />
|
||||
<Separator />
|
||||
|
||||
{/* Plugins Section */}
|
||||
<PluginsSection />
|
||||
<Separator />
|
||||
|
||||
{/* System Prompt Configuration */}
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<FileText className="h-5 w-5 text-primary" />
|
||||
<h3 className="text-lg font-semibold">{t('systemPrompt')}</h3>
|
||||
{isSystemPromptModified && (
|
||||
<div className="h-2 w-2 rounded-full bg-yellow-500" title={t('modified')} />
|
||||
)}
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t('systemPromptDescription')}
|
||||
</p>
|
||||
</div>
|
||||
<Accordion type="single" collapsible className="w-full">
|
||||
<AccordionItem value="system-prompt" className="border rounded-lg">
|
||||
<AccordionTrigger className="px-4 py-3 hover:no-underline">
|
||||
<div className="flex items-center gap-2">
|
||||
<Edit className="h-4 w-4" />
|
||||
<span className="font-medium">{t('systemPrompt')}</span>
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-4 pb-4">
|
||||
<div className="space-y-2">
|
||||
<Textarea
|
||||
id="system-prompt"
|
||||
placeholder="Enter EJS template..."
|
||||
value={systemPromptInput}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
setSystemPromptInput(value);
|
||||
updateConfig((current) => ({
|
||||
...current,
|
||||
systemPrompt: value,
|
||||
}));
|
||||
}}
|
||||
className="flex-1 font-mono text-xs min-h-[400px]"
|
||||
return (
|
||||
<SortableProviderItem
|
||||
key={provider.id}
|
||||
provider={provider}
|
||||
preset={preset}
|
||||
onRemove={handleRemoveProvider}
|
||||
onSetProvider={handleSetProvider}
|
||||
onOpenCreditsDialog={handleOpenCreditsDialog}
|
||||
showDragHandle={settings.providers.length > 1}
|
||||
/>
|
||||
{isSystemPromptModified && (
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={restoreSystemPrompt}
|
||||
className="w-full"
|
||||
>
|
||||
<RotateCcw className="h-4 w-4 mr-2" />
|
||||
{t('restoreToDefault')}
|
||||
</Button>
|
||||
);
|
||||
})}
|
||||
</Accordion>
|
||||
</SortableContext>
|
||||
</DndContext>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Available Preset Providers */}
|
||||
{availablePresets.length > 0 && (
|
||||
<div className="space-y-3">
|
||||
<h4 className="text-sm font-medium">{t('addProvider')}</h4>
|
||||
<div className="grid grid-cols-[repeat(auto-fit,minmax(min(280px,100%),1fr))] gap-3">
|
||||
{availablePresets.map((preset) => {
|
||||
const isNostrPreset = preset.nostr;
|
||||
const isLoggedIntoNostr = !!user;
|
||||
const showNostrLoginRequired = isNostrPreset && !isLoggedIntoNostr;
|
||||
|
||||
return (
|
||||
<Card key={preset.id}>
|
||||
<CardContent className="p-4 space-y-3">
|
||||
<div className="flex items-center gap-2">
|
||||
<ExternalFavicon
|
||||
url={preset.baseURL}
|
||||
size={16}
|
||||
fallback={<Bot size={16} />}
|
||||
/>
|
||||
<h5 className="font-medium">{preset.name}</h5>
|
||||
</div>
|
||||
|
||||
{showNostrLoginRequired ? (
|
||||
<div className="space-y-2">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t('loginToNostrRequired')}
|
||||
</p>
|
||||
<Button
|
||||
asChild
|
||||
className="w-full"
|
||||
>
|
||||
<Link to="/settings/nostr">
|
||||
{t('goToNostrSettings')}
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-2">
|
||||
<div className="flex gap-2">
|
||||
{!preset.nostr && (
|
||||
<ExternalInput
|
||||
type="password"
|
||||
className="flex-1"
|
||||
placeholder={preset.id === "routstr" ? t('enterCashuToken') : t('enterApiKey')}
|
||||
value={presetApiKeys[preset.id] || ''}
|
||||
onChange={(e) => setPresetApiKeys(prev => ({
|
||||
...prev,
|
||||
[preset.id]: e.target.value,
|
||||
}))}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' &&
|
||||
presetApiKeys[preset.id]?.trim() &&
|
||||
presetTermsAgreements[preset.id]) {
|
||||
handleAddPresetProvider(preset);
|
||||
}
|
||||
}}
|
||||
url={preset.apiKeysURL}
|
||||
urlTitle="Get Key"
|
||||
/>
|
||||
)}
|
||||
<Button
|
||||
onClick={() => handleAddPresetProvider(preset)}
|
||||
disabled={
|
||||
!presetTermsAgreements[preset.id] ||
|
||||
(!!preset.apiKeysURL && !presetApiKeys[preset.id]?.trim())
|
||||
}
|
||||
className={preset.nostr ? "w-full" : "h-10 px-4 ml-auto"}
|
||||
>
|
||||
{t('add')}
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
{/* Terms of Service Agreement */}
|
||||
<div className="flex items-center gap-1.5">
|
||||
<Checkbox
|
||||
id={`agree-terms-${preset.id}`}
|
||||
checked={presetTermsAgreements[preset.id] || false}
|
||||
onCheckedChange={(checked) => setPresetTermsAgreements(prev => ({
|
||||
...prev,
|
||||
[preset.id]: checked === true,
|
||||
}))}
|
||||
className="size-3 [&_svg]:size-3"
|
||||
/>
|
||||
<label
|
||||
htmlFor={`agree-terms-${preset.id}`}
|
||||
className="text-xs text-muted-foreground leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70 cursor-pointer"
|
||||
>
|
||||
{t('agreeToTermsOfService', { providerName: preset.name })}{' '}
|
||||
{preset.tosURL ? (
|
||||
<a
|
||||
href={preset.tosURL}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="text-muted-foreground underline hover:text-foreground hover:no-underline"
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
>
|
||||
{t('termsOfService')}
|
||||
</a>
|
||||
) : (
|
||||
t('termsOfService')
|
||||
)}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Custom Provider */}
|
||||
<div className="space-y-3">
|
||||
<Accordion type="single" collapsible className="w-full">
|
||||
<AccordionItem value="custom-provider">
|
||||
<AccordionTrigger className="px-4 py-3 hover:no-underline">
|
||||
<div className="flex items-center gap-2">
|
||||
<Plus className="h-4 w-4" />
|
||||
<h4 className="text-sm font-medium">{t('addCustomProvider')}</h4>
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-4 pb-4">
|
||||
<div className="space-y-3">
|
||||
<div className="grid grid-cols-2 gap-3">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-name">
|
||||
{t('name')} <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="custom-name"
|
||||
placeholder="e.g., My Custom API"
|
||||
value={customProviderName}
|
||||
onChange={(e) => {
|
||||
const newName = e.target.value;
|
||||
setCustomProviderName(newName);
|
||||
|
||||
// Auto-generate ID from name if ID hasn't been manually edited
|
||||
if (!customIdManuallyEdited) {
|
||||
setCustomProviderId(generateIdFromName(newName));
|
||||
}
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-id">
|
||||
{t('id')} <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="custom-id"
|
||||
placeholder="e.g., my-custom-api"
|
||||
value={customProviderId}
|
||||
onChange={(e) => {
|
||||
setCustomProviderId(e.target.value);
|
||||
setCustomIdManuallyEdited(true);
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-baseurl">
|
||||
{t('baseUrl')} <span className="text-destructive">*</span>
|
||||
</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">{t('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">{t('apiKey')}</SelectItem>
|
||||
<SelectItem value="nostr">Nostr</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
{customAuthMethod === 'api-key' && (
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-apikey">{t('apiKey')}</Label>
|
||||
<PasswordInput
|
||||
id="custom-apikey"
|
||||
placeholder={t('enterApiKey') + ' (optional)'}
|
||||
value={customApiKey}
|
||||
onChange={(e) => setCustomApiKey(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className="flex items-center gap-2">
|
||||
<Checkbox
|
||||
id="custom-proxy"
|
||||
checked={customProxy}
|
||||
onCheckedChange={(checked) => setCustomProxy(checked === true)}
|
||||
/>
|
||||
<Label htmlFor="custom-proxy" className="cursor-pointer">
|
||||
{t('useCorsProxy')}
|
||||
</Label>
|
||||
</div>
|
||||
<Button
|
||||
onClick={handleAddCustomProvider}
|
||||
disabled={
|
||||
!customProviderName.trim() ||
|
||||
!customProviderId.trim() ||
|
||||
!customBaseURL.trim() ||
|
||||
settings.providers.some(p => p.id === customProviderId.trim())
|
||||
}
|
||||
className="gap-2 ml-auto"
|
||||
>
|
||||
<Check className="h-4 w-4" />
|
||||
{t('addCustomProviderButton')}
|
||||
</Button>
|
||||
{settings.providers.some(p => p.id === customProviderId.trim()) && (
|
||||
<p className="text-sm text-destructive">
|
||||
{t('providerExists')}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
</div>
|
||||
|
||||
{/* Advanced Settings */}
|
||||
<div className="space-y-4">
|
||||
<Separator className="my-6" />
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setShowAdvanced(!showAdvanced)}
|
||||
className="flex items-center gap-2 text-sm text-muted-foreground hover:text-foreground transition-colors"
|
||||
>
|
||||
<span>{t('advanced')}</span>
|
||||
<ChevronDown
|
||||
className={`h-4 w-4 transition-transform ${showAdvanced ? 'rotate-180' : ''}`}
|
||||
/>
|
||||
</button>
|
||||
|
||||
{showAdvanced && (
|
||||
<div className="space-y-6">
|
||||
{/* Image Model Configuration */}
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Bot className="h-5 w-5 text-primary" />
|
||||
<h3 className="text-lg font-semibold">{t('imageModel')}</h3>
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t('imageModelDescription')}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex items-center gap-2">
|
||||
<ModelInput
|
||||
value={settings.imageModel || ''}
|
||||
onChange={(value) => updateSettings({ imageModel: value || undefined })}
|
||||
className="flex-1"
|
||||
modelFilter={imageModelFilter}
|
||||
/>
|
||||
{settings.imageModel && (
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="sm"
|
||||
onClick={() => updateSettings({ imageModel: undefined })}
|
||||
className="h-10 px-3"
|
||||
>
|
||||
<X className="h-4 w-4" />
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<Separator />
|
||||
|
||||
{/* Project Templates Section */}
|
||||
<ProjectTemplatesSection />
|
||||
<Separator />
|
||||
|
||||
{/* MCP Servers Section */}
|
||||
<MCPServersSection />
|
||||
<Separator />
|
||||
|
||||
{/* Plugins Section */}
|
||||
<PluginsSection />
|
||||
<Separator />
|
||||
|
||||
{/* System Prompt Configuration */}
|
||||
<div className="space-y-4">
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<FileText className="h-5 w-5 text-primary" />
|
||||
<h3 className="text-lg font-semibold">{t('systemPrompt')}</h3>
|
||||
{isSystemPromptModified && (
|
||||
<div className="h-2 w-2 rounded-full bg-yellow-500" title={t('modified')} />
|
||||
)}
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t('systemPromptDescription')}
|
||||
</p>
|
||||
</div>
|
||||
<Accordion type="single" collapsible className="w-full">
|
||||
<AccordionItem value="system-prompt" className="border rounded-lg">
|
||||
<AccordionTrigger className="px-4 py-3 hover:no-underline">
|
||||
<div className="flex items-center gap-2">
|
||||
<Edit className="h-4 w-4" />
|
||||
<span className="font-medium">{t('systemPrompt')}</span>
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-4 pb-4">
|
||||
<div className="space-y-2">
|
||||
<Textarea
|
||||
id="system-prompt"
|
||||
placeholder="Enter EJS template..."
|
||||
value={systemPromptInput}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
setSystemPromptInput(value);
|
||||
updateConfig((current) => ({
|
||||
...current,
|
||||
systemPrompt: value,
|
||||
}));
|
||||
}}
|
||||
className="flex-1 font-mono text-xs min-h-[400px]"
|
||||
/>
|
||||
{isSystemPromptModified && (
|
||||
<Button
|
||||
variant="outline"
|
||||
onClick={restoreSystemPrompt}
|
||||
className="w-full"
|
||||
>
|
||||
<RotateCcw className="h-4 w-4 mr-2" />
|
||||
{t('restoreToDefault')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Render credits dialog outside of accordion structure */}
|
||||
{activeCreditsDialog && (() => {
|
||||
|
||||
+442
-413
@@ -35,6 +35,7 @@ import { Label } from '@/components/ui/label';
|
||||
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion';
|
||||
import { Card, CardContent } from '@/components/ui/card';
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import { useDeploySettings } from '@/hooks/useDeploySettings';
|
||||
import { useNetlifyOAuth } from '@/hooks/useNetlifyOAuth';
|
||||
import { useVercelOAuth } from '@/hooks/useVercelOAuth';
|
||||
@@ -424,7 +425,7 @@ function getProviderUrl(provider: DeployProvider | PresetProvider): string | nul
|
||||
|
||||
export function DeploySettings() {
|
||||
const { t } = useTranslation();
|
||||
const { settings, removeProvider, setProviders } = useDeploySettings();
|
||||
const { settings, removeProvider, setProviders, isInitialized } = useDeploySettings();
|
||||
const { user } = useCurrentUser();
|
||||
const isMobile = useIsMobile();
|
||||
const navigate = useNavigate();
|
||||
@@ -704,455 +705,483 @@ export function DeploySettings() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="space-y-6">
|
||||
{/* Configured Providers */}
|
||||
{settings.providers.length > 0 && (
|
||||
{!isInitialized ? (
|
||||
<div className="space-y-6">
|
||||
{/* Loading skeleton for configured providers */}
|
||||
<div className="space-y-3">
|
||||
<h4 className="text-sm font-medium">{t('configuredProviders')}</h4>
|
||||
<DndContext
|
||||
sensors={sensors}
|
||||
collisionDetection={closestCenter}
|
||||
onDragEnd={handleDragEnd}
|
||||
>
|
||||
<SortableContext
|
||||
items={settings.providers.map((_, index) => index)}
|
||||
strategy={verticalListSortingStrategy}
|
||||
>
|
||||
<Accordion type="multiple" className="w-full space-y-2">
|
||||
{settings.providers.map((provider, index) => {
|
||||
const preset = PRESET_PROVIDERS.find(p => p.type === provider.type);
|
||||
|
||||
return (
|
||||
<SortableProviderItem
|
||||
key={index}
|
||||
provider={provider}
|
||||
index={index}
|
||||
preset={preset}
|
||||
onRemove={handleRemoveProvider}
|
||||
onUpdate={handleUpdateProvider}
|
||||
showDragHandle={settings.providers.length > 1}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</Accordion>
|
||||
</SortableContext>
|
||||
</DndContext>
|
||||
<Skeleton className="h-4 w-40" />
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-16 w-full rounded-lg" />
|
||||
<Skeleton className="h-16 w-full rounded-lg" />
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Available Preset Providers */}
|
||||
{availablePresets.length > 0 && (
|
||||
{/* Loading skeleton for add provider section */}
|
||||
<div className="space-y-3">
|
||||
<h4 className="text-sm font-medium">{t('addProvider')}</h4>
|
||||
<Skeleton className="h-4 w-32" />
|
||||
<div className="grid grid-cols-[repeat(auto-fit,minmax(min(280px,100%),1fr))] gap-3">
|
||||
{availablePresets.map((preset) => {
|
||||
const isNostrPreset = preset.requiresNostr;
|
||||
const isLoggedIntoNostr = !!user;
|
||||
const showNostrLoginRequired = isNostrPreset && !isLoggedIntoNostr;
|
||||
<Skeleton className="h-40 w-full rounded-lg" />
|
||||
<Skeleton className="h-40 w-full rounded-lg" />
|
||||
<Skeleton className="h-40 w-full rounded-lg" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
// Get OAuth hook for this preset
|
||||
const oauthHook = preset.type === 'netlify' ? netlifyOAuth :
|
||||
preset.type === 'vercel' ? vercelOAuth : null;
|
||||
const isOAuthConfigured = oauthHook?.isOAuthConfigured ?? false;
|
||||
const isOAuthLoading = oauthHook?.isLoading ?? false;
|
||||
const oauthError = oauthHook?.error ?? null;
|
||||
{/* Loading skeleton for custom provider */}
|
||||
<div className="space-y-3">
|
||||
<Skeleton className="h-16 w-full rounded-lg" />
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-6">
|
||||
{/* Configured Providers */}
|
||||
{settings.providers.length > 0 && (
|
||||
<div className="space-y-3">
|
||||
<h4 className="text-sm font-medium">{t('configuredProviders')}</h4>
|
||||
<DndContext
|
||||
sensors={sensors}
|
||||
collisionDetection={closestCenter}
|
||||
onDragEnd={handleDragEnd}
|
||||
>
|
||||
<SortableContext
|
||||
items={settings.providers.map((_, index) => index)}
|
||||
strategy={verticalListSortingStrategy}
|
||||
>
|
||||
<Accordion type="multiple" className="w-full space-y-2">
|
||||
{settings.providers.map((provider, index) => {
|
||||
const preset = PRESET_PROVIDERS.find(p => p.type === provider.type);
|
||||
|
||||
return (
|
||||
<Card key={preset.id}>
|
||||
<CardContent className="p-4 space-y-3">
|
||||
<div className="flex items-center gap-2">
|
||||
{(() => {
|
||||
const url = getProviderUrl(preset);
|
||||
return url ? (
|
||||
<ExternalFavicon
|
||||
url={url}
|
||||
size={16}
|
||||
fallback={<Rocket size={16} />}
|
||||
/>
|
||||
) : (
|
||||
<Rocket size={16} />
|
||||
);
|
||||
})()}
|
||||
<h5 className="font-medium">{preset.name}</h5>
|
||||
</div>
|
||||
<p className="text-sm text-muted-foreground">{preset.description}</p>
|
||||
return (
|
||||
<SortableProviderItem
|
||||
key={index}
|
||||
provider={provider}
|
||||
index={index}
|
||||
preset={preset}
|
||||
onRemove={handleRemoveProvider}
|
||||
onUpdate={handleUpdateProvider}
|
||||
showDragHandle={settings.providers.length > 1}
|
||||
/>
|
||||
);
|
||||
})}
|
||||
</Accordion>
|
||||
</SortableContext>
|
||||
</DndContext>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{showNostrLoginRequired ? (
|
||||
<div className="space-y-2">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t('loginToNostrRequired')}
|
||||
</p>
|
||||
<Button asChild className="w-full">
|
||||
<Link to="/settings/nostr">
|
||||
{t('goToNostrSettings')}
|
||||
</Link>
|
||||
</Button>
|
||||
{/* Available Preset Providers */}
|
||||
{availablePresets.length > 0 && (
|
||||
<div className="space-y-3">
|
||||
<h4 className="text-sm font-medium">{t('addProvider')}</h4>
|
||||
<div className="grid grid-cols-[repeat(auto-fit,minmax(min(280px,100%),1fr))] gap-3">
|
||||
{availablePresets.map((preset) => {
|
||||
const isNostrPreset = preset.requiresNostr;
|
||||
const isLoggedIntoNostr = !!user;
|
||||
const showNostrLoginRequired = isNostrPreset && !isLoggedIntoNostr;
|
||||
|
||||
// Get OAuth hook for this preset
|
||||
const oauthHook = preset.type === 'netlify' ? netlifyOAuth :
|
||||
preset.type === 'vercel' ? vercelOAuth : null;
|
||||
const isOAuthConfigured = oauthHook?.isOAuthConfigured ?? false;
|
||||
const isOAuthLoading = oauthHook?.isLoading ?? false;
|
||||
const oauthError = oauthHook?.error ?? null;
|
||||
|
||||
return (
|
||||
<Card key={preset.id}>
|
||||
<CardContent className="p-4 space-y-3">
|
||||
<div className="flex items-center gap-2">
|
||||
{(() => {
|
||||
const url = getProviderUrl(preset);
|
||||
return url ? (
|
||||
<ExternalFavicon
|
||||
url={url}
|
||||
size={16}
|
||||
fallback={<Rocket size={16} />}
|
||||
/>
|
||||
) : (
|
||||
<Rocket size={16} />
|
||||
);
|
||||
})()}
|
||||
<h5 className="font-medium">{preset.name}</h5>
|
||||
</div>
|
||||
) : isOAuthConfigured && !forceManualEntry[preset.id] ? (
|
||||
// Show OAuth button if OAuth is configured and not forced to manual
|
||||
<div className="space-y-3">
|
||||
<div className="flex gap-0">
|
||||
<Button
|
||||
onClick={() => oauthHook?.initiateOAuth()}
|
||||
disabled={isOAuthLoading}
|
||||
className="flex-1 rounded-r-none gap-2"
|
||||
variant="default"
|
||||
>
|
||||
{isOAuthLoading ? (
|
||||
<>
|
||||
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-white"></div>
|
||||
Connecting...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{(() => {
|
||||
const url = getProviderUrl(preset);
|
||||
return url ? (
|
||||
<ExternalFavicon
|
||||
url={url}
|
||||
size={16}
|
||||
fallback={<Rocket size={16} />}
|
||||
/>
|
||||
) : (
|
||||
<Rocket size={16} />
|
||||
);
|
||||
})()}
|
||||
<span className="truncate text-ellipsis overflow-hidden">
|
||||
Connect to {preset.name}
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="default"
|
||||
className="rounded-l-none border-l border-primary-foreground/20 px-2"
|
||||
disabled={isOAuthLoading}
|
||||
>
|
||||
<ChevronDown className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem
|
||||
onClick={() => setForceManualEntry(prev => ({ ...prev, [preset.id]: true }))}
|
||||
>
|
||||
Enter API key
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
{oauthError && (
|
||||
<p className="text-sm text-destructive">
|
||||
{oauthError}
|
||||
<p className="text-sm text-muted-foreground">{preset.description}</p>
|
||||
|
||||
{showNostrLoginRequired ? (
|
||||
<div className="space-y-2">
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t('loginToNostrRequired')}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<Button asChild className="w-full">
|
||||
<Link to="/settings/nostr">
|
||||
{t('goToNostrSettings')}
|
||||
</Link>
|
||||
</Button>
|
||||
</div>
|
||||
) : isOAuthConfigured && !forceManualEntry[preset.id] ? (
|
||||
// Show OAuth button if OAuth is configured and not forced to manual
|
||||
<div className="space-y-3">
|
||||
<div className="flex gap-0">
|
||||
<Button
|
||||
onClick={() => oauthHook?.initiateOAuth()}
|
||||
disabled={isOAuthLoading}
|
||||
className="flex-1 rounded-r-none gap-2"
|
||||
variant="default"
|
||||
>
|
||||
{isOAuthLoading ? (
|
||||
<>
|
||||
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-white"></div>
|
||||
Connecting...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{(() => {
|
||||
const url = getProviderUrl(preset);
|
||||
return url ? (
|
||||
<ExternalFavicon
|
||||
url={url}
|
||||
size={16}
|
||||
fallback={<Rocket size={16} />}
|
||||
/>
|
||||
) : (
|
||||
<Rocket size={16} />
|
||||
);
|
||||
})()}
|
||||
<span className="truncate text-ellipsis overflow-hidden">
|
||||
Connect to {preset.name}
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="default"
|
||||
className="rounded-l-none border-l border-primary-foreground/20 px-2"
|
||||
disabled={isOAuthLoading}
|
||||
>
|
||||
<ChevronDown className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem
|
||||
onClick={() => setForceManualEntry(prev => ({ ...prev, [preset.id]: true }))}
|
||||
>
|
||||
Enter API key
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
{oauthError && (
|
||||
<p className="text-sm text-destructive">
|
||||
{oauthError}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
// Show manual token input
|
||||
<div className="space-y-2">
|
||||
{!preset.requiresNostr && preset.type !== 'nsite' && (
|
||||
<>
|
||||
{preset.type === 'cloudflare' && (
|
||||
<ExternalInput
|
||||
type="text"
|
||||
placeholder={preset.accountIdLabel || 'Account ID'}
|
||||
value={presetApiKeys[`${preset.id}-accountId`] || ''}
|
||||
onChange={(e) => setPresetApiKeys(prev => ({
|
||||
...prev,
|
||||
[`${preset.id}-accountId`]: e.target.value,
|
||||
}))}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' && presetApiKeys[preset.id]?.trim() &&
|
||||
<div className="space-y-2">
|
||||
{!preset.requiresNostr && preset.type !== 'nsite' && (
|
||||
<>
|
||||
{preset.type === 'cloudflare' && (
|
||||
<ExternalInput
|
||||
type="text"
|
||||
placeholder={preset.accountIdLabel || 'Account ID'}
|
||||
value={presetApiKeys[`${preset.id}-accountId`] || ''}
|
||||
onChange={(e) => setPresetApiKeys(prev => ({
|
||||
...prev,
|
||||
[`${preset.id}-accountId`]: e.target.value,
|
||||
}))}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' && presetApiKeys[preset.id]?.trim() &&
|
||||
presetApiKeys[`${preset.id}-accountId`]?.trim()) {
|
||||
handleAddPresetProvider(preset);
|
||||
}
|
||||
}}
|
||||
url={preset.accountIdURL}
|
||||
urlTitle="Find ID"
|
||||
/>
|
||||
)}
|
||||
{preset.type === 'deno' && (
|
||||
handleAddPresetProvider(preset);
|
||||
}
|
||||
}}
|
||||
url={preset.accountIdURL}
|
||||
urlTitle="Find ID"
|
||||
/>
|
||||
)}
|
||||
{preset.type === 'deno' && (
|
||||
<ExternalInput
|
||||
type="text"
|
||||
placeholder={preset.organizationIdLabel || 'Organization ID'}
|
||||
value={presetApiKeys[`${preset.id}-organizationId`] || ''}
|
||||
onChange={(e) => setPresetApiKeys(prev => ({
|
||||
...prev,
|
||||
[`${preset.id}-organizationId`]: e.target.value,
|
||||
}))}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' && presetApiKeys[preset.id]?.trim() &&
|
||||
presetApiKeys[`${preset.id}-organizationId`]?.trim()) {
|
||||
handleAddPresetProvider(preset);
|
||||
}
|
||||
}}
|
||||
url={preset.organizationIdURL}
|
||||
urlTitle="Find ID"
|
||||
/>
|
||||
)}
|
||||
<ExternalInput
|
||||
type="text"
|
||||
placeholder={preset.organizationIdLabel || 'Organization ID'}
|
||||
value={presetApiKeys[`${preset.id}-organizationId`] || ''}
|
||||
type="password"
|
||||
placeholder={preset.apiKeyLabel || t('enterApiKey')}
|
||||
value={presetApiKeys[preset.id] || ''}
|
||||
onChange={(e) => setPresetApiKeys(prev => ({
|
||||
...prev,
|
||||
[`${preset.id}-organizationId`]: e.target.value,
|
||||
[preset.id]: e.target.value,
|
||||
}))}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' && presetApiKeys[preset.id]?.trim() &&
|
||||
presetApiKeys[`${preset.id}-organizationId`]?.trim()) {
|
||||
handleAddPresetProvider(preset);
|
||||
}
|
||||
}}
|
||||
url={preset.organizationIdURL}
|
||||
urlTitle="Find ID"
|
||||
/>
|
||||
)}
|
||||
<ExternalInput
|
||||
type="password"
|
||||
placeholder={preset.apiKeyLabel || t('enterApiKey')}
|
||||
value={presetApiKeys[preset.id] || ''}
|
||||
onChange={(e) => setPresetApiKeys(prev => ({
|
||||
...prev,
|
||||
[preset.id]: e.target.value,
|
||||
}))}
|
||||
onKeyDown={(e) => {
|
||||
if (e.key === 'Enter' && presetApiKeys[preset.id]?.trim() &&
|
||||
(preset.type !== 'cloudflare' || presetApiKeys[`${preset.id}-accountId`]?.trim()) &&
|
||||
(preset.type !== 'deno' || presetApiKeys[`${preset.id}-organizationId`]?.trim())) {
|
||||
handleAddPresetProvider(preset);
|
||||
}
|
||||
}}
|
||||
url={preset.apiKeyURL}
|
||||
urlTitle="Get Key"
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
<Button
|
||||
onClick={() => handleAddPresetProvider(preset)}
|
||||
disabled={
|
||||
(preset.requiresNostr && !isLoggedIntoNostr) ||
|
||||
handleAddPresetProvider(preset);
|
||||
}
|
||||
}}
|
||||
url={preset.apiKeyURL}
|
||||
urlTitle="Get Key"
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
<Button
|
||||
onClick={() => handleAddPresetProvider(preset)}
|
||||
disabled={
|
||||
(preset.requiresNostr && !isLoggedIntoNostr) ||
|
||||
(!preset.requiresNostr && preset.type !== 'nsite' && !presetApiKeys[preset.id]?.trim()) ||
|
||||
(preset.type === 'cloudflare' && !presetApiKeys[`${preset.id}-accountId`]?.trim()) ||
|
||||
(preset.type === 'deno' && !presetApiKeys[`${preset.id}-organizationId`]?.trim())
|
||||
}
|
||||
className="w-full"
|
||||
>
|
||||
{t('add')}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Custom Provider */}
|
||||
<div className="space-y-3">
|
||||
<Accordion type="single" collapsible className="w-full">
|
||||
<AccordionItem value="custom-provider">
|
||||
<AccordionTrigger className="px-4 py-3 hover:no-underline">
|
||||
<div className="flex items-center gap-2">
|
||||
<Plus className="h-4 w-4" />
|
||||
<h4 className="text-sm font-medium">{t('addCustomProvider')}</h4>
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-4 pb-4">
|
||||
<div className="space-y-3">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-provider-type">
|
||||
{t('providerType')} <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Select
|
||||
value={customProviderType}
|
||||
onValueChange={(value: 'shakespeare' | 'netlify' | 'vercel' | 'nsite' | 'cloudflare' | 'deno') => {
|
||||
setCustomProviderType(value);
|
||||
// Reset form when provider type changes
|
||||
setCustomApiKey('');
|
||||
setCustomAccountId('');
|
||||
setCustomOrganizationId('');
|
||||
setCustomBaseURL('');
|
||||
setCustomBaseDomain('');
|
||||
setCustomHost('');
|
||||
setCustomProxy(false);
|
||||
setCustomGateway('');
|
||||
setCustomRelayUrls('');
|
||||
setCustomBlossomServers('');
|
||||
}}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder={t('selectProviderType')} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="shakespeare">Shakespeare Deploy</SelectItem>
|
||||
<SelectItem value="nsite">nsite</SelectItem>
|
||||
<SelectItem value="netlify">Netlify</SelectItem>
|
||||
<SelectItem value="vercel">Vercel</SelectItem>
|
||||
<SelectItem value="cloudflare">Cloudflare</SelectItem>
|
||||
<SelectItem value="deno">Deno Deploy</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{customProviderType && (
|
||||
<>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-name">
|
||||
{t('providerName')} <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="custom-name"
|
||||
placeholder="e.g., My Production Deploy"
|
||||
value={customName}
|
||||
onChange={(e) => setCustomName(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{customProviderType === 'shakespeare' ? (
|
||||
<>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t('shakespeareDeployNostrAuth')}
|
||||
</p>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-host">Host (Optional)</Label>
|
||||
<Input
|
||||
id="custom-host"
|
||||
placeholder="shakespeare.wtf"
|
||||
value={customHost}
|
||||
onChange={(e) => setCustomHost(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
) : customProviderType === 'nsite' ? (
|
||||
<>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Deploy to Nostr as a static website. Uses kind 34128 events and Blossom file storage.
|
||||
</p>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-gateway">Gateway</Label>
|
||||
<Input
|
||||
id="custom-gateway"
|
||||
placeholder="nsite.lol"
|
||||
value={customGateway}
|
||||
onChange={(e) => setCustomGateway(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-relays">Relay URLs (comma-separated)</Label>
|
||||
<Input
|
||||
id="custom-relays"
|
||||
placeholder="wss://relay.nostr.band, wss://relay.damus.io"
|
||||
value={customRelayUrls}
|
||||
onChange={(e) => setCustomRelayUrls(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-blossom">Blossom Servers (comma-separated)</Label>
|
||||
<Input
|
||||
id="custom-blossom"
|
||||
placeholder="https://blossom.primal.net/"
|
||||
value={customBlossomServers}
|
||||
onChange={(e) => setCustomBlossomServers(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{customProviderType === 'cloudflare' && (
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-accountid">
|
||||
Account ID <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="custom-accountid"
|
||||
placeholder="Enter Account ID"
|
||||
value={customAccountId}
|
||||
onChange={(e) => setCustomAccountId(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{customProviderType === 'deno' && (
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-organizationid">
|
||||
Organization ID <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="custom-organizationid"
|
||||
placeholder="Enter Organization ID"
|
||||
value={customOrganizationId}
|
||||
onChange={(e) => setCustomOrganizationId(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-apikey">
|
||||
{customProviderType === 'netlify' ? 'Personal Access Token' :
|
||||
customProviderType === 'cloudflare' ? 'API Token' :
|
||||
customProviderType === 'deno' ? 'Access Token' :
|
||||
'Access Token'} <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<PasswordInput
|
||||
id="custom-apikey"
|
||||
placeholder={t('enterApiKey')}
|
||||
value={customApiKey}
|
||||
onChange={(e) => setCustomApiKey(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-baseurl">Base URL (Optional)</Label>
|
||||
<Input
|
||||
id="custom-baseurl"
|
||||
placeholder={
|
||||
customProviderType === 'netlify'
|
||||
? 'https://api.netlify.com/api/v1'
|
||||
: customProviderType === 'vercel'
|
||||
? 'https://api.vercel.com'
|
||||
: customProviderType === 'deno'
|
||||
? 'https://api.deno.com/v1'
|
||||
: 'https://api.cloudflare.com/client/v4'
|
||||
}
|
||||
value={customBaseURL}
|
||||
onChange={(e) => setCustomBaseURL(e.target.value)}
|
||||
/>
|
||||
className="w-full"
|
||||
>
|
||||
{t('add')}
|
||||
</Button>
|
||||
</div>
|
||||
{(customProviderType === 'cloudflare' || customProviderType === 'deno') && (
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Custom Provider */}
|
||||
<div className="space-y-3">
|
||||
<Accordion type="single" collapsible className="w-full">
|
||||
<AccordionItem value="custom-provider">
|
||||
<AccordionTrigger className="px-4 py-3 hover:no-underline">
|
||||
<div className="flex items-center gap-2">
|
||||
<Plus className="h-4 w-4" />
|
||||
<h4 className="text-sm font-medium">{t('addCustomProvider')}</h4>
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-4 pb-4">
|
||||
<div className="space-y-3">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-provider-type">
|
||||
{t('providerType')} <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Select
|
||||
value={customProviderType}
|
||||
onValueChange={(value: 'shakespeare' | 'netlify' | 'vercel' | 'nsite' | 'cloudflare' | 'deno') => {
|
||||
setCustomProviderType(value);
|
||||
// Reset form when provider type changes
|
||||
setCustomApiKey('');
|
||||
setCustomAccountId('');
|
||||
setCustomOrganizationId('');
|
||||
setCustomBaseURL('');
|
||||
setCustomBaseDomain('');
|
||||
setCustomHost('');
|
||||
setCustomProxy(false);
|
||||
setCustomGateway('');
|
||||
setCustomRelayUrls('');
|
||||
setCustomBlossomServers('');
|
||||
}}
|
||||
>
|
||||
<SelectTrigger>
|
||||
<SelectValue placeholder={t('selectProviderType')} />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="shakespeare">Shakespeare Deploy</SelectItem>
|
||||
<SelectItem value="nsite">nsite</SelectItem>
|
||||
<SelectItem value="netlify">Netlify</SelectItem>
|
||||
<SelectItem value="vercel">Vercel</SelectItem>
|
||||
<SelectItem value="cloudflare">Cloudflare</SelectItem>
|
||||
<SelectItem value="deno">Deno Deploy</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
|
||||
{customProviderType && (
|
||||
<>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-name">
|
||||
{t('providerName')} <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="custom-name"
|
||||
placeholder="e.g., My Production Deploy"
|
||||
value={customName}
|
||||
onChange={(e) => setCustomName(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{customProviderType === 'shakespeare' ? (
|
||||
<>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{t('shakespeareDeployNostrAuth')}
|
||||
</p>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-basedomain">Base Domain (Optional)</Label>
|
||||
<Label htmlFor="custom-host">Host (Optional)</Label>
|
||||
<Input
|
||||
id="custom-basedomain"
|
||||
placeholder={customProviderType === 'cloudflare' ? 'workers.dev' : 'deno.dev'}
|
||||
value={customBaseDomain}
|
||||
onChange={(e) => setCustomBaseDomain(e.target.value)}
|
||||
id="custom-host"
|
||||
placeholder="shakespeare.wtf"
|
||||
value={customHost}
|
||||
onChange={(e) => setCustomHost(e.target.value)}
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{customProviderType === 'cloudflare'
|
||||
? 'The domain suffix for deployed workers (e.g., workers.dev)'
|
||||
: 'The domain suffix for deployed projects (e.g., deno.dev)'}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
) : customProviderType === 'nsite' ? (
|
||||
<>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
Deploy to Nostr as a static website. Uses kind 34128 events and Blossom file storage.
|
||||
</p>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-gateway">Gateway</Label>
|
||||
<Input
|
||||
id="custom-gateway"
|
||||
placeholder="nsite.lol"
|
||||
value={customGateway}
|
||||
onChange={(e) => setCustomGateway(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-relays">Relay URLs (comma-separated)</Label>
|
||||
<Input
|
||||
id="custom-relays"
|
||||
placeholder="wss://relay.nostr.band, wss://relay.damus.io"
|
||||
value={customRelayUrls}
|
||||
onChange={(e) => setCustomRelayUrls(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-blossom">Blossom Servers (comma-separated)</Label>
|
||||
<Input
|
||||
id="custom-blossom"
|
||||
placeholder="https://blossom.primal.net/"
|
||||
value={customBlossomServers}
|
||||
onChange={(e) => setCustomBlossomServers(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
{customProviderType === 'cloudflare' && (
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-accountid">
|
||||
Account ID <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="custom-accountid"
|
||||
placeholder="Enter Account ID"
|
||||
value={customAccountId}
|
||||
onChange={(e) => setCustomAccountId(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
{customProviderType === 'deno' && (
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-organizationid">
|
||||
Organization ID <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="custom-organizationid"
|
||||
placeholder="Enter Organization ID"
|
||||
value={customOrganizationId}
|
||||
onChange={(e) => setCustomOrganizationId(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-apikey">
|
||||
{customProviderType === 'netlify' ? 'Personal Access Token' :
|
||||
customProviderType === 'cloudflare' ? 'API Token' :
|
||||
customProviderType === 'deno' ? 'Access Token' :
|
||||
'Access Token'} <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<PasswordInput
|
||||
id="custom-apikey"
|
||||
placeholder={t('enterApiKey')}
|
||||
value={customApiKey}
|
||||
onChange={(e) => setCustomApiKey(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-baseurl">Base URL (Optional)</Label>
|
||||
<Input
|
||||
id="custom-baseurl"
|
||||
placeholder={
|
||||
customProviderType === 'netlify'
|
||||
? 'https://api.netlify.com/api/v1'
|
||||
: customProviderType === 'vercel'
|
||||
? 'https://api.vercel.com'
|
||||
: customProviderType === 'deno'
|
||||
? 'https://api.deno.com/v1'
|
||||
: 'https://api.cloudflare.com/client/v4'
|
||||
}
|
||||
value={customBaseURL}
|
||||
onChange={(e) => setCustomBaseURL(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
{(customProviderType === 'cloudflare' || customProviderType === 'deno') && (
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-basedomain">Base Domain (Optional)</Label>
|
||||
<Input
|
||||
id="custom-basedomain"
|
||||
placeholder={customProviderType === 'cloudflare' ? 'workers.dev' : 'deno.dev'}
|
||||
value={customBaseDomain}
|
||||
onChange={(e) => setCustomBaseDomain(e.target.value)}
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{customProviderType === 'cloudflare'
|
||||
? 'The domain suffix for deployed workers (e.g., workers.dev)'
|
||||
: 'The domain suffix for deployed projects (e.g., deno.dev)'}
|
||||
</p>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
<div className="flex items-center space-x-2">
|
||||
<Checkbox
|
||||
id="custom-proxy"
|
||||
checked={customProxy}
|
||||
onCheckedChange={(checked) => setCustomProxy(checked === true)}
|
||||
/>
|
||||
<Label htmlFor="custom-proxy" className="text-sm font-normal cursor-pointer">
|
||||
<div className="flex items-center space-x-2">
|
||||
<Checkbox
|
||||
id="custom-proxy"
|
||||
checked={customProxy}
|
||||
onCheckedChange={(checked) => setCustomProxy(checked === true)}
|
||||
/>
|
||||
<Label htmlFor="custom-proxy" className="text-sm font-normal cursor-pointer">
|
||||
Use CORS Proxy
|
||||
</Label>
|
||||
</div>
|
||||
</Label>
|
||||
</div>
|
||||
|
||||
<Button
|
||||
onClick={handleAddCustomProvider}
|
||||
disabled={
|
||||
!customProviderType ||
|
||||
<Button
|
||||
onClick={handleAddCustomProvider}
|
||||
disabled={
|
||||
!customProviderType ||
|
||||
!customName.trim() ||
|
||||
(customProviderType !== 'shakespeare' && customProviderType !== 'nsite' && !customApiKey.trim()) ||
|
||||
(customProviderType === 'cloudflare' && !customAccountId.trim()) ||
|
||||
(customProviderType === 'deno' && !customOrganizationId.trim())
|
||||
}
|
||||
className="gap-2 ml-auto"
|
||||
>
|
||||
<Check className="h-4 w-4" />
|
||||
{t('add')}
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
}
|
||||
className="gap-2 ml-auto"
|
||||
>
|
||||
<Check className="h-4 w-4" />
|
||||
{t('add')}
|
||||
</Button>
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
+315
-282
@@ -8,6 +8,7 @@ import { Badge } from '@/components/ui/badge';
|
||||
import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from '@/components/ui/accordion';
|
||||
import { Card, CardContent } from '@/components/ui/card';
|
||||
import { Switch } from '@/components/ui/switch';
|
||||
import { Skeleton } from '@/components/ui/skeleton';
|
||||
import {
|
||||
DropdownMenu,
|
||||
DropdownMenuContent,
|
||||
@@ -50,7 +51,7 @@ const PRESET_PROVIDERS: PresetProvider[] = [
|
||||
|
||||
export function GitSettings() {
|
||||
const { t } = useTranslation();
|
||||
const { settings, addCredential, removeCredential, updateCredential, updateSettings } = useGitSettings();
|
||||
const { settings, addCredential, removeCredential, updateCredential, updateSettings, isInitialized } = useGitSettings();
|
||||
const { initiateOAuth, isLoading: isOAuthLoading, error: oauthError, isOAuthConfigured } = useGitHubOAuth();
|
||||
const isMobile = useIsMobile();
|
||||
const navigate = useNavigate();
|
||||
@@ -173,157 +174,218 @@ export function GitSettings() {
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className="space-y-6">
|
||||
{/* Configured Credentials */}
|
||||
{settings.credentials.length > 0 && (
|
||||
{!isInitialized ? (
|
||||
<div className="space-y-6">
|
||||
{/* Loading skeleton for configured credentials */}
|
||||
<div className="space-y-3">
|
||||
<h4 className="text-sm font-medium">{t('configuredCredentials')}</h4>
|
||||
<Accordion type="multiple" className="w-full space-y-2">
|
||||
{settings.credentials.map((credential, index) => {
|
||||
const origin = getOriginFromCredential(credential);
|
||||
const preset = PRESET_PROVIDERS.find(p => p.origin === origin);
|
||||
const isCustom = !preset;
|
||||
<Skeleton className="h-4 w-40" />
|
||||
<div className="space-y-2">
|
||||
<Skeleton className="h-16 w-full rounded-lg" />
|
||||
<Skeleton className="h-16 w-full rounded-lg" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
return (
|
||||
<AccordionItem key={`${origin}-${index}`} value={`${origin}-${index}`}>
|
||||
<AccordionTrigger className="px-4 py-3 hover:no-underline">
|
||||
{/* Loading skeleton for add provider section */}
|
||||
<div className="space-y-3">
|
||||
<Skeleton className="h-4 w-32" />
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-3">
|
||||
<Skeleton className="h-32 w-full rounded-lg" />
|
||||
<Skeleton className="h-32 w-full rounded-lg" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Loading skeleton for custom provider */}
|
||||
<div className="space-y-3">
|
||||
<Skeleton className="h-16 w-full rounded-lg" />
|
||||
</div>
|
||||
|
||||
{/* Loading skeleton for git identity */}
|
||||
<div className="space-y-3">
|
||||
<Skeleton className="h-16 w-full rounded-lg" />
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="space-y-6">
|
||||
{/* Configured Credentials */}
|
||||
{settings.credentials.length > 0 && (
|
||||
<div className="space-y-3">
|
||||
<h4 className="text-sm font-medium">{t('configuredCredentials')}</h4>
|
||||
<Accordion type="multiple" className="w-full space-y-2">
|
||||
{settings.credentials.map((credential, index) => {
|
||||
const origin = getOriginFromCredential(credential);
|
||||
const preset = PRESET_PROVIDERS.find(p => p.origin === origin);
|
||||
const isCustom = !preset;
|
||||
|
||||
return (
|
||||
<AccordionItem key={`${origin}-${index}`} value={`${origin}-${index}`}>
|
||||
<AccordionTrigger className="px-4 py-3 hover:no-underline">
|
||||
<div className="flex items-center gap-2">
|
||||
<ExternalFavicon
|
||||
url={origin}
|
||||
size={16}
|
||||
fallback={<GitBranch size={16} />}
|
||||
/>
|
||||
<span className="font-medium">
|
||||
{preset?.name || credential.host}
|
||||
</span>
|
||||
{isCustom && <Badge variant="outline">{t('custom')}</Badge>}
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-4 pb-4">
|
||||
<div className="space-y-3">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor={`${origin}-${index}-origin`}>
|
||||
{t('origin')} <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id={`${origin}-${index}-origin`}
|
||||
placeholder="https://github.com"
|
||||
value={origin}
|
||||
disabled
|
||||
className="bg-muted"
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor={`${origin}-${index}-username`}>
|
||||
{t('username')} <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id={`${origin}-${index}-username`}
|
||||
placeholder="git"
|
||||
value={credential.username}
|
||||
onChange={(e) => handleUpdateCredential(index, { username: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor={`${origin}-${index}-password`}>
|
||||
{t('password')} <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<PasswordInput
|
||||
id={`${origin}-${index}-password`}
|
||||
placeholder={t('enterPassword')}
|
||||
value={credential.password}
|
||||
onChange={(e) => handleUpdateCredential(index, { password: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
variant="destructive"
|
||||
size="sm"
|
||||
onClick={() => handleRemoveCredential(index)}
|
||||
>
|
||||
<Trash2 className="h-4 w-4 mr-2" />
|
||||
{t('delete')}
|
||||
</Button>
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
);
|
||||
})}
|
||||
</Accordion>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Available Preset Providers */}
|
||||
{availablePresets.length > 0 && (
|
||||
<div className="space-y-3">
|
||||
<h4 className="text-sm font-medium">{t('addProvider')}</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 gap-2">
|
||||
<ExternalFavicon
|
||||
url={origin}
|
||||
url={preset.origin}
|
||||
size={16}
|
||||
fallback={<GitBranch size={16} />}
|
||||
/>
|
||||
<span className="font-medium">
|
||||
{preset?.name || credential.host}
|
||||
</span>
|
||||
{isCustom && <Badge variant="outline">{t('custom')}</Badge>}
|
||||
<h5 className="font-medium">{preset.name}</h5>
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-4 pb-4">
|
||||
<div className="space-y-3">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor={`${origin}-${index}-origin`}>
|
||||
{t('origin')} <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id={`${origin}-${index}-origin`}
|
||||
placeholder="https://github.com"
|
||||
value={origin}
|
||||
disabled
|
||||
className="bg-muted"
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor={`${origin}-${index}-username`}>
|
||||
{t('username')} <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id={`${origin}-${index}-username`}
|
||||
placeholder="git"
|
||||
value={credential.username}
|
||||
onChange={(e) => handleUpdateCredential(index, { username: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor={`${origin}-${index}-password`}>
|
||||
{t('password')} <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<PasswordInput
|
||||
id={`${origin}-${index}-password`}
|
||||
placeholder={t('enterPassword')}
|
||||
value={credential.password}
|
||||
onChange={(e) => handleUpdateCredential(index, { password: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
variant="destructive"
|
||||
size="sm"
|
||||
onClick={() => handleRemoveCredential(index)}
|
||||
>
|
||||
<Trash2 className="h-4 w-4 mr-2" />
|
||||
{t('delete')}
|
||||
</Button>
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
);
|
||||
})}
|
||||
</Accordion>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Available Preset Providers */}
|
||||
{availablePresets.length > 0 && (
|
||||
<div className="space-y-3">
|
||||
<h4 className="text-sm font-medium">{t('addProvider')}</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 gap-2">
|
||||
<ExternalFavicon
|
||||
url={preset.origin}
|
||||
size={16}
|
||||
fallback={<GitBranch size={16} />}
|
||||
/>
|
||||
<h5 className="font-medium">{preset.name}</h5>
|
||||
</div>
|
||||
|
||||
{preset.id === 'github' ? (
|
||||
{preset.id === 'github' ? (
|
||||
// Special rendering for GitHub - OAuth button if configured, otherwise token input
|
||||
isOAuthConfigured && !forceManualEntry[preset.id] ? (
|
||||
<div className="space-y-3">
|
||||
<div className="flex gap-0">
|
||||
<Button
|
||||
onClick={initiateOAuth}
|
||||
disabled={isOAuthLoading}
|
||||
className="flex-1 rounded-r-none gap-2"
|
||||
variant="default"
|
||||
>
|
||||
{isOAuthLoading ? (
|
||||
<>
|
||||
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-white"></div>
|
||||
isOAuthConfigured && !forceManualEntry[preset.id] ? (
|
||||
<div className="space-y-3">
|
||||
<div className="flex gap-0">
|
||||
<Button
|
||||
onClick={initiateOAuth}
|
||||
disabled={isOAuthLoading}
|
||||
className="flex-1 rounded-r-none gap-2"
|
||||
variant="default"
|
||||
>
|
||||
{isOAuthLoading ? (
|
||||
<>
|
||||
<div className="animate-spin rounded-full h-4 w-4 border-b-2 border-white"></div>
|
||||
Connecting...
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<ExternalFavicon
|
||||
url="https://github.com"
|
||||
size={16}
|
||||
fallback={<GitBranch size={16} />}
|
||||
/>
|
||||
<span className="truncate text-ellipsis overflow-hidden">
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<ExternalFavicon
|
||||
url="https://github.com"
|
||||
size={16}
|
||||
fallback={<GitBranch size={16} />}
|
||||
/>
|
||||
<span className="truncate text-ellipsis overflow-hidden">
|
||||
Connect to GitHub
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="default"
|
||||
className="rounded-l-none border-l border-primary-foreground/20 px-2"
|
||||
disabled={isOAuthLoading}
|
||||
>
|
||||
<ChevronDown className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem
|
||||
onClick={() => setForceManualEntry(prev => ({ ...prev, [preset.id]: true }))}
|
||||
>
|
||||
</span>
|
||||
</>
|
||||
)}
|
||||
</Button>
|
||||
<DropdownMenu>
|
||||
<DropdownMenuTrigger asChild>
|
||||
<Button
|
||||
variant="default"
|
||||
className="rounded-l-none border-l border-primary-foreground/20 px-2"
|
||||
disabled={isOAuthLoading}
|
||||
>
|
||||
<ChevronDown className="h-4 w-4" />
|
||||
</Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end">
|
||||
<DropdownMenuItem
|
||||
onClick={() => setForceManualEntry(prev => ({ ...prev, [preset.id]: true }))}
|
||||
>
|
||||
Enter API key
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</DropdownMenuItem>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
</div>
|
||||
{oauthError && (
|
||||
<p className="text-sm text-destructive">
|
||||
{oauthError}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
{oauthError && (
|
||||
<p className="text-sm text-destructive">
|
||||
{oauthError}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex gap-2">
|
||||
<ExternalInput
|
||||
type="password"
|
||||
className="flex-1"
|
||||
placeholder={t('enterToken')}
|
||||
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);
|
||||
}
|
||||
}}
|
||||
url={preset.tokenURL}
|
||||
urlTitle="Get Token"
|
||||
/>
|
||||
<Button
|
||||
onClick={() => handleAddPresetProvider(preset)}
|
||||
disabled={!presetTokens[preset.id]?.trim()}
|
||||
size="sm"
|
||||
className="h-10"
|
||||
>
|
||||
{t('add')}
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
) : (
|
||||
// Standard rendering for other providers
|
||||
<div className="flex gap-2">
|
||||
<ExternalInput
|
||||
type="password"
|
||||
@@ -346,165 +408,136 @@ export function GitSettings() {
|
||||
onClick={() => handleAddPresetProvider(preset)}
|
||||
disabled={!presetTokens[preset.id]?.trim()}
|
||||
size="sm"
|
||||
className="h-10"
|
||||
>
|
||||
{t('add')}
|
||||
</Button>
|
||||
</div>
|
||||
)
|
||||
) : (
|
||||
// Standard rendering for other providers
|
||||
<div className="flex gap-2">
|
||||
<ExternalInput
|
||||
type="password"
|
||||
className="flex-1"
|
||||
placeholder={t('enterToken')}
|
||||
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);
|
||||
}
|
||||
}}
|
||||
url={preset.tokenURL}
|
||||
urlTitle="Get Token"
|
||||
/>
|
||||
<Button
|
||||
onClick={() => handleAddPresetProvider(preset)}
|
||||
disabled={!presetTokens[preset.id]?.trim()}
|
||||
size="sm"
|
||||
>
|
||||
{t('add')}
|
||||
</Button>
|
||||
</div>
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
)}
|
||||
</CardContent>
|
||||
</Card>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
)}
|
||||
|
||||
{/* Custom Provider */}
|
||||
<div className="space-y-3">
|
||||
<Accordion type="single" collapsible className="w-full">
|
||||
<AccordionItem value="custom-provider">
|
||||
<AccordionTrigger className="px-4 py-3 hover:no-underline">
|
||||
<div className="flex items-center gap-2">
|
||||
<Plus className="h-4 w-4" />
|
||||
<h4 className="text-sm font-medium">{t('addCustomProvider')}</h4>
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-4 pb-4">
|
||||
<div className="space-y-3">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-origin">
|
||||
{t('origin')} <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<Input
|
||||
id="custom-origin"
|
||||
placeholder="https://git.example.com"
|
||||
value={customOrigin}
|
||||
onChange={(e) => setCustomOrigin(e.target.value)}
|
||||
/>
|
||||
{/* Custom Provider */}
|
||||
<div className="space-y-3">
|
||||
<Accordion type="single" collapsible className="w-full">
|
||||
<AccordionItem value="custom-provider">
|
||||
<AccordionTrigger className="px-4 py-3 hover:no-underline">
|
||||
<div className="flex items-center gap-2">
|
||||
<Plus className="h-4 w-4" />
|
||||
<h4 className="text-sm font-medium">{t('addCustomProvider')}</h4>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-username">
|
||||
{t('username')} <span className="text-destructive">*</span>
|
||||
</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">
|
||||
{t('password')} <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<PasswordInput
|
||||
id="custom-password"
|
||||
placeholder={t('enterPassword')}
|
||||
value={customPassword}
|
||||
onChange={(e) => setCustomPassword(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<Button
|
||||
onClick={handleAddCustomProvider}
|
||||
disabled={
|
||||
!customOrigin.trim() ||
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-4 pb-4">
|
||||
<div className="space-y-3">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="custom-origin">
|
||||
{t('origin')} <span className="text-destructive">*</span>
|
||||
</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">
|
||||
{t('username')} <span className="text-destructive">*</span>
|
||||
</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">
|
||||
{t('password')} <span className="text-destructive">*</span>
|
||||
</Label>
|
||||
<PasswordInput
|
||||
id="custom-password"
|
||||
placeholder={t('enterPassword')}
|
||||
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" />
|
||||
{t('addCustomProviderButton')}
|
||||
</Button>
|
||||
{customOrigin.trim() in settings.credentials && (
|
||||
<p className="text-sm text-destructive">
|
||||
{t('credentialsExist')}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
</div>
|
||||
}
|
||||
size="sm"
|
||||
className="gap-2"
|
||||
>
|
||||
<Check className="h-4 w-4" />
|
||||
{t('addCustomProviderButton')}
|
||||
</Button>
|
||||
{customOrigin.trim() in settings.credentials && (
|
||||
<p className="text-sm text-destructive">
|
||||
{t('credentialsExist')}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
</div>
|
||||
|
||||
{/* Git Identity */}
|
||||
<div className="space-y-3">
|
||||
<Accordion type="single" collapsible className="w-full">
|
||||
<AccordionItem value="git-identity">
|
||||
<AccordionTrigger className="px-4 py-3 hover:no-underline">
|
||||
<div className="flex items-center gap-2">
|
||||
<User className="h-4 w-4" />
|
||||
<h4 className="text-sm font-medium">{t('gitIdentity')}</h4>
|
||||
</div>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-4 pb-4">
|
||||
<div className="space-y-4">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="git-name">{t('name')}</Label>
|
||||
<Input
|
||||
id="git-name"
|
||||
placeholder="Your Name"
|
||||
value={settings.name || ''}
|
||||
onChange={(e) => updateSettings({ name: e.target.value })}
|
||||
/>
|
||||
{/* Git Identity */}
|
||||
<div className="space-y-3">
|
||||
<Accordion type="single" collapsible className="w-full">
|
||||
<AccordionItem value="git-identity">
|
||||
<AccordionTrigger className="px-4 py-3 hover:no-underline">
|
||||
<div className="flex items-center gap-2">
|
||||
<User className="h-4 w-4" />
|
||||
<h4 className="text-sm font-medium">{t('gitIdentity')}</h4>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="git-email">{t('email')}</Label>
|
||||
<Input
|
||||
id="git-email"
|
||||
type="email"
|
||||
placeholder="[email protected]"
|
||||
value={settings.email || ''}
|
||||
onChange={(e) => updateSettings({ email: e.target.value })}
|
||||
/>
|
||||
</AccordionTrigger>
|
||||
<AccordionContent className="px-4 pb-4">
|
||||
<div className="space-y-4">
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="git-name">{t('name')}</Label>
|
||||
<Input
|
||||
id="git-name"
|
||||
placeholder="Your Name"
|
||||
value={settings.name || ''}
|
||||
onChange={(e) => updateSettings({ name: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
<Label htmlFor="git-email">{t('email')}</Label>
|
||||
<Input
|
||||
id="git-email"
|
||||
type="email"
|
||||
placeholder="[email protected]"
|
||||
value={settings.email || ''}
|
||||
onChange={(e) => updateSettings({ email: e.target.value })}
|
||||
/>
|
||||
</div>
|
||||
<div className="flex items-center justify-between space-x-2">
|
||||
<Label htmlFor="co-author" className="flex-1 cursor-pointer">
|
||||
{t('coAuthoredByShakespeare')}
|
||||
</Label>
|
||||
<Switch
|
||||
id="co-author"
|
||||
checked={settings.coAuthorEnabled ?? true}
|
||||
onCheckedChange={(checked) => updateSettings({ coAuthorEnabled: checked })}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex items-center justify-between space-x-2">
|
||||
<Label htmlFor="co-author" className="flex-1 cursor-pointer">
|
||||
{t('coAuthoredByShakespeare')}
|
||||
</Label>
|
||||
<Switch
|
||||
id="co-author"
|
||||
checked={settings.coAuthorEnabled ?? true}
|
||||
onCheckedChange={(checked) => updateSettings({ coAuthorEnabled: checked })}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
</AccordionContent>
|
||||
</AccordionItem>
|
||||
</Accordion>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user