Files
Netcatty/components/keychain/IdentityPanel.tsx
T
LAPTOP-O016UC3M\Qi Chen bcad0c6865 Refactors UI and Electron main into modular subcomponents
Extracts major UI panels, file transfer, terminal controls, and SFTP logic into dedicated subcomponents for improved maintainability and clarity.
Modularizes Electron main process, delegating SSH, SFTP, terminal, port forwarding, and window management to bridge modules, reducing complexity and centralizing IPC registration.

Enables easier future development, clearer separation of concerns, and better scalability by making both frontend and backend architectures more modular and easier to reason about.
2025-12-11 15:20:42 +08:00

150 lines
6.4 KiB
TypeScript

/**
* Identity Panel - Create/Edit identity
*/
import React from 'react';
import { Identity, SSHKey } from '../../types';
import { Label } from '../ui/label';
import { Input } from '../ui/input';
import { Button } from '../ui/button';
import { Dropdown, DropdownTrigger, DropdownContent } from '../ui/dropdown';
import { User, Key, BadgeCheck, Shield, ChevronDown, Eye, EyeOff } from 'lucide-react';
interface IdentityPanelProps {
draftIdentity: Partial<Identity>;
setDraftIdentity: (identity: Partial<Identity>) => void;
keys: SSHKey[];
showPassphrase: boolean;
setShowPassphrase: (show: boolean) => void;
isNew: boolean;
onSave: () => void;
}
export const IdentityPanel: React.FC<IdentityPanelProps> = ({
draftIdentity,
setDraftIdentity,
keys,
showPassphrase,
setShowPassphrase,
isNew,
onSave,
}) => {
return (
<>
<div className="flex items-center gap-3 mb-4">
<div className="h-10 w-10 rounded-lg bg-green-500/15 text-green-500 flex items-center justify-center">
<User size={20} />
</div>
<Input
value={draftIdentity.label || ''}
onChange={e => setDraftIdentity({ ...draftIdentity, label: e.target.value })}
placeholder="Label"
className="flex-1"
/>
</div>
<div className="space-y-2">
<Label>Username *</Label>
<div className="relative">
<User size={14} className="absolute left-3 top-1/2 -translate-y-1/2 text-muted-foreground" />
<Input
value={draftIdentity.username || ''}
onChange={e => setDraftIdentity({ ...draftIdentity, username: e.target.value })}
placeholder="Username"
className="pl-9"
/>
</div>
</div>
<div className="space-y-2">
<Label>Password</Label>
<div className="relative">
<Input
type={showPassphrase ? 'text' : 'password'}
value={draftIdentity.password || ''}
onChange={e => setDraftIdentity({ ...draftIdentity, password: e.target.value })}
placeholder="Password"
className="pr-10"
/>
<Button
type="button"
variant="ghost"
size="icon"
className="absolute right-1 top-1/2 -translate-y-1/2 h-8 w-8"
onClick={() => setShowPassphrase(!showPassphrase)}
>
{showPassphrase ? <EyeOff size={14} /> : <Eye size={14} />}
</Button>
</div>
</div>
<div className="space-y-2">
<Label>Authentication Method</Label>
<Dropdown>
<DropdownTrigger asChild>
<Button variant="secondary" className="w-full justify-between h-10">
<span className="flex items-center gap-2">
{draftIdentity.authMethod === 'key' && <><Key size={14} /> Key</>}
{draftIdentity.authMethod === 'certificate' && <><BadgeCheck size={14} /> Certificate</>}
{draftIdentity.authMethod === 'fido2' && <><Shield size={14} /> FIDO2</>}
{(!draftIdentity.authMethod || draftIdentity.authMethod === 'password') && 'None (Password only)'}
</span>
<ChevronDown size={14} />
</Button>
</DropdownTrigger>
<DropdownContent className="w-56" align="start">
<Button
variant="ghost"
className="w-full justify-start gap-2"
onClick={() => setDraftIdentity({ ...draftIdentity, authMethod: 'key', keyId: undefined })}
>
<Key size={14} /> Key
</Button>
<Button
variant="ghost"
className="w-full justify-start gap-2"
onClick={() => setDraftIdentity({ ...draftIdentity, authMethod: 'certificate', keyId: undefined })}
>
<BadgeCheck size={14} /> Certificate
</Button>
<Button
variant="ghost"
className="w-full justify-start gap-2"
onClick={() => setDraftIdentity({ ...draftIdentity, authMethod: 'fido2', keyId: undefined })}
>
<Shield size={14} /> FIDO2
</Button>
</DropdownContent>
</Dropdown>
</div>
{(draftIdentity.authMethod === 'key' || draftIdentity.authMethod === 'certificate') && (
<div className="space-y-2">
<Label>Select {draftIdentity.authMethod === 'key' ? 'Key' : 'Certificate'}</Label>
<select
value={draftIdentity.keyId || ''}
onChange={e => setDraftIdentity({ ...draftIdentity, keyId: e.target.value || undefined })}
className="flex h-10 w-full rounded-md border border-input bg-background px-3 py-2 text-sm"
>
<option value="">Select...</option>
{keys
.filter(k => draftIdentity.authMethod === 'certificate' ? k.certificate : !k.certificate)
.map(k => (
<option key={k.id} value={k.id}>{k.label}</option>
))
}
</select>
</div>
)}
<Button
className="w-full h-11"
onClick={onSave}
disabled={!draftIdentity.label?.trim() || !draftIdentity.username?.trim()}
>
{isNew ? 'Save Identity' : 'Update Identity'}
</Button>
</>
);
};