Spaces:
Sleeping
Sleeping
File size: 12,253 Bytes
8e0dd55 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 | 'use client';
import React, { useState } from 'react';
import { useLanguage } from '@/contexts/LanguageContext';
import UserSelector from './UserSelector';
import TokenInput from './TokenInput';
interface ConfigurationModalProps {
isOpen: boolean;
onClose: () => void;
// Repository input
repositoryInput: string;
// Language selection
selectedLanguage: string;
setSelectedLanguage: (value: string) => void;
supportedLanguages: Record<string, string>;
// Wiki type options
isComprehensiveView: boolean;
setIsComprehensiveView: (value: boolean) => void;
// Model selection
provider: string;
setProvider: (value: string) => void;
model: string;
setModel: (value: string) => void;
isCustomModel: boolean;
setIsCustomModel: (value: boolean) => void;
customModel: string;
setCustomModel: (value: string) => void;
// Platform selection
selectedPlatform: 'github' | 'gitlab' | 'bitbucket';
setSelectedPlatform: (value: 'github' | 'gitlab' | 'bitbucket') => void;
// Access token
accessToken: string;
setAccessToken: (value: string) => void;
// File filter options
excludedDirs: string;
setExcludedDirs: (value: string) => void;
excludedFiles: string;
setExcludedFiles: (value: string) => void;
includedDirs: string;
setIncludedDirs: (value: string) => void;
includedFiles: string;
setIncludedFiles: (value: string) => void;
// Form submission
onSubmit: () => void;
isSubmitting: boolean;
// Authentication
authRequired?: boolean;
authCode?: string;
setAuthCode?: (code: string) => void;
isAuthLoading?: boolean;
}
export default function ConfigurationModal({
isOpen,
onClose,
repositoryInput,
selectedLanguage,
setSelectedLanguage,
supportedLanguages,
isComprehensiveView,
setIsComprehensiveView,
provider,
setProvider,
model,
setModel,
isCustomModel,
setIsCustomModel,
customModel,
setCustomModel,
selectedPlatform,
setSelectedPlatform,
accessToken,
setAccessToken,
excludedDirs,
setExcludedDirs,
excludedFiles,
setExcludedFiles,
includedDirs,
setIncludedDirs,
includedFiles,
setIncludedFiles,
onSubmit,
isSubmitting,
authRequired,
authCode,
setAuthCode,
isAuthLoading
}: ConfigurationModalProps) {
const { messages: t } = useLanguage();
// Show token section state
const [showTokenSection, setShowTokenSection] = useState(false);
if (!isOpen) return null;
return (
<div className="fixed inset-0 z-50 overflow-y-auto">
<div className="flex min-h-screen items-center justify-center p-4 text-center bg-black/50">
<div className="relative transform overflow-hidden rounded-lg bg-[var(--card-bg)] text-left shadow-xl transition-all sm:my-8 sm:max-w-2xl sm:w-full">
{/* Modal header with close button */}
<div className="flex items-center justify-between px-6 py-4 border-b border-[var(--border-color)]">
<h3 className="text-lg font-medium text-[var(--accent-primary)]">
<span className="text-[var(--accent-primary)]">{t.form?.configureWiki || 'Configure Wiki'}</span>
</h3>
<button
type="button"
onClick={onClose}
className="text-[var(--muted)] hover:text-[var(--foreground)] focus:outline-none transition-colors"
>
<svg className="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
{/* Modal body */}
<div className="p-6 max-h-[70vh] overflow-y-auto">
{/* Repository info */}
<div className="mb-4">
<label className="block text-sm font-medium text-[var(--foreground)] mb-2">
{t.form?.repository || 'Repository'}
</label>
<div className="bg-[var(--background)]/70 p-3 rounded-md border border-[var(--border-color)] text-sm text-[var(--foreground)]">
{repositoryInput}
</div>
</div>
{/* Language selection */}
<div className="mb-4">
<label htmlFor="language-select" className="block text-sm font-medium text-[var(--foreground)] mb-2">
{t.form?.wikiLanguage || 'Wiki Language'}
</label>
<select
id="language-select"
value={selectedLanguage}
onChange={(e) => setSelectedLanguage(e.target.value)}
className="input-japanese block w-full px-3 py-2 text-sm rounded-md bg-transparent text-[var(--foreground)] focus:outline-none focus:border-[var(--accent-primary)]"
>
{
Object.entries(supportedLanguages).map(([key, value])=> <option key={key} value={key}>{value}</option>)
}
</select>
</div>
{/* Wiki Type Selector - more compact version */}
<div className="mb-4">
<label className="block text-sm font-medium text-[var(--foreground)] mb-2">
{t.form?.wikiType || 'Wiki Type'}
</label>
<div className="flex gap-3">
<button
type="button"
onClick={() => setIsComprehensiveView(true)}
className={`flex-1 flex items-center justify-between p-2 rounded-md border transition-colors ${
isComprehensiveView
? 'bg-[var(--accent-primary)]/10 border-[var(--accent-primary)]/30 text-[var(--accent-primary)]'
: 'bg-[var(--background)]/50 border-[var(--border-color)] text-[var(--foreground)] hover:bg-[var(--background)]'
}`}
>
<div className="flex items-center">
<div className="text-left">
<div className="font-medium text-sm">{t.form?.comprehensive || 'Comprehensive'}</div>
<div className="text-xs opacity-80">
{t.form?.comprehensiveDescription || 'Detailed wiki with structured sections'}
</div>
</div>
</div>
{isComprehensiveView && (
<div className="ml-2 h-4 w-4 rounded-full bg-[var(--accent-primary)]/20 flex items-center justify-center">
<div className="h-2 w-2 rounded-full bg-[var(--accent-primary)]"></div>
</div>
)}
</button>
<button
type="button"
onClick={() => setIsComprehensiveView(false)}
className={`flex-1 flex items-center justify-between p-2 rounded-md border transition-colors ${
!isComprehensiveView
? 'bg-[var(--accent-primary)]/10 border-[var(--accent-primary)]/30 text-[var(--accent-primary)]'
: 'bg-[var(--background)]/50 border-[var(--border-color)] text-[var(--foreground)] hover:bg-[var(--background)]'
}`}
>
<div className="flex items-center">
<div className="text-left">
<div className="font-medium text-sm">{t.form?.concise || 'Concise'}</div>
<div className="text-xs opacity-80">
{t.form?.conciseDescription || 'Simplified wiki with fewer pages'}
</div>
</div>
</div>
{!isComprehensiveView && (
<div className="ml-2 h-4 w-4 rounded-full bg-[var(--accent-primary)]/20 flex items-center justify-center">
<div className="h-2 w-2 rounded-full bg-[var(--accent-primary)]"></div>
</div>
)}
</button>
</div>
</div>
{/* Model Selector */}
<div className="mb-4">
<UserSelector
provider={provider}
setProvider={setProvider}
model={model}
setModel={setModel}
isCustomModel={isCustomModel}
setIsCustomModel={setIsCustomModel}
customModel={customModel}
setCustomModel={setCustomModel}
showFileFilters={true}
excludedDirs={excludedDirs}
setExcludedDirs={setExcludedDirs}
excludedFiles={excludedFiles}
setExcludedFiles={setExcludedFiles}
includedDirs={includedDirs}
setIncludedDirs={setIncludedDirs}
includedFiles={includedFiles}
setIncludedFiles={setIncludedFiles}
/>
</div>
{/* Access token section using TokenInput component */}
<TokenInput
selectedPlatform={selectedPlatform}
setSelectedPlatform={setSelectedPlatform}
accessToken={accessToken}
setAccessToken={setAccessToken}
showTokenSection={showTokenSection}
onToggleTokenSection={() => setShowTokenSection(!showTokenSection)}
allowPlatformChange={true}
/>
{/* Authorization Code Input */}
{isAuthLoading && (
<div className="mb-4 p-3 bg-[var(--background)]/50 rounded-md border border-[var(--border-color)] text-sm text-[var(--muted)]">
Loading authentication status...
</div>
)}
{!isAuthLoading && authRequired && (
<div className="mb-4 p-4 bg-[var(--background)]/50 rounded-md border border-[var(--border-color)]">
<label htmlFor="authCode" className="block text-sm font-medium text-[var(--foreground)] mb-2">
{t.form?.authorizationCode || 'Authorization Code'}
</label>
<input
type="password"
id="authCode"
value={authCode || ''}
onChange={(e) => setAuthCode?.(e.target.value)}
className="input-japanese block w-full px-3 py-2 text-sm rounded-md bg-transparent text-[var(--foreground)] focus:outline-none focus:border-[var(--accent-primary)]"
placeholder="Enter your authorization code"
/>
<div className="flex items-center mt-2 text-xs text-[var(--muted)]">
<svg xmlns="http://www.w3.org/2000/svg" className="h-4 w-4 mr-1 text-[var(--muted)]"
fill="none" viewBox="0 0 24 24" stroke="currentColor">
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2}
d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z" />
</svg>
{t.form?.authorizationRequired || 'Authentication is required to generate the wiki.'}
</div>
</div>
)}
</div>
{/* Modal footer */}
<div className="flex items-center justify-end gap-2 px-6 py-4 border-t border-[var(--border-color)]">
<button
type="button"
onClick={onClose}
className="px-4 py-2 text-sm font-medium rounded-md border border-[var(--border-color)]/50 text-[var(--muted)] bg-transparent hover:bg-[var(--background)] hover:text-[var(--foreground)] transition-colors"
>
{t.common?.cancel || 'Cancel'}
</button>
<button
type="button"
onClick={onSubmit}
disabled={isSubmitting}
className="px-4 py-2 text-sm font-medium rounded-md border border-transparent bg-[var(--accent-primary)]/90 text-white hover:bg-[var(--accent-primary)] transition-colors disabled:opacity-50 disabled:cursor-not-allowed"
>
{isSubmitting ? (t.common?.processing || 'Processing...') : (t.common?.generateWiki || 'Generate Wiki')}
</button>
</div>
</div>
</div>
</div>
);
}
|