"use client"; import { useEffect, useState } from "react"; import Link from "next/link"; import { useParams } from "next/navigation"; import { PageLayout } from "@/components/templates/PageLayout"; import { SubCard } from "@/components/molecules/SubCard/SubCard"; import { DevicePhoneMobileIcon, CheckCircleIcon } from "@heroicons/react/24/outline"; import { simActionsService } from "@/features/subscriptions/api/sim-actions.api"; import type { SimAvailablePlan } from "@customer-portal/domain/sim"; import { AlertBanner } from "@/components/molecules/AlertBanner/AlertBanner"; import { Formatting } from "@customer-portal/domain/toolkit"; import { Button } from "@/components/atoms"; const { formatCurrency } = Formatting; export function SimChangePlanContainer() { const params = useParams(); const subscriptionId = params["id"] as string; const [plans, setPlans] = useState([]); const [selectedPlan, setSelectedPlan] = useState(null); const [message, setMessage] = useState(null); const [error, setError] = useState(null); const [loading, setLoading] = useState(false); const [loadingPlans, setLoadingPlans] = useState(true); useEffect(() => { const fetchPlans = async () => { try { const availablePlans = await simActionsService.getAvailablePlans(subscriptionId); setPlans(availablePlans); } catch (e: unknown) { setError( process.env.NODE_ENV === "development" ? e instanceof Error ? e.message : "Failed to load available plans" : "Unable to load available plans right now. Please try again." ); } finally { setLoadingPlans(false); } }; void fetchPlans(); }, [subscriptionId]); const currentPlan = plans.find(p => p.isCurrentPlan); const submit = async (e: React.FormEvent) => { e.preventDefault(); if (!selectedPlan) { setError("Please select a new plan"); return; } setLoading(true); setMessage(null); setError(null); try { const result = await simActionsService.changePlanFull(subscriptionId, { newPlanCode: selectedPlan.freebitPlanCode, newPlanSku: selectedPlan.sku, newPlanName: selectedPlan.name, }); setMessage(`Plan change scheduled for ${result.scheduledAt || "the 1st of next month"}`); setSelectedPlan(null); } catch (e: unknown) { setError( process.env.NODE_ENV === "development" ? e instanceof Error ? e.message : "Failed to change plan" : "Unable to submit your plan change right now. Please try again." ); } finally { setLoading(false); } }; return ( } title="Change Plan" description="Switch to a different data plan" >
← Back to SIM Management

Change Your Plan

Select a new plan below. Plan changes will take effect on the 1st of the following month. Changes must be requested before the 25th of the current month.

{message && (
{message}
)} {error && (
{error}
)} {loadingPlans ? (
{[1, 2, 3, 4].map(i => (
))}
) : (
void submit(e)} className="space-y-6"> {/* Current Plan */} {currentPlan && (
Current Plan
{currentPlan.name}
{currentPlan.simDataSize}
{currentPlan.monthlyPrice ? formatCurrency(currentPlan.monthlyPrice) : "—"}
/month
)} {/* Available Plans */}
{plans .filter(p => !p.isCurrentPlan) .map(plan => ( ))}
{/* Info Box */}

Important Notes

  • • Plan changes take effect on the 1st of the following month
  • • Requests must be made before the 25th of the current month
  • • Your current data balance will be reset when the new plan activates
{/* Submit */}
)}
); } export default SimChangePlanContainer;