From 0d7b684c7790f0ea2a54b63e16ddbab6c37b6ee4 Mon Sep 17 00:00:00 2001 From: sazzadulalambd Date: Sun, 10 May 2026 02:27:17 +0600 Subject: [PATCH] feat: refactor rental plans to use IDs, add support for EV models, and enable dynamic plan creation --- src/app/admin/settings/page.tsx | 480 ++++++++++++++++++-------------- 1 file changed, 274 insertions(+), 206 deletions(-) diff --git a/src/app/admin/settings/page.tsx b/src/app/admin/settings/page.tsx index beca5a7..0adf4d2 100644 --- a/src/app/admin/settings/page.tsx +++ b/src/app/admin/settings/page.tsx @@ -93,8 +93,9 @@ interface CompanySettings { }; plans: { singleRent: { - tier: 'Economy' | 'Standard' | 'Premium'; + id: string; name: string; + evModels: string[]; contractMonths: number[]; dailyRent: number; dailyRentPenalty1: number; @@ -113,8 +114,9 @@ interface CompanySettings { description: string; }[]; rentToOwn: { - tier: 'Economy' | 'Standard' | 'Premium'; + id: string; name: string; + evModels: string[]; contractMonths: number[]; dailyRent: number; dailyRentPenalty1: number; @@ -138,8 +140,9 @@ interface CompanySettings { description: string; }[]; shareEv: { - tier: 'Economy' | 'Standard' | 'Premium'; + id: string; name: string; + evModels: string[]; contractMonths: number[]; dailyRentEach: number; dailyRentPenalty1: number; @@ -445,8 +448,9 @@ const initialSettings: CompanySettings = { plans: { singleRent: [ { - tier: 'Premium', + id: 'sr-1', name: 'Single Rent - Premium', + evModels: [], contractMonths: [1, 3, 6, 12], dailyRent: 400, dailyRentPenalty1: 500, @@ -465,8 +469,9 @@ const initialSettings: CompanySettings = { description: 'Premium single person rental plan with extra benefits', }, { - tier: 'Standard', + id: 'sr-2', name: 'Single Rent - Standard', + evModels: [], contractMonths: [1, 3, 6, 12], dailyRent: 300, dailyRentPenalty1: 400, @@ -485,8 +490,9 @@ const initialSettings: CompanySettings = { description: 'Standard single person rental plan', }, { - tier: 'Economy', + id: 'sr-3', name: 'Single Rent - Economy', + evModels: [], contractMonths: [1, 3, 6, 12], dailyRent: 250, dailyRentPenalty1: 300, @@ -507,8 +513,9 @@ const initialSettings: CompanySettings = { ], rentToOwn: [ { - tier: 'Premium', + id: 'rto-1', name: 'Rent to Own - Premium', + evModels: [], contractMonths: [12, 18, 24, 36], dailyRent: 350, dailyRentPenalty1: 450, @@ -532,8 +539,9 @@ const initialSettings: CompanySettings = { description: 'Premium rent to own plan with high-end EV', }, { - tier: 'Standard', + id: 'rto-2', name: 'Rent to Own - Standard', + evModels: [], contractMonths: [12, 18, 24, 36], dailyRent: 250, dailyRentPenalty1: 350, @@ -557,8 +565,9 @@ const initialSettings: CompanySettings = { description: 'Standard rent to own plan', }, { - tier: 'Economy', + id: 'rto-3', name: 'Rent to Own - Economy', + evModels: [], contractMonths: [12, 18, 24, 36], dailyRent: 200, dailyRentPenalty1: 250, @@ -584,8 +593,9 @@ const initialSettings: CompanySettings = { ], shareEv: [ { - tier: 'Premium', + id: 'se-1', name: 'Share an EV - Premium', + evModels: [], contractMonths: [1, 3, 6, 12], dailyRentEach: 300, dailyRentPenalty1: 400, @@ -611,8 +621,9 @@ const initialSettings: CompanySettings = { description: 'Premium shared EV with premium bikes', }, { - tier: 'Standard', + id: 'se-2', name: 'Share an EV - Standard', + evModels: [], contractMonths: [1, 3, 6, 12], dailyRentEach: 200, dailyRentPenalty1: 250, @@ -638,8 +649,9 @@ const initialSettings: CompanySettings = { description: 'Standard shared EV plan', }, { - tier: 'Economy', + id: 'se-3', name: 'Share an EV - Economy', + evModels: [], contractMonths: [1, 3, 6, 12], dailyRentEach: 150, dailyRentPenalty1: 200, @@ -934,6 +946,90 @@ export default function CompanySettingsPage() { setTimeout(() => setSaved(false), 2000); }; + const addNewPlan = (type: 'singleRent' | 'rentToOwn' | 'shareEv') => { + const newId = `${type}-${Date.now()}`; + const defaultPlan = type === 'singleRent' ? { + id: newId, + name: '', + evModels: [], + contractMonths: [1, 3, 6], + dailyRent: 300, + dailyRentPenalty1: 400, + dailyRentPenalty2: 800, + dailyRentPenalty3: 4000, + deposit: 20000, + weeklySubscription: 2100, + weeklyPenalty1: 2600, + weeklyPenalty2: 5200, + weeklyPenalty3: 12000, + monthlySubscription: 9000, + monthlyPenalty1: 11000, + monthlyPenalty2: 22000, + monthlyPenalty3: 40000, + ficoSharePercent: 45, + description: '', + } : type === 'rentToOwn' ? { + id: newId, + name: '', + evModels: [], + contractMonths: [12, 18, 24], + dailyRent: 250, + dailyRentPenalty1: 350, + dailyRentPenalty2: 700, + dailyRentPenalty3: 3500, + deposit: 18000, + weeklySubscription: 1750, + weeklyPenalty1: 2200, + weeklyPenalty2: 4400, + weeklyPenalty3: 10000, + monthlySubscription: 7000, + monthlyPenalty1: 9000, + monthlyPenalty2: 18000, + monthlyPenalty3: 30000, + durationMonths: 18, + evPrice: 120000, + totalPayment: 135000, + profit: 15000, + ficoRentSharePercent: 45, + ficoProfitSharePercent: 45, + description: '', + } : { + id: newId, + name: '', + evModels: [], + contractMonths: [1, 3, 6], + dailyRentEach: 200, + dailyRentPenalty1: 250, + dailyRentPenalty2: 500, + dailyRentPenalty3: 2500, + totalDailyRent: 400, + depositEach: 15000, + depositPenalty1: 18000, + depositPenalty2: 25000, + depositPenalty3: 40000, + totalDeposit: 30000, + weeklySubscriptionEach: 1400, + weeklyPenalty1: 1800, + weeklyPenalty2: 3500, + weeklyPenalty3: 8000, + totalWeeklySubscription: 2800, + monthlySubscriptionEach: 5600, + monthlyPenalty1: 7000, + monthlyPenalty2: 14000, + monthlyPenalty3: 25000, + totalMonthlySubscription: 11200, + ficoSharePercent: 45, + description: '', + }; + if (type === 'singleRent') { + setSettings({ ...settings, plans: { ...settings.plans, singleRent: [...settings.plans.singleRent, defaultPlan as typeof settings.plans.singleRent[number]] } }); + } else if (type === 'rentToOwn') { + setSettings({ ...settings, plans: { ...settings.plans, rentToOwn: [...settings.plans.rentToOwn, defaultPlan as typeof settings.plans.rentToOwn[number]] } }); + } else { + setSettings({ ...settings, plans: { ...settings.plans, shareEv: [...settings.plans.shareEv, defaultPlan as typeof settings.plans.shareEv[number]] } }); + } + }; + const addPolicyRule = (tab: 'investor' | 'merchant' | 'swapstation') => { if (!newPolicyName.trim()) return; const newRule = { title: newPolicyName, description: newPolicyDesc || '

' }; @@ -2347,19 +2443,52 @@ export default function CompanySettingsPage() { {activePlanTab === 'singleRent' && (
{settings.plans.singleRent.map((plan, idx) => ( -
+
-

SINGLE RENT - {plan.tier} - ৳{plan.dailyRent}/day

+

{plan.name} - ৳{plan.dailyRent}/day