Temuulen Ankhbayar 454fb29c85 fix: reset order config state when selecting a new plan and validate MNP phone length
Order wizard was skipping steps (jumping to add-ons) due to stale currentStep
persisting in localStorage from previous orders. Reset store on plan selection
and exclude currentStep from persistence. Also add max(11) validation on MNP
phone number to prevent Salesforce STRING_TOO_LONG errors.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-07 11:07:51 +09:00

50 lines
1.6 KiB
TypeScript

"use client";
import { useMemo, useState } from "react";
import { useRouter } from "next/navigation";
import type { SimCatalogProduct } from "@customer-portal/domain/services";
import { useAccountSimCatalog } from "@/features/services/hooks";
import { useServicesBasePath } from "@/features/services/hooks/useServicesBasePath";
import { useCatalogStore } from "@/features/services/stores/services.store";
import {
SimPlansContent,
type SimPlansTab,
} from "@/features/services/components/sim/SimPlansContent";
/**
* Account SIM Plans Container
*
* Fetches account context (payment methods + personalised catalog) and
* renders the shared SIM plans UI.
*/
export function SimPlansContainer() {
const router = useRouter();
const servicesBasePath = useServicesBasePath();
const { data, error } = useAccountSimCatalog();
const plans: SimCatalogProduct[] = useMemo(() => data?.plans ?? [], [data?.plans]);
// Simple loading check: show skeleton until we have data or an error
const isLoading = !data && !error;
const [activeTab, setActiveTab] = useState<SimPlansTab>("data-voice");
const handleSelectPlan = (planSku: string) => {
const { resetSimConfig, setSimConfig } = useCatalogStore.getState();
resetSimConfig();
setSimConfig({ planSku, currentStep: 1 });
router.push(`${servicesBasePath}/sim/configure?planSku=${encodeURIComponent(planSku)}`);
};
return (
<SimPlansContent
variant="account"
plans={plans}
isLoading={isLoading}
error={error}
activeTab={activeTab}
onTabChange={setActiveTab}
onSelectPlan={handleSelectPlan}
/>
);
}
export default SimPlansContainer;