import { useEffect, useState } from 'react'; import { useNavigate, useParams } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { Upload, Pencil, Trash2 } from 'lucide-react'; import { CodeBlock } from '../../ui'; import { stringify as yamlStringify } from 'yaml'; import { credentials } from '../../api'; import type { Credential } from '../../api'; import { Breadcrumbs, Button, Card, DescriptionList, Notification, Timestamp, UuidBadge } from '../../ui'; import styles from '../Page.module.css'; export function CredentialDetailPage() { const { t } = useTranslation(); const { id } = useParams<{ id: string }>(); const navigate = useNavigate(); const [credential, setCredential] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); useEffect(() => { if (!id) return; credentials .get(id) .then(setCredential) .catch((err: Error) => setError(err.message)) .finally(() => setLoading(false)); }, [id]); const handleDelete = async () => { if (!credential) return; await credentials.remove(credential.id); navigate('/credentials'); }; const handleExport = async () => { if (!credential) return; const data = await credentials.exportCredential(credential.id); const blob = new Blob([yamlStringify(data)], { type: 'application/yaml' }); const url = URL.createObjectURL(blob); const a = document.createElement('a'); a.href = url; a.download = `credential-${credential.name}.yaml`; a.click(); URL.revokeObjectURL(url); }; return (
navigate('/credentials') }, { label: credential?.name ?? `#${id}` }, ]} /> {credential && (
)}
{error && ( {error.startsWith('404') ? t('errors.not_found_credential', { id }) : error} )} {loading &&

{t('credentials.loading')}

} {credential && ( <>
}, { term: t('credentials.field_last_used'), detail: credential.lastUsedAt ? ( ) : ( '—' ), }, { term: t('credentials.field_created'), detail: , }, { term: t('credentials.field_updated'), detail: , }, ]} />
{credential.data && ( <>

{t('credentials.section_data')}

{ try { return JSON.stringify(JSON.parse(credential.data), null, 2); } catch { return credential.data; } })()} /> )} )}
); }