"use client"; import React, { useState } from "react"; import { authenticatedApi } from "@/lib/api"; import { XMarkIcon } from "@heroicons/react/24/outline"; interface ChangePlanModalProps { subscriptionId: number; currentPlanCode?: string; onClose: () => void; onSuccess: () => void; onError: (message: string) => void; } export function ChangePlanModal({ subscriptionId, currentPlanCode, onClose, onSuccess, onError }: ChangePlanModalProps) { const PLAN_CODES = ["PASI_5G", "PASI_10G", "PASI_25G", "PASI_50G"] as const; type PlanCode = typeof PLAN_CODES[number]; const PLAN_LABELS: Record = { PASI_5G: "5GB", PASI_10G: "10GB", PASI_25G: "25GB", PASI_50G: "50GB", }; const allowedPlans = (PLAN_CODES as readonly PlanCode[]).filter(code => code !== (currentPlanCode || '')); const [newPlanCode, setNewPlanCode] = useState<"" | PlanCode>(""); const [assignGlobalIp, setAssignGlobalIp] = useState(false); const [scheduledAt, setScheduledAt] = useState(""); // YYYY-MM-DD const [loading, setLoading] = useState(false); const submit = async () => { if (!newPlanCode) { onError("Please select a new plan"); return; } setLoading(true); try { await authenticatedApi.post(`/subscriptions/${subscriptionId}/sim/change-plan`, { newPlanCode: newPlanCode, assignGlobalIp, scheduledAt: scheduledAt ? scheduledAt.replaceAll("-", "") : undefined, }); onSuccess(); } catch (e: any) { onError(e instanceof Error ? e.message : "Failed to change plan"); } finally { setLoading(false); } }; return (

Change SIM Plan

Only plans different from your current plan are listed.

setAssignGlobalIp(e.target.checked)} className="h-4 w-4 text-blue-600 border-gray-300 rounded" />
setScheduledAt(e.target.value)} className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 text-sm" />

If empty, the plan change is processed immediately.

); }