2025-05-13 18:50:30 +02:00
|
|
|
export interface VesselData {
|
|
|
|
|
imo: string;
|
|
|
|
|
vesselName: string;
|
|
|
|
|
type: string;
|
|
|
|
|
length: number;
|
|
|
|
|
width: number;
|
|
|
|
|
estimatedEnginePower: number;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface CarbonCalculation {
|
|
|
|
|
yearlyEmissions: number;
|
|
|
|
|
offsetCost: number;
|
|
|
|
|
recommendedProjects: Array<{
|
|
|
|
|
id: string;
|
|
|
|
|
name: string;
|
|
|
|
|
description: string;
|
|
|
|
|
costPerTon: number;
|
|
|
|
|
}>;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface CarbonEstimate {
|
|
|
|
|
fuelConsumption: number; // liters per year
|
|
|
|
|
co2Emissions: number; // tons per year
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface TripEstimate {
|
|
|
|
|
distance: number; // nautical miles
|
|
|
|
|
duration: number; // hours
|
|
|
|
|
fuelConsumption: number; // liters
|
|
|
|
|
co2Emissions: number; // tons
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface Currency {
|
|
|
|
|
code: string;
|
|
|
|
|
symbol: string;
|
|
|
|
|
rate: number; // Exchange rate relative to USD
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type CurrencyCode = 'USD' | 'EUR' | 'GBP' | 'CHF';
|
|
|
|
|
|
|
|
|
|
export interface Portfolio {
|
|
|
|
|
id: number;
|
|
|
|
|
name: string;
|
|
|
|
|
description: string;
|
|
|
|
|
projects: OffsetProject[];
|
|
|
|
|
pricePerTon: number;
|
|
|
|
|
currency: CurrencyCode;
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-29 21:45:14 +01:00
|
|
|
export type CertificationStatus =
|
|
|
|
|
| 'standard 2020'
|
|
|
|
|
| 'standard 2023'
|
|
|
|
|
| 'nonstandard'
|
|
|
|
|
| 'in progress';
|
|
|
|
|
|
2025-05-13 18:50:30 +02:00
|
|
|
export interface OffsetProject {
|
|
|
|
|
id: string;
|
|
|
|
|
name: string;
|
|
|
|
|
description: string;
|
|
|
|
|
shortDescription: string;
|
|
|
|
|
imageUrl: string;
|
|
|
|
|
pricePerTon: number;
|
2025-10-29 21:45:14 +01:00
|
|
|
percentage?: number; // Project's contribution to portfolio
|
|
|
|
|
certificationStatus?: CertificationStatus; // Wren certification standard
|
2025-05-13 18:50:30 +02:00
|
|
|
location: string;
|
|
|
|
|
type: string;
|
|
|
|
|
verificationStandard: string;
|
|
|
|
|
impactMetrics: {
|
|
|
|
|
co2Reduced: number;
|
|
|
|
|
treesPlanted?: number;
|
|
|
|
|
livelihoodsImproved?: number;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2025-10-29 21:45:14 +01:00
|
|
|
export type OffsetOrderSource =
|
|
|
|
|
| 'subscription'
|
|
|
|
|
| 'flight'
|
|
|
|
|
| 'gift'
|
|
|
|
|
| 'custom-duration'
|
|
|
|
|
| 'one-off'
|
|
|
|
|
| 'referral-bonus'
|
|
|
|
|
| 'annual-incentive'
|
|
|
|
|
| 'public-api'
|
|
|
|
|
| 'special-offer';
|
|
|
|
|
|
2025-05-13 18:50:30 +02:00
|
|
|
export interface OffsetOrder {
|
|
|
|
|
id: string;
|
2025-10-29 21:45:14 +01:00
|
|
|
amountCharged: number; // Amount in cents (amount_paid_by_customer from API)
|
2025-05-13 18:50:30 +02:00
|
|
|
currency: CurrencyCode;
|
|
|
|
|
tons: number;
|
|
|
|
|
portfolio: Portfolio;
|
|
|
|
|
status: 'pending' | 'completed' | 'failed';
|
|
|
|
|
createdAt: string;
|
|
|
|
|
dryRun: boolean;
|
2025-10-29 21:45:14 +01:00
|
|
|
source?: OffsetOrderSource; // Source of the payment
|
|
|
|
|
note?: string; // Optional note attached to the order
|
2025-05-13 18:50:30 +02:00
|
|
|
}
|
|
|
|
|
|
2025-11-02 19:13:15 +01:00
|
|
|
export type CalculatorType = 'trip' | 'annual' | 'mobile';
|
2025-10-29 21:45:14 +01:00
|
|
|
|
|
|
|
|
// Stripe Checkout Types
|
|
|
|
|
export interface CheckoutSession {
|
|
|
|
|
sessionId: string;
|
|
|
|
|
url: string;
|
|
|
|
|
orderId: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface StoredOrder {
|
|
|
|
|
id: string;
|
|
|
|
|
stripeSessionId: string;
|
|
|
|
|
stripePaymentIntent: string | null;
|
|
|
|
|
wrenOrderId: string | null;
|
|
|
|
|
customerEmail: string | null;
|
|
|
|
|
tons: number;
|
|
|
|
|
portfolioId: number;
|
|
|
|
|
baseAmount: number; // in cents
|
|
|
|
|
processingFee: number; // in cents
|
|
|
|
|
totalAmount: number; // in cents
|
|
|
|
|
currency: CurrencyCode;
|
|
|
|
|
status: 'pending' | 'paid' | 'fulfilled' | 'failed';
|
|
|
|
|
createdAt: string;
|
|
|
|
|
updatedAt: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export interface OrderDetailsResponse {
|
|
|
|
|
order: {
|
|
|
|
|
id: string;
|
|
|
|
|
tons: number;
|
|
|
|
|
portfolioId: number;
|
|
|
|
|
baseAmount: number;
|
|
|
|
|
processingFee: number;
|
|
|
|
|
totalAmount: number;
|
|
|
|
|
currency: string;
|
|
|
|
|
status: string;
|
|
|
|
|
wrenOrderId: string | null;
|
2025-10-31 17:24:51 +01:00
|
|
|
stripeSessionId: string;
|
2025-10-29 21:45:14 +01:00
|
|
|
createdAt: string;
|
2025-10-31 17:24:51 +01:00
|
|
|
portfolio?: Portfolio; // Portfolio data with projects for pie chart
|
2025-10-29 21:45:14 +01:00
|
|
|
};
|
|
|
|
|
session: {
|
|
|
|
|
paymentStatus: string;
|
|
|
|
|
customerEmail?: string;
|
|
|
|
|
};
|
|
|
|
|
}
|
Integrate NocoDB backend for admin portal with real data
Phase 2 Backend Integration Complete:
Backend Infrastructure:
- Created NocoDB client abstraction layer (src/api/nocodbClient.ts)
- Clean TypeScript API hiding NocoDB query syntax complexity
- Helper methods for orders, stats, search, timeline, and filtering
- Automatic date range handling and pagination support
API Routes:
- POST /api/admin/stats - Dashboard statistics with time range filtering
- GET /api/admin/orders - List orders with search, filter, sort, pagination
- GET /api/admin/orders/[id] - Single order details
- PATCH /api/admin/orders/[id] - Update order fields
- DELETE /api/admin/orders/[id] - Cancel order (soft delete)
- GET /api/admin/orders/export - CSV/Excel export with filters
Dashboard Updates:
- Real-time data fetching from NocoDB
- Time range selector (7d, 30d, 90d, all time)
- Recharts line chart for orders timeline
- Recharts pie chart for status distribution
- Loading states and error handling
- Dynamic stat cards with real numbers
Dependencies Added:
- papaparse - CSV export
- xlsx - Excel export with styling
- @types/papaparse - TypeScript support
Data Types:
- OrderRecord interface for NocoDB data structure
- DashboardStats, TimelineData, OrderFilters interfaces
- Full type safety across API and UI
Environment Configuration:
- NOCODB_BASE_URL, NOCODB_BASE_ID configured
- NOCODB_API_KEY, NOCODB_ORDERS_TABLE_ID configured
- All credentials stored securely in .env.local
Ready for testing with sample data in NocoDB!
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-03 10:40:25 +01:00
|
|
|
|
|
|
|
|
// NocoDB Order Record (Admin Portal)
|
|
|
|
|
export interface OrderRecord {
|
|
|
|
|
// NocoDB metadata
|
|
|
|
|
Id: number;
|
|
|
|
|
CreatedAt: string;
|
|
|
|
|
UpdatedAt: string;
|
|
|
|
|
|
|
|
|
|
// Order identification
|
|
|
|
|
orderId: string;
|
|
|
|
|
status: 'pending' | 'paid' | 'fulfilled' | 'cancelled';
|
|
|
|
|
source?: string; // 'web', 'mobile-app', 'manual'
|
|
|
|
|
|
|
|
|
|
// Vessel information
|
|
|
|
|
vesselName: string;
|
|
|
|
|
imoNumber?: string;
|
|
|
|
|
vesselType?: string;
|
|
|
|
|
vesselLength?: string;
|
|
|
|
|
|
|
|
|
|
// Trip details
|
|
|
|
|
departurePort?: string;
|
|
|
|
|
arrivalPort?: string;
|
|
|
|
|
distance: string;
|
|
|
|
|
avgSpeed: string;
|
|
|
|
|
duration?: string;
|
|
|
|
|
enginePower?: string;
|
|
|
|
|
|
|
|
|
|
// Carbon offset details
|
|
|
|
|
co2Tons: string;
|
|
|
|
|
portfolioId?: string;
|
|
|
|
|
portfolioName?: string;
|
|
|
|
|
totalAmount: string;
|
|
|
|
|
currency: string;
|
|
|
|
|
amountUSD: string;
|
|
|
|
|
|
|
|
|
|
// Customer information
|
|
|
|
|
customerName: string;
|
|
|
|
|
customerEmail: string;
|
|
|
|
|
customerCompany?: string;
|
|
|
|
|
customerPhone?: string;
|
|
|
|
|
|
|
|
|
|
// Payment & fulfillment
|
|
|
|
|
paymentMethod?: string;
|
|
|
|
|
paymentReference?: string;
|
|
|
|
|
wrenOrderId?: string;
|
|
|
|
|
certificateUrl?: string;
|
|
|
|
|
fulfilledAt?: string;
|
|
|
|
|
|
|
|
|
|
// Admin notes
|
|
|
|
|
notes?: string;
|
|
|
|
|
}
|