"use client"; import React, { useState } from 'react'; import { PlusIcon, ArrowPathIcon, XMarkIcon, ExclamationTriangleIcon, CheckCircleIcon } from '@heroicons/react/24/outline'; import { TopUpModal } from './TopUpModal'; import { authenticatedApi } from '@/lib/api'; interface SimActionsProps { subscriptionId: number; simType: 'physical' | 'esim'; status: string; onTopUpSuccess?: () => void; onPlanChangeSuccess?: () => void; onCancelSuccess?: () => void; onReissueSuccess?: () => void; } export function SimActions({ subscriptionId, simType, status, onTopUpSuccess, onPlanChangeSuccess, onCancelSuccess, onReissueSuccess }: SimActionsProps) { const [showTopUpModal, setShowTopUpModal] = useState(false); const [showCancelConfirm, setShowCancelConfirm] = useState(false); const [showReissueConfirm, setShowReissueConfirm] = useState(false); const [loading, setLoading] = useState(null); const [error, setError] = useState(null); const [success, setSuccess] = useState(null); const isActive = status === 'active'; const canTopUp = isActive; const canReissue = isActive && simType === 'esim'; const canCancel = isActive; const handleReissueEsim = async () => { setLoading('reissue'); setError(null); try { await authenticatedApi.post(`/subscriptions/${subscriptionId}/sim/reissue-esim`); setSuccess('eSIM profile reissued successfully'); setShowReissueConfirm(false); onReissueSuccess?.(); } catch (error: any) { setError(error instanceof Error ? error.message : 'Failed to reissue eSIM profile'); } finally { setLoading(null); } }; const handleCancelSim = async () => { setLoading('cancel'); setError(null); try { await authenticatedApi.post(`/subscriptions/${subscriptionId}/sim/cancel`, {}); setSuccess('SIM service cancelled successfully'); setShowCancelConfirm(false); onCancelSuccess?.(); } catch (error: any) { setError(error instanceof Error ? error.message : 'Failed to cancel SIM service'); } finally { setLoading(null); } }; // Clear success/error messages after 5 seconds React.useEffect(() => { if (success || error) { const timer = setTimeout(() => { setSuccess(null); setError(null); }, 5000); return () => clearTimeout(timer); } }, [success, error]); return (
{/* Header */}

SIM Management Actions

Manage your SIM service

{/* Content */}
{/* Status Messages */} {success && (

{success}

)} {error && (

{error}

)} {!isActive && (

SIM management actions are only available for active services.

)} {/* Action Buttons */}
{/* Top Up Data */} {/* Reissue eSIM (only for eSIMs) */} {simType === 'esim' && ( )} {/* Cancel SIM */}
{/* Action Descriptions */}
Top Up Data: Add additional data quota to your SIM service. You can choose the amount and schedule it for later if needed.
{simType === 'esim' && (
Reissue eSIM: Generate a new eSIM profile for download. Use this if your previous download failed or you need to install on a new device.
)}
Cancel SIM: Permanently cancel your SIM service. This action cannot be undone and will terminate your service immediately.
{/* Top Up Modal */} {showTopUpModal && ( setShowTopUpModal(false)} onSuccess={() => { setShowTopUpModal(false); setSuccess('Data top-up completed successfully'); onTopUpSuccess?.(); }} onError={(message) => setError(message)} /> )} {/* Reissue eSIM Confirmation */} {showReissueConfirm && (

Reissue eSIM Profile

This will generate a new eSIM profile for download. Your current eSIM will remain active until you activate the new profile.

)} {/* Cancel Confirmation */} {showCancelConfirm && (

Cancel SIM Service

Are you sure you want to cancel this SIM service? This action cannot be undone and will permanently terminate your service.

)}
); }