import { useEffect, useRef, useState } from 'react';
import { useNavigate } from 'react-router-dom';
import { useTranslation } from 'react-i18next';
import { usePageTitle } from '../../hooks/usePageTitle';
import { useImportFile } from '../../hooks/useImportFile';
import { Settings, Pencil, Trash2, Plus, Download, KeyRound } from 'lucide-react';
import { credentials } from '../../api';
import type { Credential } from '../../api';
import {
Breadcrumbs,
Button,
Card,
ContextMenu,
DescriptionList,
Timestamp,
UuidBadge,
} from '../../ui';
import { DeleteConfirmationModal } from '../../components/modals';
import styles from '../Page.module.css';
function CredentialCard({
credential,
onDelete,
}: {
credential: Credential;
onDelete: (id: string) => 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 = (
);
return (
navigate(`/credentials/${credential.id}`)}
>
: '—',
},
]}
/>
);
}
function AddCredentialCard() {
const { t } = useTranslation();
const navigate = useNavigate();
return (
);
}
export function CredentialsPage() {
const { t } = useTranslation();
usePageTitle(t('credentials.title'));
const [items, setItems] = useState([]);
const [loading, setLoading] = useState(true);
const [deleteId, setDeleteId] = useState(null);
const [deleting, setDeleting] = useState(false);
const fileInputRef = useRef(null);
const load = () => {
credentials
.list()
.then((res) => setItems(res.data))
.finally(() => setLoading(false));
};
useEffect(() => {
load();
}, []);
const requestDelete = (id: string) => {
setDeleteId(id);
};
const handleDelete = async () => {
if (!deleteId) return;
setDeleting(true);
try {
await credentials.remove(deleteId);
setItems((prev) => prev.filter((c) => c.id !== deleteId));
setDeleteId(null);
} finally {
setDeleting(false);
}
};
const handleImport = useImportFile('credential');
return (
{loading ? (
{t('credentials.loading')}
) : (
{items.map((credential) => (
))}
)}
setDeleteId(null)}
onConfirm={handleDelete}
isDeleting={deleting}
/>
);
}