"use client"; import Link from "next/link"; import { useParams, useRouter } from "next/navigation"; import { useEffect, useMemo, useState, type ReactNode } from "react"; import { simActionsService } from "@/features/subscriptions/services/sim-actions.service"; import { useAuthStore } from "@/features/auth/services/auth.store"; import type { SimDetails } from "@/features/sim-management/components/SimDetailsCard"; type Step = 1 | 2 | 3; function Notice({ title, children }: { title: string; children: ReactNode }) { return (
{title}
{children}
); } function InfoRow({ label, value }: { label: string; value: string }) { return (
{label}
{value}
); } export function SimCancelContainer() { const params = useParams(); const router = useRouter(); const subscriptionId = params.id as string; const [step, setStep] = useState(1); const [loading, setLoading] = useState(false); const [details, setDetails] = useState(null); const [error, setError] = useState(null); const [message, setMessage] = useState(null); const [acceptTerms, setAcceptTerms] = useState(false); const [confirmMonthEnd, setConfirmMonthEnd] = useState(false); const [cancelMonth, setCancelMonth] = useState(""); const [email, setEmail] = useState(""); const [email2, setEmail2] = useState(""); const [notes, setNotes] = useState(""); const [registeredEmail, setRegisteredEmail] = useState(null); useEffect(() => { const fetchDetails = async () => { try { const info = await simActionsService.getSimInfo(subscriptionId); setDetails(info?.details || null); } catch (e: unknown) { setError(e instanceof Error ? e.message : "Failed to load SIM details"); } }; void fetchDetails(); }, [subscriptionId]); useEffect(() => { const fetchEmail = () => { try { const emailFromStore = useAuthStore.getState().user?.email; if (emailFromStore) { setRegisteredEmail(emailFromStore); return; } } catch { // ignore } }; fetchEmail(); }, []); const monthOptions = useMemo(() => { const opts: { value: string; label: string }[] = []; const now = new Date(); for (let i = 1; i <= 12; i++) { const d = new Date(Date.UTC(now.getUTCFullYear(), now.getUTCMonth() + i, 1)); const y = d.getUTCFullYear(); const m = String(d.getUTCMonth() + 1).padStart(2, "0"); opts.push({ value: `${y}${m}`, label: `${y} / ${m}` }); } return opts; }, []); const canProceedStep2 = !!details; const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; const emailProvided = email.trim().length > 0 || email2.trim().length > 0; const emailValid = !emailProvided || (emailPattern.test(email.trim()) && emailPattern.test(email2.trim())); const emailsMatch = !emailProvided || email.trim() === email2.trim(); const canProceedStep3 = acceptTerms && !!cancelMonth && confirmMonthEnd && emailValid && emailsMatch; const runDate = cancelMonth ? `${cancelMonth}01` : null; const submit = async () => { setLoading(true); setError(null); setMessage(null); if (!runDate) { setError("Please select a cancellation month before submitting."); setLoading(false); return; } try { await simActionsService.cancel(subscriptionId, { scheduledAt: runDate }); setMessage("Cancellation request submitted. You will receive a confirmation email."); setTimeout(() => router.push(`/subscriptions/${subscriptionId}#sim-management`), 1500); } catch (e: unknown) { setError(e instanceof Error ? e.message : "Failed to submit cancellation"); } finally { setLoading(false); } }; return (
← Back to SIM Management
Step {step} of 3
{error && (
{error}
)} {message && (
{message}
)}

Cancel SIM

Cancel SIM: Permanently cancel your SIM service. This action cannot be undone and will terminate your service immediately.

{step === 1 && (

Cancellation takes effect at the start of the selected month.

)} {step === 2 && (
Online cancellations must be made from this website by the 25th of the desired cancellation month. Once a request of a cancellation of the SONIXNET SIM is accepted from this online form, a confirmation email containing details of the SIM plan will be sent to the registered email address. The SIM card is a rental piece of hardware and must be returned to Assist Solutions upon cancellation. The cancellation request through this website retains to your SIM subscriptions only. To cancel any other services with Assist Solutions (home internet etc.) please contact Assist Solutions at info@asolutions.co.jp The SONIXNET SIM has a minimum contract term agreement of three months (sign-up month is not included in the minimum term of three months; ie. sign-up in January = minimum term is February, March, April). If the minimum contract term is not fulfilled, the monthly fees of the remaining months will be charged upon cancellation. Cancellation of option services only (Voice Mail, Call Waiting) while keeping the base plan active is not possible from this online form. Please contact Assist Solutions Customer Support (info@asolutions.co.jp) for more information. Upon cancelling the base plan, all additional options associated with the requested SIM plan will be cancelled. Upon cancellation the SIM phone number will be lost. In order to keep the phone number active to be used with a different cellular provider, a request for an MNP transfer (administrative fee \1,000yen+tax) is necessary. The MNP cannot be requested from this online form. Please contact Assist Solutions Customer Support (info@asolutions.co.jp) for more information.
setAcceptTerms(e.target.checked)} />
setConfirmMonthEnd(e.target.checked)} disabled={!cancelMonth} />
)} {step === 3 && (
{registeredEmail && (
Your registered email address is:{" "} {registeredEmail}
)}
You will receive a cancellation confirmation email. If you would like to receive this email on a different address, please enter the address below.
setEmail(e.target.value)} placeholder="you@example.com" />
setEmail2(e.target.value)} placeholder="you@example.com" />