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
+21 -12
View File
@@ -15,6 +15,7 @@ import Input from '../../components/ui/Input';
import Modal from '../../components/ui/Modal'; import Modal from '../../components/ui/Modal';
import FileUpload from '../../components/ui/FileUpload'; 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 { 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 JpgToPdfModal from '../../components/ui/JpgToPdfModal';
import { calculateConsumption, calculateCosts, calculateMultiMeterConsumption } from '../../utils/energyCalculations'; import { calculateConsumption, calculateCosts, calculateMultiMeterConsumption } from '../../utils/energyCalculations';
import CopyButton, { CopyableBlock } from '../../components/ui/CopyButton'; import CopyButton, { CopyableBlock } from '../../components/ui/CopyButton';
@@ -122,19 +123,27 @@ function SimCardDisplay({ simCard }: { simCard: SimCard }) {
if (showCredentials) { if (showCredentials) {
setShowCredentials(false); setShowCredentials(false);
setCredentials(null); setCredentials(null);
} else { return;
setIsLoading(true); }
try { setIsLoading(true);
const res = await contractApi.getSimCardCredentials(simCard.id); try {
if (res.data) { const res = await contractApi.getSimCardCredentials(simCard.id);
setCredentials(res.data); if (!res?.data) {
setShowCredentials(true); toast.error('Backend lieferte keine PIN/PUK-Daten zurück');
} return;
} catch (err) {
alert('PIN/PUK konnte nicht geladen werden');
} finally {
setIsLoading(false);
} }
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) {
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);
} }
}; };