SIM-Karten: PIN/PUK-Fehler statt stummer Alert-Meldung

Der bisherige alert() maskierte die eigentliche Ursache (Vertrag
nicht gefunden / Kein Zugriff / Decrypt-Fehler). Ersetzt durch
Toast mit Backend-Message + console.error mit Stacktrace, plus
Info-Toast wenn die SIM in der DB gar keine PIN/PUK hinterlegt hat.

Endpoint (GET /contracts/simcard/:id/credentials) und Auditing
unverändert.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-07-17 14:45:20 +02:00
co-authored by Claude Opus 4.7
parent e743e6795b
commit aeecc3327f
@@ -15,6 +15,7 @@ import Input from '../../components/ui/Input';
import Modal from '../../components/ui/Modal';
import FileUpload from '../../components/ui/FileUpload';
import { Edit, Trash2, Copy, Eye, EyeOff, ArrowLeft, ArrowRight, Download, ExternalLink, Plus, ChevronDown, ChevronUp, Gauge, CheckCircle, Circle, ClipboardList, MessageSquare, Calculator, Info, X, BellOff, Lock, Shield, FileText, Images } from 'lucide-react';
import toast from 'react-hot-toast';
import JpgToPdfModal from '../../components/ui/JpgToPdfModal';
import { calculateConsumption, calculateCosts, calculateMultiMeterConsumption } from '../../utils/energyCalculations';
import CopyButton, { CopyableBlock } from '../../components/ui/CopyButton';
@@ -122,20 +123,28 @@ function SimCardDisplay({ simCard }: { simCard: SimCard }) {
if (showCredentials) {
setShowCredentials(false);
setCredentials(null);
} else {
return;
}
setIsLoading(true);
try {
const res = await contractApi.getSimCardCredentials(simCard.id);
if (res.data) {
if (!res?.data) {
toast.error('Backend lieferte keine PIN/PUK-Daten zurück');
return;
}
if (!res.data.pin && !res.data.puk) {
toast('Für diese SIM sind keine PIN/PUK hinterlegt', { icon: '️' });
}
setCredentials(res.data);
setShowCredentials(true);
}
} catch (err) {
alert('PIN/PUK konnte nicht geladen werden');
const msg = err instanceof Error ? err.message : 'Unbekannter Fehler';
// eslint-disable-next-line no-console
console.error('[SimCardDisplay] getSimCardCredentials failed:', err);
toast.error(`PIN/PUK konnte nicht geladen werden: ${msg}`);
} finally {
setIsLoading(false);
}
}
};
return (