import { useEffect, useState } from 'react'; import { useNavigate } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { Settings, Pencil, Trash2, Plus } from 'lucide-react'; import { credentials } from '../../api'; import type { Credential } from '../../api'; import { Breadcrumbs, Button, Card, ContextMenu, DescriptionList, Timestamp } from '../../ui'; import styles from '../Page.module.css'; function CredentialCard({ credential, onDelete, }: { credential: Credential; onDelete: (id: number) => void; }) { const { t } = useTranslation(); const navigate = useNavigate(); const header = (
{credential.name}
e.stopPropagation()}> } items={[ { label: t('credentials.action_edit'), icon: , onClick: () => navigate(`/credentials/${credential.id}/edit`), }, { label: t('credentials.action_delete'), icon: , variant: 'danger', onClick: () => onDelete(credential.id), }, ]} />
); const footer = (
#{credential.id}
); return ( navigate(`/credentials/${credential.id}`)} > : '—', }, ]} /> ); } function AddCredentialCard() { const { t } = useTranslation(); const navigate = useNavigate(); return (
); } export function CredentialsPage() { const { t } = useTranslation(); const [items, setItems] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const load = () => { credentials .list() .then((res) => setItems(res.data)) .catch((err: Error) => setError(err.message)) .finally(() => setLoading(false)); }; useEffect(() => { load(); }, []); const handleDelete = async (id: number) => { await credentials.remove(id); setItems((prev) => prev.filter((c) => c.id !== id)); }; return (
{error &&

{error}

} {loading ? (

{t('credentials.loading')}

) : (
{items.map((credential) => ( ))}
)}
); }