"use client"; import React, { useState } from "react"; import { apiClient } from "@/lib/api"; import { XMarkIcon } from "@heroicons/react/24/outline"; import { mapToSimplifiedFormat } from "../utils/plan"; 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 = ["5GB", "10GB", "25GB", "50GB"] as const; type PlanCode = (typeof PLAN_CODES)[number]; const normalizedCurrentPlan = mapToSimplifiedFormat(currentPlanCode); const allowedPlans = (PLAN_CODES as readonly PlanCode[]).filter( code => code !== (normalizedCurrentPlan as PlanCode) ); const [newPlanCode, setNewPlanCode] = useState<"" | PlanCode>(""); const [loading, setLoading] = useState(false); const submit = async () => { if (!newPlanCode) { onError("Please select a new plan"); return; } setLoading(true); try { await apiClient.POST("/api/subscriptions/{id}/sim/change-plan", { params: { path: { id: subscriptionId } }, body: { newPlanCode, }, }); onSuccess(); } catch (e: unknown) { onError(e instanceof Error ? e.message : "Failed to change plan"); } finally { setLoading(false); } }; return (
Only plans different from your current plan are listed. The change will be scheduled for the 1st of the next month.