From 2325cf2753fc0b8cefaeda45f0587af316244103 Mon Sep 17 00:00:00 2001 From: tema Date: Mon, 8 Sep 2025 18:45:00 +0900 Subject: [PATCH] Refactor Freebit plan change request and improve error handling - Updated FreebititPlanChangeRequest interface to use 'planCode' instead of 'plancode' for consistency. - Enhanced error handling in WhmcsInvoiceService to provide a default message for payment errors. - Removed unused state variables for global IP assignment and scheduling in SIM change plan components to streamline the user interface. --- .../src/vendors/freebit/freebit.service.ts | 2 +- .../freebit/interfaces/freebit.types.ts | 2 +- .../whmcs/services/whmcs-invoice.service.ts | 2 +- .../[id]/sim/change-plan/page.tsx | 14 ---------- .../components/ChangePlanModal.tsx | 28 +------------------ 5 files changed, 4 insertions(+), 44 deletions(-) diff --git a/apps/bff/src/vendors/freebit/freebit.service.ts b/apps/bff/src/vendors/freebit/freebit.service.ts index 6785da4d..c85f801b 100644 --- a/apps/bff/src/vendors/freebit/freebit.service.ts +++ b/apps/bff/src/vendors/freebit/freebit.service.ts @@ -467,7 +467,7 @@ export class FreebititService { try { const request: Omit = { account, - plancode: newPlanCode, + planCode: newPlanCode, globalip: options.assignGlobalIp ? '1' : '0', runTime: options.scheduledAt, }; diff --git a/apps/bff/src/vendors/freebit/interfaces/freebit.types.ts b/apps/bff/src/vendors/freebit/interfaces/freebit.types.ts index 37a3c086..a06f386a 100644 --- a/apps/bff/src/vendors/freebit/interfaces/freebit.types.ts +++ b/apps/bff/src/vendors/freebit/interfaces/freebit.types.ts @@ -164,7 +164,7 @@ export interface FreebititQuotaHistoryResponse { export interface FreebititPlanChangeRequest { authKey: string; account: string; - plancode: string; + planCode: string; globalip?: '0' | '1'; // 0=no IP, 1=assign global IP runTime?: string; // YYYYMMDD - optional, immediate if omitted } diff --git a/apps/bff/src/vendors/whmcs/services/whmcs-invoice.service.ts b/apps/bff/src/vendors/whmcs/services/whmcs-invoice.service.ts index dcebf99d..373b883f 100644 --- a/apps/bff/src/vendors/whmcs/services/whmcs-invoice.service.ts +++ b/apps/bff/src/vendors/whmcs/services/whmcs-invoice.service.ts @@ -370,7 +370,7 @@ export class WhmcsInvoiceService { }); // Return user-friendly error message instead of technical API error - const userFriendlyError = this.getUserFriendlyPaymentError(response.message || response.error); + const userFriendlyError = this.getUserFriendlyPaymentError(response.message || response.error || 'Unknown payment error'); return { success: false, diff --git a/apps/portal/src/app/subscriptions/[id]/sim/change-plan/page.tsx b/apps/portal/src/app/subscriptions/[id]/sim/change-plan/page.tsx index a55ebd88..8823c2ee 100644 --- a/apps/portal/src/app/subscriptions/[id]/sim/change-plan/page.tsx +++ b/apps/portal/src/app/subscriptions/[id]/sim/change-plan/page.tsx @@ -20,8 +20,6 @@ export default function SimChangePlanPage() { 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); @@ -40,8 +38,6 @@ export default function SimChangePlanPage() { try { await authenticatedApi.post(`/subscriptions/${subscriptionId}/sim/change-plan`, { newPlanCode, - assignGlobalIp, - scheduledAt: scheduledAt ? scheduledAt.replace(/-/g, "") : undefined, }); setMessage("Plan change submitted successfully"); } catch (e: any) { @@ -78,16 +74,6 @@ export default function SimChangePlanPage() { -
- 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 diff --git a/apps/portal/src/features/sim-management/components/ChangePlanModal.tsx b/apps/portal/src/features/sim-management/components/ChangePlanModal.tsx index c12cf386..fef89f7a 100644 --- a/apps/portal/src/features/sim-management/components/ChangePlanModal.tsx +++ b/apps/portal/src/features/sim-management/components/ChangePlanModal.tsx @@ -25,8 +25,6 @@ export function ChangePlanModal({ subscriptionId, currentPlanCode, onClose, onSu const allowedPlans = (PLAN_CODES as readonly PlanCode[]).filter(code => code !== (currentPlanCode || '')); const [newPlanCode, setNewPlanCode] = useState<"" | PlanCode>(""); - const [assignGlobalIp, setAssignGlobalIp] = useState(false); - const [scheduledAt, setScheduledAt] = useState(""); // YYYY-MM-DD const [loading, setLoading] = useState(false); const submit = async () => { @@ -38,8 +36,6 @@ export function ChangePlanModal({ subscriptionId, currentPlanCode, onClose, onSu try { await authenticatedApi.post(`/subscriptions/${subscriptionId}/sim/change-plan`, { newPlanCode: newPlanCode, - assignGlobalIp, - scheduledAt: scheduledAt ? scheduledAt.replaceAll("-", "") : undefined, }); onSuccess(); } catch (e: any) { @@ -78,29 +74,7 @@ export function ChangePlanModal({ subscriptionId, currentPlanCode, onClose, onSu ))} -

Only plans different from your current plan are listed.

-
-
- setAssignGlobalIp(e.target.checked)} - className="h-4 w-4 text-blue-600 border-gray-300 rounded" - /> - -
-
- - setScheduledAt(e.target.value)} - className="mt-1 block w-full rounded-md border-gray-300 shadow-sm focus:border-blue-500 focus:ring-blue-500 text-sm" - /> -

If empty, the plan change is processed immediately.

+

Only plans different from your current plan are listed. The change will be scheduled for the 1st of the next month.