"use client"; import React, { useState, useEffect } from 'react'; import { DevicePhoneMobileIcon, ExclamationTriangleIcon, ArrowPathIcon } from '@heroicons/react/24/outline'; import { SimDetailsCard, type SimDetails } from './SimDetailsCard'; import { DataUsageChart, type SimUsage } from './DataUsageChart'; import { SimActions } from './SimActions'; import { authenticatedApi } from '@/lib/api'; interface SimManagementSectionProps { subscriptionId: number; } interface SimInfo { details: SimDetails; usage: SimUsage; } export function SimManagementSection({ subscriptionId }: SimManagementSectionProps) { const [simInfo, setSimInfo] = useState(null); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const fetchSimInfo = async () => { try { setError(null); const data = await authenticatedApi.get<{ details: SimDetails; usage: SimUsage; }>(`/subscriptions/${subscriptionId}/sim`); setSimInfo(data); } catch (error: any) { if (error.status === 400) { // Not a SIM subscription - this component shouldn't be shown setError('This subscription is not a SIM service'); } else { setError(error instanceof Error ? error.message : 'Failed to load SIM information'); } } finally { setLoading(false); } }; useEffect(() => { fetchSimInfo(); }, [subscriptionId]); const handleRefresh = () => { setLoading(true); fetchSimInfo(); }; const handleActionSuccess = () => { // Refresh SIM info after any successful action fetchSimInfo(); }; if (loading) { return (

SIM Management

); } if (error) { return (

SIM Management

Unable to Load SIM Information

{error}

); } if (!simInfo) { return null; } return (
{/* Section Header */}

SIM Management

Manage your SIM service and data usage

{/* SIM Details */} {/* Data Usage */} {/* SIM Actions */} {/* Additional Information */}

Important Information

  • • Data usage is updated in real-time and may take a few minutes to reflect recent activity
  • • Top-up data will be available immediately after successful processing
  • • SIM cancellation is permanent and cannot be undone
  • {simInfo.details.simType === 'esim' && (
  • • eSIM profile reissue will provide a new QR code for activation
  • )}
); }