"use client"; import { useMemo, useState } from "react"; import Link from "next/link"; import { useParams } from "next/navigation"; import { PageLayout } from "@/components/layout/PageLayout"; import { SubCard } from "@/components/ui/sub-card"; import { DevicePhoneMobileIcon } from "@heroicons/react/24/outline"; import { simActionsService } from "@/features/subscriptions/services/sim-actions.service"; import { AlertBanner } from "@/components/common/AlertBanner"; 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", }; export function SimChangePlanContainer() { const params = useParams(); const subscriptionId = parseInt(params.id as string); const [currentPlanCode] = useState(""); const [newPlanCode, setNewPlanCode] = useState<"" | PlanCode>(""); const [assignGlobalIp, setAssignGlobalIp] = useState(false); const [scheduledAt, setScheduledAt] = useState(""); const [message, setMessage] = useState(null); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); const options = useMemo( () => (PLAN_CODES as readonly PlanCode[]).filter(c => c !== (currentPlanCode as PlanCode)), [currentPlanCode] ); const submit = async (e: React.FormEvent) => { e.preventDefault(); if (!newPlanCode) { setError("Please select a new plan"); return; } setLoading(true); setMessage(null); setError(null); try { await simActionsService.changePlan(subscriptionId, { newPlanCode, assignGlobalIp, scheduledAt: scheduledAt ? scheduledAt.replace(/-/g, "") : undefined, }); setMessage("Plan change submitted successfully"); } catch (e: unknown) { setError(e instanceof Error ? e.message : "Failed to change plan"); } finally { setLoading(false); } }; return ( } title="Change Plan" description="Switch to a different data plan" >
← Back to SIM Management

Change Plan: Switch to a different data plan. Important: Plan changes must be requested before the 25th of the month. Changes will take effect on the 1st of the following month.

{message && (
{message}
)} {error && (
{error}
)}
void submit(e)} className="space-y-6">
setAssignGlobalIp(e.target.checked)} className="h-4 w-4 text-blue-600 border-gray-300 rounded" />
setScheduledAt(e.target.value)} className="w-full px-3 py-2 border border-gray-300 rounded-md" />
Back
); } export default SimChangePlanContainer;