From 646068dbe34b8f4756442b17d792e885f3f8bc53 Mon Sep 17 00:00:00 2001 From: sazzadulalambd Date: Tue, 19 May 2026 18:55:50 +0600 Subject: [PATCH] refactor: dynamic display of asset details and investment data based on investment type --- src/app/investor/investments/[id]/page.tsx | 220 ++++++++++++++------- src/app/investor/plans/page.tsx | 26 ++- src/data/mockData.ts | 3 + 3 files changed, 173 insertions(+), 76 deletions(-) diff --git a/src/app/investor/investments/[id]/page.tsx b/src/app/investor/investments/[id]/page.tsx index 1293509..7575ad3 100644 --- a/src/app/investor/investments/[id]/page.tsx +++ b/src/app/investor/investments/[id]/page.tsx @@ -34,13 +34,6 @@ export default function InvestorInvestmentDetailPage({ params }: { params: Promi const [activeTab, setActiveTab] = useState('overview'); const [showPaymentModal, setShowPaymentModal] = useState(false); - const paymentHistory: PaymentRecord[] = [ - { id: 'pay1', date: '2024-01-15', amount: Math.round((investment?.totalInvestment || 0) * 0.5), installmentNo: 1, type: 'installment', method: 'Bank Transfer', status: 'completed' }, - { id: 'pay2', date: '2024-02-15', amount: Math.round((investment?.totalInvestment || 0) * 0.25), installmentNo: null, type: 'partial', method: 'bKash', status: 'completed' }, - ]; - - - if (!investment) { return (
@@ -58,6 +51,20 @@ export default function InvestorInvestmentDetailPage({ params }: { params: Promi ); } + const isBattery = investment.assetType === 'battery' || investment.planName?.toLowerCase().includes('battery'); + + const paymentHistory: PaymentRecord[] = [ + { + id: `pay_${investment.id}`, + date: investment.startDate || '2024-02-01', + amount: investment.totalInvestment, + installmentNo: null, + type: 'full', + method: investment.paymentMethod === 'bank' ? 'Bank Transfer' : 'bKash', + status: 'completed' + } + ]; + const totalPaid = paymentHistory.reduce((sum, p) => p.status === 'completed' ? sum + p.amount : sum, 0); const dueAmount = investment.totalInvestment - totalPaid; @@ -69,24 +76,32 @@ export default function InvestorInvestmentDetailPage({ params }: { params: Promi }; const style = planConfig[investment.planType] || planConfig.gold; - const demoBikes = [ - { id: 'b1', model: 'Yadea DT3', brand: 'Yadea', plateNumber: 'AB-1234', image: 'https://images.unsplash.com/photo-1558618666-fcd25c85cd64?w=400&h=300&fit=crop', status: 'rented', currentRent: 450, totalEarnings: 45000, batteryLevel: 85, range: 60, location: 'Dhaka Central Hub' }, - { id: 'b2', model: 'Apex E-Bike Pro', brand: 'Apex', plateNumber: 'CD-5678', image: 'https://images.unsplash.com/photo-1622185135505-2d795043906a?w=400&h=300&fit=crop', status: 'rented', currentRent: 500, totalEarnings: 52000, batteryLevel: 72, range: 55, location: 'Gulshan Area' }, - { id: 'b3', model: 'Niu NQi Sport', brand: 'Niu', plateNumber: 'EF-9012', image: 'https://images.unsplash.com/photo-1591353230407-2b14a8e4c8d3?w=400&h=300&fit=crop', status: 'available', currentRent: 0, totalEarnings: 28000, batteryLevel: 95, range: 70, location: 'Mirpur Depot' }, - { id: 'b4', model: 'Yadea DT3', brand: 'Yadea', plateNumber: 'GH-3456', image: 'https://images.unsplash.com/photo-1558618666-fcd25c85cd64?w=400&h=300&fit=crop', status: 'maintenance', currentRent: 0, totalEarnings: 15000, batteryLevel: 0, range: 0, location: 'Service Center' }, - ]; + const bikeIds = investment.bikeIds || (investmentId === 'ip1' ? ['b1'] : investmentId === 'ip2' ? ['b2'] : []); + const batteryIds = investment.batteryIds || (isBattery ? ['BAT-001', 'BAT-002', 'BAT-005'] : []); - const demoPnl = { grossRevenue: 185000, platformFee: 83250, insurance: 15000, maintenance: 8500, netProfit: 78250 }; + const assignedBikes = [ + { id: 'b1', model: 'Etron ET50', brand: 'Etron', plateNumber: 'Dhaka Metro Cha-1234', image: 'https://images.unsplash.com/photo-1558618666-fcd25c85cd64?w=400&h=300&fit=crop', status: 'rented', currentRent: 350, totalEarnings: 114250, batteryLevel: 78, range: 60, location: 'Gulshan 1' }, + { id: 'b2', model: 'Yadea DT3', brand: 'Yadea', plateNumber: 'Dhaka Metro Cha-5678', image: 'https://images.unsplash.com/photo-1558618666-fcd25c85cd64?w=400&h=300&fit=crop', status: 'available', currentRent: 300, totalEarnings: 12750, batteryLevel: 95, range: 75, location: 'Banani' } + ].filter(bike => bikeIds.includes(bike.id)); - const demoTransactions = [ - { id: 'tx1', date: '2024-05-15', description: 'Rental Income - Bike AB-1234', amount: 450, status: 'completed' }, - { id: 'tx2', date: '2024-05-14', description: 'Rental Income - Bike CD-5678', amount: 500, status: 'completed' }, - { id: 'tx3', date: '2024-05-13', description: 'Rental Income - Bike AB-1234', amount: 450, status: 'completed' }, - { id: 'tx4', date: '2024-05-12', description: 'Rental Income - Bike EF-9012', amount: 350, status: 'completed' }, - { id: 'tx5', date: '2024-05-11', description: 'Rental Income - Bike CD-5678', amount: 500, status: 'completed' }, - { id: 'tx6', date: '2024-05-10', description: 'Withdrawal to Bank', amount: -10000, status: 'completed' }, - { id: 'tx7', date: '2024-05-09', description: 'Rental Income - Bike AB-1234', amount: 450, status: 'completed' }, - { id: 'tx8', date: '2024-05-08', description: 'Rental Income - Bike CD-5678', amount: 500, status: 'completed' }, + const assignedBatteries = [ + { id: 'BAT-001', serialNumber: 'SN-2024-00001', brand: 'EVE Energy', model: 'Li-Ion 60V50Ah', status: 'In-Use', cycleCount: 156, soc: '78% / 95%', earnings: 4500, batteryLevel: 78, location: 'Dhaka Central Hub' }, + { id: 'BAT-002', serialNumber: 'SN-2024-00002', brand: 'EVE Energy', model: 'Li-Ion 60V50Ah', status: 'In-Use', cycleCount: 142, soc: '82% / 96%', earnings: 4500, batteryLevel: 82, location: 'Dhaka Central Hub' }, + { id: 'BAT-005', serialNumber: 'SN-2024-00005', brand: 'EVE Energy', model: 'Li-Ion 60V50Ah', status: 'Available', cycleCount: 88, soc: '91% / 98%', earnings: 0, batteryLevel: 91, location: 'Dhaka Central Hub' } + ].filter(bat => batteryIds.includes(bat.id)); + + const demoPnl = isBattery ? { grossRevenue: 22500, platformFee: 13500, insurance: 0, maintenance: 0, netProfit: 9000 } : { grossRevenue: 185000, platformFee: 83250, insurance: 15000, maintenance: 8500, netProfit: 78250 }; + + const demoTransactions = isBattery ? [ + { id: 'tx-bat-1', date: '2024-03-01', description: 'Monthly Yield Share - BAT-001', amount: 4500, status: 'completed' }, + { id: 'tx-bat-2', date: '2024-02-15', description: 'Monthly Yield Share - BAT-002', amount: 4500, status: 'completed' }, + { id: 'tx-bat-funded', date: investment.startDate || '2024-02-01', description: 'Investment Funded - Standard Battery Plan', amount: investment.totalInvestment, status: 'completed' } + ] : [ + { id: 'tx1', date: '2024-05-15', description: 'Rental Income - Bike Dhaka Metro Cha-1234', amount: 350, status: 'completed' }, + { id: 'tx2', date: '2024-05-14', description: 'Rental Income - Bike Dhaka Metro Cha-5678', amount: 300, status: 'completed' }, + { id: 'tx3', date: '2024-05-13', description: 'Rental Income - Bike Dhaka Metro Cha-1234', amount: 350, status: 'completed' }, + { id: 'tx4', date: '2024-05-12', description: 'Rental Income - Bike Dhaka Metro Cha-5678', amount: 300, status: 'completed' }, + { id: 'tx-funded', date: investment.startDate || '2024-01-15', description: `Investment Funded - ${investment.planName}`, amount: investment.totalInvestment, status: 'completed' } ]; const handlePaymentSubmit = () => { @@ -174,12 +189,18 @@ export default function InvestorInvestmentDetailPage({ params }: { params: Promi
-
- +
+ {isBattery ? ( + + ) : ( + + )}
-

Bikes

+

{isBattery ? 'Batteries' : 'Bikes'}

-

{demoBikes.length}

+

+ {isBattery ? assignedBatteries.length : assignedBikes.length} +

@@ -188,7 +209,7 @@ export default function InvestorInvestmentDetailPage({ params }: { params: Promi
{[ { key: 'overview', label: 'Overview', icon: FileText, count: null }, - { key: 'bikes', label: 'Bikes', icon: Bike, count: demoBikes.length }, + { key: 'bikes', label: isBattery ? 'Batteries' : 'Bikes', icon: isBattery ? Battery : Bike, count: isBattery ? assignedBatteries.length : assignedBikes.length }, { key: 'transactions', label: 'Transactions', icon: CreditCard, count: demoTransactions.length }, { key: 'statement', label: 'Statement', icon: Receipt, count: null }, ].map((tab) => { @@ -257,59 +278,103 @@ export default function InvestorInvestmentDetailPage({ params }: { params: Promi
-
-

- Profit Sharing -

-

Your share based on rental model

-
-
-

Single Rent

-

55%

-
-
-

Rent to Own

-

45%

-
-
-

Share EV

-

40%

+ {isBattery ? ( +
+

+ Profit Sharing +

+

Profit sharing ratio when batteries are utilized

+
+
+

Profit Share

+

40%

+
-
+ ) : ( +
+

+ Profit Sharing +

+

Your share based on rental model

+
+
+

Single Rent

+

40%

+
+
+

Rent to Own

+

50%

+
+
+

Share EV

+

55%

+
+
+
+ )}
)} {activeTab === 'bikes' && ( -
-

{demoBikes.length} bikes assigned to this investment

- {demoBikes.map((bike) => ( -
-
- {bike.model} -
-
-
-
{bike.model}
- {bike.status} + isBattery ? ( +
+

{assignedBatteries.length} battery pack{assignedBatteries.length !== 1 ? 's' : ''} assigned to this investment

+ {assignedBatteries.map((battery) => ( +
+
+
-

{bike.plateNumber} • {bike.brand}

-
- {bike.batteryLevel}% - {bike.range} km - {bike.location} +
+
+
{battery.model}
+ {battery.status} +
+

{battery.serialNumber} • {battery.brand}

+
+ Cycle Count: {battery.cycleCount} + SoC / Health: {battery.soc} + {battery.location} +
+
+
+

Est. Monthly Return

+

৳{(investment.monthlyReturn / assignedBatteries.length).toLocaleString()}

+

Total: ৳{battery.earnings.toLocaleString()}

-
-

Daily Rent

-

৳{bike.currentRent}

-

Total: ৳{bike.totalEarnings.toLocaleString()}

+ ))} +
+ ) : ( +
+

{assignedBikes.length} bike{assignedBikes.length !== 1 ? 's' : ''} assigned to this investment

+ {assignedBikes.map((bike) => ( +
+
+ {bike.model} +
+
+
+
{bike.model}
+ {bike.status} +
+

{bike.plateNumber} • {bike.brand}

+
+ {bike.batteryLevel}% + {bike.location} +
+
+
+

Est. Monthly Return

+

৳{bike.currentRent}

+

Total: ৳{bike.totalEarnings.toLocaleString()}

+
-
- ))} -
+ ))} +
+ ) )} {activeTab === 'statement' && ( @@ -322,12 +387,21 @@ export default function InvestorInvestmentDetailPage({ params }: { params: Promi ৳{demoPnl.grossRevenue.toLocaleString()}
-
Platform Fee (45%)-৳{demoPnl.platformFee.toLocaleString()}
-
Insurance Coverage-৳{demoPnl.insurance.toLocaleString()}
-
Maintenance-৳{demoPnl.maintenance.toLocaleString()}
+
+ Platform Fee {isBattery ? '(60%)' : '(45%)'} + -৳{demoPnl.platformFee.toLocaleString()} +
+
+ Insurance Coverage + -৳{demoPnl.insurance.toLocaleString()} +
+
+ Maintenance + -৳{demoPnl.maintenance.toLocaleString()} +
- Your Share (55%) + Your Share {isBattery ? '(40%)' : '(55%)'} ৳{demoPnl.netProfit.toLocaleString()}
diff --git a/src/app/investor/plans/page.tsx b/src/app/investor/plans/page.tsx index 40273a0..a152ed1 100644 --- a/src/app/investor/plans/page.tsx +++ b/src/app/investor/plans/page.tsx @@ -117,17 +117,37 @@ export default function MyInvestmentsPage() {
+
+ Assigned Assets + + {inv.planName.toLowerCase().includes('battery') || inv.assetType === 'battery' ? ( + `${inv.batteryIds?.length || 3} Batteries` + ) : ( + `${inv.bikeIds?.length || 1} Bike${(inv.bikeIds?.length || 1) > 1 ? 's' : ''}` + )} + +
Duration - 12 months + {inv.durationMonths || 12} months
Lock-in Period - 3 months + {inv.lockInMonths || 3} months
Early Exit Penalty - 10% + {inv.exitPenaltyPercent || 10}% +
+
+ Profit Sharing + + {inv.planName.toLowerCase().includes('battery') || inv.assetType === 'battery' ? ( + '40%' + ) : ( + '40% / 50% / 55%' + )} +
diff --git a/src/data/mockData.ts b/src/data/mockData.ts index 99af70f..cbb051e 100644 --- a/src/data/mockData.ts +++ b/src/data/mockData.ts @@ -109,6 +109,9 @@ export interface InvestmentPlan { paymentMethod: 'bank' | 'mobile' | 'cash' | 'cheque'; transactionId?: string; notes?: string; + durationMonths?: number; + lockInMonths?: number; + exitPenaltyPercent?: number; createdAt: string; }