feat(logistics): add Delhivery One logistics hub, carrier navigation, and trial order dispatch
This commit is contained in:
parent
9ce178ea5e
commit
97edf25b26
7 changed files with 596 additions and 3 deletions
452
app/(admin)/delhivery-logistics/page.tsx
Normal file
452
app/(admin)/delhivery-logistics/page.tsx
Normal file
|
|
@ -0,0 +1,452 @@
|
||||||
|
'use client';
|
||||||
|
|
||||||
|
import React, { useState, useEffect } from 'react';
|
||||||
|
import {
|
||||||
|
Navigation,
|
||||||
|
Wallet,
|
||||||
|
Package,
|
||||||
|
Clock,
|
||||||
|
RefreshCw,
|
||||||
|
MapPin,
|
||||||
|
Loader2,
|
||||||
|
Printer,
|
||||||
|
ExternalLink,
|
||||||
|
ShieldAlert,
|
||||||
|
ArrowRight,
|
||||||
|
Sparkles,
|
||||||
|
} from 'lucide-react';
|
||||||
|
import { apiFetch } from '@/services/api/client';
|
||||||
|
import { API_ENDPOINTS } from '@/services/api/config';
|
||||||
|
import { toast } from 'sonner';
|
||||||
|
import { format } from 'date-fns';
|
||||||
|
import { LogisticsHeaderNav } from '@/components/logistics/LogisticsHeaderNav';
|
||||||
|
|
||||||
|
interface DelhiveryDashboard {
|
||||||
|
status: string;
|
||||||
|
is_enabled: boolean;
|
||||||
|
mode: string;
|
||||||
|
client_cms: string;
|
||||||
|
pickup_location: string;
|
||||||
|
pickup_pin: string;
|
||||||
|
wallet: {
|
||||||
|
balance_inr: number;
|
||||||
|
currency: string;
|
||||||
|
is_trial_credit: boolean;
|
||||||
|
status: string;
|
||||||
|
};
|
||||||
|
shipment_counts: {
|
||||||
|
ready_to_ship: number;
|
||||||
|
in_transit: number;
|
||||||
|
out_for_delivery: number;
|
||||||
|
delivered: number;
|
||||||
|
rto_returned: number;
|
||||||
|
};
|
||||||
|
couriers: Array<{
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
mode: string;
|
||||||
|
min_weight_kg: number;
|
||||||
|
estimated_days: number;
|
||||||
|
rate_inr: number;
|
||||||
|
rating: number;
|
||||||
|
cod_supported: boolean;
|
||||||
|
}>;
|
||||||
|
recent_dispatches: Array<{
|
||||||
|
order_id: string;
|
||||||
|
order_no: string;
|
||||||
|
awb_code: string;
|
||||||
|
courier: string;
|
||||||
|
destination_city: string;
|
||||||
|
destination_pin: string;
|
||||||
|
status: string;
|
||||||
|
fulfillment_status: string;
|
||||||
|
package_weight: number;
|
||||||
|
dispatch_date: string;
|
||||||
|
label_url: string;
|
||||||
|
tracking_url: string;
|
||||||
|
}>;
|
||||||
|
}
|
||||||
|
|
||||||
|
function inr(amount: number) {
|
||||||
|
return `₹${amount.toLocaleString('en-IN', { minimumFractionDigits: 2, maximumFractionDigits: 2 })}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function dateLabel(value?: string) {
|
||||||
|
if (!value) return '—';
|
||||||
|
const date = new Date(value);
|
||||||
|
if (Number.isNaN(date.getTime())) return '—';
|
||||||
|
return format(date, 'dd-MMM-yyyy, hh:mm a');
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function DelhiveryLogisticsPage() {
|
||||||
|
const [data, setData] = useState<DelhiveryDashboard | null>(null);
|
||||||
|
const [loading, setLoading] = useState<boolean>(true);
|
||||||
|
|
||||||
|
// Rate calculator state
|
||||||
|
const [pickupPin, setPickupPin] = useState<string>('560001');
|
||||||
|
const [deliveryPin, setDeliveryPin] = useState<string>('');
|
||||||
|
const [weightKg, setWeightKg] = useState<number>(0.5);
|
||||||
|
const [rateLoading, setRateLoading] = useState<boolean>(false);
|
||||||
|
const [calculatedRates, setCalculatedRates] = useState<DelhiveryDashboard['couriers'] | null>(null);
|
||||||
|
|
||||||
|
const fetchData = async () => {
|
||||||
|
try {
|
||||||
|
setLoading(true);
|
||||||
|
const res = await apiFetch<DelhiveryDashboard>(API_ENDPOINTS.DELHIVERY_DASHBOARD);
|
||||||
|
if (res) {
|
||||||
|
setData(res);
|
||||||
|
setCalculatedRates(res.couriers || []);
|
||||||
|
}
|
||||||
|
} catch (err: unknown) {
|
||||||
|
console.error('Failed to load Delhivery dashboard:', err);
|
||||||
|
toast.error('Failed to load Delhivery One logistics information');
|
||||||
|
} finally {
|
||||||
|
setLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
fetchData();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleCalculateRate = async (e: React.FormEvent) => {
|
||||||
|
e.preventDefault();
|
||||||
|
if (!deliveryPin || deliveryPin.trim().length !== 6) {
|
||||||
|
toast.error('Please enter a valid 6-digit delivery pincode');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
setRateLoading(true);
|
||||||
|
const res = await apiFetch<{
|
||||||
|
couriers: DelhiveryDashboard['couriers'];
|
||||||
|
}>(`${API_ENDPOINTS.DELHIVERY_RATES}?delivery_pincode=${deliveryPin}&pickup_pincode=${pickupPin}&weight_kg=${weightKg}`);
|
||||||
|
if (res?.couriers) {
|
||||||
|
setCalculatedRates(res.couriers);
|
||||||
|
toast.success(`Rates calculated for pincode ${deliveryPin}`);
|
||||||
|
}
|
||||||
|
} catch (err: unknown) {
|
||||||
|
toast.error('Failed to calculate shipping rates');
|
||||||
|
} finally {
|
||||||
|
setRateLoading(false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const dataCardShell =
|
||||||
|
'crm-radius-section border border-border bg-card shadow-[0_1px_3px_rgba(16,24,40,0.06)] min-w-0';
|
||||||
|
const fieldClass =
|
||||||
|
'w-full h-9 px-3 crm-radius-control border border-border bg-card text-[13px] text-foreground placeholder:text-muted-foreground focus:outline-none focus:border-primary';
|
||||||
|
const labelClass = 'block text-[11px] font-semibold text-muted-foreground uppercase mb-1.5';
|
||||||
|
const primaryButton =
|
||||||
|
'inline-flex items-center justify-center gap-2 h-9 px-4 crm-radius-control bg-primary hover:bg-primary/90 text-white text-[13px] font-semibold cursor-pointer disabled:opacity-50';
|
||||||
|
const secondaryButton =
|
||||||
|
'inline-flex items-center justify-center gap-2 h-9 px-4 crm-radius-control border border-border bg-card text-foreground text-[13px] font-medium hover:bg-muted cursor-pointer disabled:opacity-50';
|
||||||
|
|
||||||
|
const couriers = calculatedRates || data?.couriers || [];
|
||||||
|
const dispatches = data?.recent_dispatches || [];
|
||||||
|
const counts = data?.shipment_counts || {
|
||||||
|
ready_to_ship: 0,
|
||||||
|
in_transit: 0,
|
||||||
|
out_for_delivery: 0,
|
||||||
|
delivered: 0,
|
||||||
|
rto_returned: 0,
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col gap-5 min-w-0">
|
||||||
|
<LogisticsHeaderNav />
|
||||||
|
|
||||||
|
{/* Page Header */}
|
||||||
|
<div className="flex flex-wrap items-center justify-between gap-3 min-w-0">
|
||||||
|
<div className="flex items-center gap-2.5 min-w-0">
|
||||||
|
<div className="w-9 h-9 rounded-lg bg-red-500/10 text-red-600 flex items-center justify-center shrink-0 font-black">
|
||||||
|
D1
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<h1 className="text-lg font-bold text-foreground">Delhivery One Logistics</h1>
|
||||||
|
<span className="inline-flex items-center px-2 py-0.5 crm-radius-badge bg-amber-500/15 text-amber-600 border border-amber-500/30 text-[11px] font-bold">
|
||||||
|
Trial Mode
|
||||||
|
</span>
|
||||||
|
<span className="inline-flex items-center px-2 py-0.5 crm-radius-badge bg-emerald-500/15 text-emerald-600 border border-emerald-500/30 text-[11px] font-semibold">
|
||||||
|
Auto-Pickup Simulated
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<p className="text-[12px] text-muted-foreground">
|
||||||
|
Automated Express Fulfillment • CMS Client:{' '}
|
||||||
|
<code className="text-foreground">{data?.client_cms?.slice(-12) || 'e97e8488-2ebd'}</code>
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button type="button" onClick={fetchData} disabled={loading} className={secondaryButton}>
|
||||||
|
<RefreshCw className={`w-3.5 h-3.5 ${loading ? 'animate-spin' : ''}`} />
|
||||||
|
Refresh
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Trial Mode Alert Banner */}
|
||||||
|
<div className="p-3.5 rounded-lg border border-amber-500/30 bg-amber-500/10 flex items-start gap-3">
|
||||||
|
<ShieldAlert className="w-5 h-5 text-amber-600 shrink-0 mt-0.5" />
|
||||||
|
<div className="text-[12.5px] text-foreground leading-relaxed">
|
||||||
|
<strong className="text-amber-700 dark:text-amber-400">Delhivery One is currently running in Trial Mode.</strong>{' '}
|
||||||
|
When orders are marked "Ready for delivery" with Delhivery One selected, real AWBs and printable thermal shipping slips are generated immediately. Live billing charges and physical carrier dispatches are suppressed until live API tokens are activated.
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Metric Cards */}
|
||||||
|
<div className="grid grid-cols-1 sm:grid-cols-2 xl:grid-cols-4 gap-4">
|
||||||
|
{/* Trial Wallet */}
|
||||||
|
<div className={`${dataCardShell} p-4`}>
|
||||||
|
<div className="flex items-start justify-between gap-2">
|
||||||
|
<div className="min-w-0">
|
||||||
|
<p className="text-[13px] text-muted-foreground font-medium">Trial Wallet Balance</p>
|
||||||
|
<p className="text-[22px] font-bold text-foreground mt-1.5 tracking-tight truncate">
|
||||||
|
{loading ? '—' : inr(data?.wallet.balance_inr ?? 5000)}
|
||||||
|
</p>
|
||||||
|
<span className="text-[11px] font-medium text-amber-600 mt-1 inline-block">
|
||||||
|
Trial Credits Active
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<span className="w-9 h-9 rounded-full bg-amber-500/10 text-amber-600 flex items-center justify-center shrink-0">
|
||||||
|
<Wallet className="w-4 h-4" />
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Ready to Ship */}
|
||||||
|
<div className={`${dataCardShell} p-4`}>
|
||||||
|
<div className="flex items-start justify-between gap-2">
|
||||||
|
<div className="min-w-0">
|
||||||
|
<p className="text-[13px] text-muted-foreground font-medium">Ready to Dispatch</p>
|
||||||
|
<p className="text-[22px] font-bold text-foreground mt-1.5 tracking-tight truncate">
|
||||||
|
{loading ? '—' : counts.ready_to_ship}
|
||||||
|
</p>
|
||||||
|
<span className="text-[11px] text-muted-foreground mt-1 inline-block">
|
||||||
|
Manifested & Label Ready
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<span className="w-9 h-9 rounded-full bg-blue-500/10 text-blue-600 flex items-center justify-center shrink-0">
|
||||||
|
<Package className="w-4 h-4" />
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* In Transit */}
|
||||||
|
<div className={`${dataCardShell} p-4`}>
|
||||||
|
<div className="flex items-start justify-between gap-2">
|
||||||
|
<div className="min-w-0">
|
||||||
|
<p className="text-[13px] text-muted-foreground font-medium">In Transit / Out for Delivery</p>
|
||||||
|
<p className="text-[22px] font-bold text-foreground mt-1.5 tracking-tight truncate">
|
||||||
|
{loading ? '—' : counts.in_transit + counts.out_for_delivery}
|
||||||
|
</p>
|
||||||
|
<span className="text-[11px] text-muted-foreground mt-1 inline-block">
|
||||||
|
On road to consignee
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<span className="w-9 h-9 rounded-full bg-purple-500/10 text-purple-600 flex items-center justify-center shrink-0">
|
||||||
|
<Navigation className="w-4 h-4" />
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Total Delivered */}
|
||||||
|
<div className={`${dataCardShell} p-4`}>
|
||||||
|
<div className="flex items-start justify-between gap-2">
|
||||||
|
<div className="min-w-0">
|
||||||
|
<p className="text-[13px] text-muted-foreground font-medium">Delivered Parcels</p>
|
||||||
|
<p className="text-[22px] font-bold text-foreground mt-1.5 tracking-tight truncate text-emerald-600">
|
||||||
|
{loading ? '—' : counts.delivered}
|
||||||
|
</p>
|
||||||
|
<span className="text-[11px] text-muted-foreground mt-1 inline-block">
|
||||||
|
Successful handovers
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<span className="w-9 h-9 rounded-full bg-emerald-500/10 text-emerald-600 flex items-center justify-center shrink-0">
|
||||||
|
<Clock className="w-4 h-4" />
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Main Grid: Rate Calculator & Available Services */}
|
||||||
|
<div className="grid grid-cols-1 lg:grid-cols-3 gap-5">
|
||||||
|
{/* Rate Calculator */}
|
||||||
|
<div className={`${dataCardShell} p-5 lg:col-span-1`}>
|
||||||
|
<div className="flex items-center gap-2 mb-4">
|
||||||
|
<MapPin className="w-4 h-4 text-primary" />
|
||||||
|
<h2 className="text-[15px] font-bold text-foreground">Delhivery Rate & TAT Calculator</h2>
|
||||||
|
</div>
|
||||||
|
<form onSubmit={handleCalculateRate} className="space-y-3.5">
|
||||||
|
<div>
|
||||||
|
<label className={labelClass}>Origin Pincode (Hub)</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
value={pickupPin}
|
||||||
|
onChange={(e) => setPickupPin(e.target.value)}
|
||||||
|
maxLength={6}
|
||||||
|
className={fieldClass}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className={labelClass}>Destination Pincode</label>
|
||||||
|
<input
|
||||||
|
type="text"
|
||||||
|
placeholder="e.g. 560034"
|
||||||
|
value={deliveryPin}
|
||||||
|
onChange={(e) => setDeliveryPin(e.target.value)}
|
||||||
|
maxLength={6}
|
||||||
|
className={fieldClass}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label className={labelClass}>Dead Weight (KG)</label>
|
||||||
|
<input
|
||||||
|
type="number"
|
||||||
|
step="0.05"
|
||||||
|
min="0.05"
|
||||||
|
max="50"
|
||||||
|
value={weightKg}
|
||||||
|
onChange={(e) => setWeightKg(parseFloat(e.target.value) || 0.5)}
|
||||||
|
className={fieldClass}
|
||||||
|
required
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<button
|
||||||
|
type="submit"
|
||||||
|
disabled={rateLoading}
|
||||||
|
className={`${primaryButton} w-full mt-2`}
|
||||||
|
>
|
||||||
|
{rateLoading ? <Loader2 className="w-4 h-4 animate-spin" /> : <Sparkles className="w-4 h-4" />}
|
||||||
|
Calculate Freight Rates
|
||||||
|
</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Courier Services Table */}
|
||||||
|
<div className={`${dataCardShell} p-5 lg:col-span-2 overflow-hidden flex flex-col`}>
|
||||||
|
<div className="flex items-center justify-between gap-2 mb-4">
|
||||||
|
<div>
|
||||||
|
<h2 className="text-[15px] font-bold text-foreground">Available Delhivery Service Lines</h2>
|
||||||
|
<p className="text-[12px] text-muted-foreground">Estimated transit time and shipping charges for {weightKg} kg</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="overflow-x-auto -mx-5 -mb-5">
|
||||||
|
<table className="w-full text-left text-[12.5px]">
|
||||||
|
<thead className="bg-muted/50 border-b border-border text-[11px] font-semibold text-muted-foreground uppercase">
|
||||||
|
<tr>
|
||||||
|
<th className="px-5 py-3">Service Tier</th>
|
||||||
|
<th className="px-3 py-3">Mode</th>
|
||||||
|
<th className="px-3 py-3">Est. Transit</th>
|
||||||
|
<th className="px-3 py-3">Rate (INR)</th>
|
||||||
|
<th className="px-3 py-3">COD</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody className="divide-y divide-border">
|
||||||
|
{couriers.map((c) => (
|
||||||
|
<tr key={c.id} className="hover:bg-muted/20">
|
||||||
|
<td className="px-5 py-3.5 font-semibold text-foreground flex items-center gap-2">
|
||||||
|
<div className="w-2 h-2 rounded-full bg-red-500 shrink-0" />
|
||||||
|
{c.name}
|
||||||
|
</td>
|
||||||
|
<td className="px-3 py-3.5 text-muted-foreground">{c.mode}</td>
|
||||||
|
<td className="px-3 py-3.5 font-medium text-foreground">
|
||||||
|
{c.estimated_days} {c.estimated_days === 1 ? 'Day' : 'Days'}
|
||||||
|
</td>
|
||||||
|
<td className="px-3 py-3.5 font-bold text-foreground">{inr(c.rate_inr)}</td>
|
||||||
|
<td className="px-3 py-3.5">
|
||||||
|
{c.cod_supported ? (
|
||||||
|
<span className="text-emerald-600 font-semibold text-[11px]">Supported</span>
|
||||||
|
) : (
|
||||||
|
<span className="text-muted-foreground text-[11px]">Prepaid only</span>
|
||||||
|
)}
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Recent Delhivery Dispatches */}
|
||||||
|
<div className={`${dataCardShell} p-5`}>
|
||||||
|
<div className="flex items-center justify-between gap-3 mb-4">
|
||||||
|
<div>
|
||||||
|
<h2 className="text-[15px] font-bold text-foreground">Recent Delhivery Shipments</h2>
|
||||||
|
<p className="text-[12px] text-muted-foreground">Orders dispatched via Delhivery One automated fulfillment</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{dispatches.length === 0 ? (
|
||||||
|
<div className="text-center py-12 text-muted-foreground text-[13px] border border-dashed border-border rounded-lg">
|
||||||
|
<Package className="w-8 h-8 mx-auto mb-2 text-muted-foreground/50" />
|
||||||
|
<p className="font-medium text-foreground">No Delhivery shipments dispatched yet</p>
|
||||||
|
<p className="text-[12px] mt-1">
|
||||||
|
When an order is updated to "Ready for delivery" with Delhivery One selected, it will appear here with live AWB tracking and thermal slips.
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
) : (
|
||||||
|
<div className="overflow-x-auto -mx-5 -mb-5">
|
||||||
|
<table className="w-full text-left text-[12.5px]">
|
||||||
|
<thead className="bg-muted/50 border-b border-border text-[11px] font-semibold text-muted-foreground uppercase">
|
||||||
|
<tr>
|
||||||
|
<th className="px-5 py-3">Order No</th>
|
||||||
|
<th className="px-3 py-3">AWB Code</th>
|
||||||
|
<th className="px-3 py-3">Courier Mode</th>
|
||||||
|
<th className="px-3 py-3">Destination</th>
|
||||||
|
<th className="px-3 py-3">Status</th>
|
||||||
|
<th className="px-3 py-3">Date</th>
|
||||||
|
<th className="px-5 py-3 text-right">Actions</th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody className="divide-y divide-border">
|
||||||
|
{dispatches.map((d) => (
|
||||||
|
<tr key={d.order_id} className="hover:bg-muted/20">
|
||||||
|
<td className="px-5 py-3.5 font-bold text-foreground">{d.order_no}</td>
|
||||||
|
<td className="px-3 py-3.5 font-mono text-[12px] text-foreground font-semibold">
|
||||||
|
{d.awb_code}
|
||||||
|
</td>
|
||||||
|
<td className="px-3 py-3.5 text-muted-foreground">{d.courier}</td>
|
||||||
|
<td className="px-3 py-3.5 text-foreground">
|
||||||
|
{d.destination_city} ({d.destination_pin})
|
||||||
|
</td>
|
||||||
|
<td className="px-3 py-3.5">
|
||||||
|
<span className="inline-flex items-center px-2 py-0.5 crm-radius-badge bg-blue-500/15 text-blue-600 font-semibold text-[11px]">
|
||||||
|
{d.status}
|
||||||
|
</span>
|
||||||
|
</td>
|
||||||
|
<td className="px-3 py-3.5 text-muted-foreground text-[11.5px]">
|
||||||
|
{dateLabel(d.dispatch_date)}
|
||||||
|
</td>
|
||||||
|
<td className="px-5 py-3.5 text-right space-x-2">
|
||||||
|
<a
|
||||||
|
href={d.label_url}
|
||||||
|
target="_blank"
|
||||||
|
rel="noreferrer"
|
||||||
|
className="inline-flex items-center gap-1 text-[12px] font-semibold text-primary hover:underline"
|
||||||
|
>
|
||||||
|
<Printer className="w-3.5 h-3.5" />
|
||||||
|
Label
|
||||||
|
</a>
|
||||||
|
<a
|
||||||
|
href={d.tracking_url}
|
||||||
|
target="_blank"
|
||||||
|
rel="noreferrer"
|
||||||
|
className="inline-flex items-center gap-1 text-[12px] font-semibold text-muted-foreground hover:text-foreground hover:underline ml-2"
|
||||||
|
>
|
||||||
|
<ExternalLink className="w-3.5 h-3.5" />
|
||||||
|
Track
|
||||||
|
</a>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
))}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
@ -136,6 +136,64 @@ export default function ShippingIntegrationsPage() {
|
||||||
</div>
|
</div>
|
||||||
<IntegrationsHeaderNav activeTab="shipping" />
|
<IntegrationsHeaderNav activeTab="shipping" />
|
||||||
|
|
||||||
|
{/* Delhivery One Configuration Card */}
|
||||||
|
<div className={`${shell} p-5 bg-gradient-to-br from-card to-amber-500/5 border-amber-500/20`}>
|
||||||
|
<div className="flex flex-wrap items-center justify-between gap-3 mb-4">
|
||||||
|
<div className="flex items-center gap-2.5">
|
||||||
|
<div className="w-8 h-8 rounded-lg bg-red-500/10 text-red-600 flex items-center justify-center font-black text-[13px]">
|
||||||
|
D1
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<div className="flex items-center gap-2">
|
||||||
|
<h3 className="font-bold text-foreground text-[15px]">Delhivery One Logistics</h3>
|
||||||
|
<span className="inline-flex px-2 py-0.5 crm-radius-badge bg-amber-500/15 text-amber-600 border border-amber-500/30 text-[10px] font-bold">
|
||||||
|
Trial Mode Active
|
||||||
|
</span>
|
||||||
|
<span className="inline-flex px-2 py-0.5 crm-radius-badge bg-emerald-500/15 text-emerald-600 border border-emerald-500/30 text-[10px] font-semibold">
|
||||||
|
Auto-Pickup Simulated
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<p className="text-[12px] text-muted-foreground">
|
||||||
|
Configured with client credentials & MCP gateway • Safe simulated fulfillment
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<a
|
||||||
|
href="/delhivery-logistics"
|
||||||
|
className="inline-flex items-center gap-1.5 h-8 px-3 crm-radius-control bg-primary text-white text-[12px] font-semibold hover:bg-primary/90"
|
||||||
|
>
|
||||||
|
Open Delhivery Hub →
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3.5 text-[12px]">
|
||||||
|
<div className="p-3 rounded-lg bg-card border border-border">
|
||||||
|
<span className="text-[10px] font-bold uppercase text-muted-foreground block mb-1">Client ID</span>
|
||||||
|
<code className="text-foreground font-mono">ucp-service-cli</code>
|
||||||
|
</div>
|
||||||
|
<div className="p-3 rounded-lg bg-card border border-border">
|
||||||
|
<span className="text-[10px] font-bold uppercase text-muted-foreground block mb-1">Client Realm</span>
|
||||||
|
<code className="text-foreground font-mono">ucp-Q72U870K1D05</code>
|
||||||
|
</div>
|
||||||
|
<div className="p-3 rounded-lg bg-card border border-border">
|
||||||
|
<span className="text-[10px] font-bold uppercase text-muted-foreground block mb-1">Client CMS ID</span>
|
||||||
|
<code className="text-foreground font-mono">cms::client::e97e8488-2ebd...</code>
|
||||||
|
</div>
|
||||||
|
<div className="p-3 rounded-lg bg-card border border-border">
|
||||||
|
<span className="text-[10px] font-bold uppercase text-muted-foreground block mb-1">Auth Endpoint</span>
|
||||||
|
<span className="text-muted-foreground truncate block">https://ucp-auth.delhivery.com/holyknight</span>
|
||||||
|
</div>
|
||||||
|
<div className="p-3 rounded-lg bg-card border border-border">
|
||||||
|
<span className="text-[10px] font-bold uppercase text-muted-foreground block mb-1">Origin Pickup PIN</span>
|
||||||
|
<span className="text-foreground font-bold">560001 (Bengaluru Central Hub)</span>
|
||||||
|
</div>
|
||||||
|
<div className="p-3 rounded-lg bg-card border border-border">
|
||||||
|
<span className="text-[10px] font-bold uppercase text-muted-foreground block mb-1">MCP Auto-Mint</span>
|
||||||
|
<span className="text-emerald-600 font-semibold">d1-mcp-mint@latest (Active)</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div className="grid grid-cols-1 lg:grid-cols-12 gap-6">
|
<div className="grid grid-cols-1 lg:grid-cols-12 gap-6">
|
||||||
{/* Credentials Form (Cols 1-6) */}
|
{/* Credentials Form (Cols 1-6) */}
|
||||||
<div className={`${shell} p-4 lg:col-span-6`}>
|
<div className={`${shell} p-4 lg:col-span-6`}>
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import { apiFetch } from '@/services/api/client';
|
||||||
import { API_ENDPOINTS } from '@/services/api/config';
|
import { API_ENDPOINTS } from '@/services/api/config';
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
import { format } from 'date-fns';
|
import { format } from 'date-fns';
|
||||||
|
import { LogisticsHeaderNav } from '@/components/logistics/LogisticsHeaderNav';
|
||||||
|
|
||||||
interface LogisticsDashboard {
|
interface LogisticsDashboard {
|
||||||
status: string;
|
status: string;
|
||||||
|
|
@ -114,6 +115,7 @@ export default function LogisticsDashboardPage() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col gap-5 min-w-0">
|
<div className="flex flex-col gap-5 min-w-0">
|
||||||
|
<LogisticsHeaderNav />
|
||||||
<div className="flex flex-wrap items-center justify-between gap-3 min-w-0">
|
<div className="flex flex-wrap items-center justify-between gap-3 min-w-0">
|
||||||
<div className="flex items-center gap-2 min-w-0">
|
<div className="flex items-center gap-2 min-w-0">
|
||||||
<h1 className="text-lg font-semibold text-foreground">Shiprocket</h1>
|
<h1 className="text-lg font-semibold text-foreground">Shiprocket</h1>
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ import {
|
||||||
import { toast } from 'sonner';
|
import { toast } from 'sonner';
|
||||||
import { format } from 'date-fns';
|
import { format } from 'date-fns';
|
||||||
import { apiFetch } from '@/services/api/client';
|
import { apiFetch } from '@/services/api/client';
|
||||||
|
import { API_BASE_URL } from '@/services/api/config';
|
||||||
import { SlideOver } from '@/components/ui/SlideOver';
|
import { SlideOver } from '@/components/ui/SlideOver';
|
||||||
import { CustomSelect } from '@/components/ui/CustomSelect';
|
import { CustomSelect } from '@/components/ui/CustomSelect';
|
||||||
import { TablePagination, useClientPagination } from '@/components/ui/TablePagination';
|
import { TablePagination, useClientPagination } from '@/components/ui/TablePagination';
|
||||||
|
|
@ -181,7 +182,7 @@ export default function OrderIntelligencePage() {
|
||||||
const [verifiedItems, setVerifiedItems] = useState<string[]>([]);
|
const [verifiedItems, setVerifiedItems] = useState<string[]>([]);
|
||||||
const [showStatusForm, setShowStatusForm] = useState(false);
|
const [showStatusForm, setShowStatusForm] = useState(false);
|
||||||
const [newStatus, setNewStatus] = useState('PROCESSING');
|
const [newStatus, setNewStatus] = useState('PROCESSING');
|
||||||
const [logisticsProvider, setLogisticsProvider] = useState<'SHIPROCKET' | 'LOCAL_DELIVERY'>('SHIPROCKET');
|
const [logisticsProvider, setLogisticsProvider] = useState<'DELHIVERY' | 'SHIPROCKET' | 'LOCAL_DELIVERY'>('DELHIVERY');
|
||||||
const [packageWeight, setPackageWeight] = useState<string>('0.5');
|
const [packageWeight, setPackageWeight] = useState<string>('0.5');
|
||||||
const [trackingNo, setTrackingNo] = useState('');
|
const [trackingNo, setTrackingNo] = useState('');
|
||||||
const [courier, setCourier] = useState('');
|
const [courier, setCourier] = useState('');
|
||||||
|
|
@ -1102,7 +1103,7 @@ export default function OrderIntelligencePage() {
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
{detailData.shipping_label_url && (
|
{detailData.shipping_label_url && (
|
||||||
<a
|
<a
|
||||||
href={detailData.shipping_label_url.startsWith('http') ? detailData.shipping_label_url : `http://localhost:8000${detailData.shipping_label_url}`}
|
href={detailData.shipping_label_url.startsWith('http') ? detailData.shipping_label_url : `${API_BASE_URL}${detailData.shipping_label_url}`}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
className="inline-flex items-center gap-1.5 px-3 py-1.5 bg-primary text-white crm-radius-button text-[12px] font-semibold hover:opacity-90 shadow-sm"
|
className="inline-flex items-center gap-1.5 px-3 py-1.5 bg-primary text-white crm-radius-button text-[12px] font-semibold hover:opacity-90 shadow-sm"
|
||||||
|
|
@ -1133,7 +1134,7 @@ export default function OrderIntelligencePage() {
|
||||||
</div>
|
</div>
|
||||||
{detailData.shipping_label_url && (
|
{detailData.shipping_label_url && (
|
||||||
<a
|
<a
|
||||||
href={detailData.shipping_label_url.startsWith('http') ? detailData.shipping_label_url : `http://localhost:8000${detailData.shipping_label_url}`}
|
href={detailData.shipping_label_url.startsWith('http') ? detailData.shipping_label_url : `${API_BASE_URL}${detailData.shipping_label_url}`}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
rel="noopener noreferrer"
|
rel="noopener noreferrer"
|
||||||
className="inline-flex items-center gap-1.5 px-2.5 py-1 bg-primary/10 hover:bg-primary/20 text-primary text-[11px] font-semibold crm-radius-button"
|
className="inline-flex items-center gap-1.5 px-2.5 py-1 bg-primary/10 hover:bg-primary/20 text-primary text-[11px] font-semibold crm-radius-button"
|
||||||
|
|
@ -1229,6 +1230,7 @@ export default function OrderIntelligencePage() {
|
||||||
value={logisticsProvider}
|
value={logisticsProvider}
|
||||||
onChange={(val) => setLogisticsProvider(val as any)}
|
onChange={(val) => setLogisticsProvider(val as any)}
|
||||||
options={[
|
options={[
|
||||||
|
{ value: 'DELHIVERY', label: 'Delhivery One (Automated Pickup & Tracking - Trial Mode)' },
|
||||||
{ value: 'SHIPROCKET', label: 'Shiprocket (Automated Pickup & Tracking)' },
|
{ value: 'SHIPROCKET', label: 'Shiprocket (Automated Pickup & Tracking)' },
|
||||||
{ value: 'LOCAL_DELIVERY', label: 'Local / Store Delivery (Manual Handover)' },
|
{ value: 'LOCAL_DELIVERY', label: 'Local / Store Delivery (Manual Handover)' },
|
||||||
]}
|
]}
|
||||||
|
|
@ -1251,6 +1253,11 @@ export default function OrderIntelligencePage() {
|
||||||
Actual physical scale weight for courier billing and manifest verification.
|
Actual physical scale weight for courier billing and manifest verification.
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
{logisticsProvider === 'DELHIVERY' && (
|
||||||
|
<div className="text-[11px] text-amber-700 dark:text-amber-300 bg-amber-500/10 p-2.5 rounded border border-amber-500/25">
|
||||||
|
⚡ <strong>Delhivery One Automated Pickup (Trial Mode):</strong> Confirming will immediately assign a Delhivery AWB, generate the printable 4"x6" thermal shipping slip, and register package dispatch.
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
{logisticsProvider === 'SHIPROCKET' && (
|
{logisticsProvider === 'SHIPROCKET' && (
|
||||||
<div className="text-[11px] text-primary bg-primary/10 p-2.5 rounded border border-primary/20">
|
<div className="text-[11px] text-primary bg-primary/10 p-2.5 rounded border border-primary/20">
|
||||||
⚡ <strong>Automated Pickup Trigger:</strong> Confirming will immediately create the order in Shiprocket, assign the AWB number, generate the printable shipping label slip, and schedule carrier pickup at the shop location.
|
⚡ <strong>Automated Pickup Trigger:</strong> Confirming will immediately create the order in Shiprocket, assign the AWB number, generate the printable shipping label slip, and schedule carrier pickup at the shop location.
|
||||||
|
|
|
||||||
|
|
@ -106,6 +106,7 @@ const NAV_GROUPS: NavGroup[] = [
|
||||||
children: [
|
children: [
|
||||||
{ name: 'Customer Store Orders', href: '/orders' },
|
{ name: 'Customer Store Orders', href: '/orders' },
|
||||||
{ name: 'Razorpay Dashboard', href: '/razorpay-dashboard' },
|
{ name: 'Razorpay Dashboard', href: '/razorpay-dashboard' },
|
||||||
|
{ name: 'Delhivery Logistics', href: '/delhivery-logistics' },
|
||||||
{ name: 'Shiprocket Logistics', href: '/logistics' },
|
{ name: 'Shiprocket Logistics', href: '/logistics' },
|
||||||
{ name: 'Warranties', href: '/warranties' },
|
{ name: 'Warranties', href: '/warranties' },
|
||||||
{ name: 'Refunds & Returns', href: '/refunds' },
|
{ name: 'Refunds & Returns', href: '/refunds' },
|
||||||
|
|
|
||||||
67
components/logistics/LogisticsHeaderNav.tsx
Normal file
67
components/logistics/LogisticsHeaderNav.tsx
Normal file
|
|
@ -0,0 +1,67 @@
|
||||||
|
'use client';
|
||||||
|
|
||||||
|
import React from 'react';
|
||||||
|
import Link from 'next/link';
|
||||||
|
import { usePathname } from 'next/navigation';
|
||||||
|
import { Truck, Navigation, Settings } from 'lucide-react';
|
||||||
|
|
||||||
|
export const LogisticsHeaderNav: React.FC = () => {
|
||||||
|
const pathname = usePathname();
|
||||||
|
|
||||||
|
const tabs = [
|
||||||
|
{
|
||||||
|
id: 'delhivery',
|
||||||
|
name: 'Delhivery One (Trial)',
|
||||||
|
href: '/delhivery-logistics',
|
||||||
|
icon: Navigation,
|
||||||
|
badge: 'Trial Active',
|
||||||
|
match: pathname === '/delhivery-logistics',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'shiprocket',
|
||||||
|
name: 'Shiprocket',
|
||||||
|
href: '/logistics',
|
||||||
|
icon: Truck,
|
||||||
|
match: pathname === '/logistics',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 'settings',
|
||||||
|
name: 'Logistics Credentials',
|
||||||
|
href: '/integrations/shipping',
|
||||||
|
icon: Settings,
|
||||||
|
match: pathname.startsWith('/integrations/shipping'),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex items-center gap-2 overflow-x-auto pb-1 mb-2">
|
||||||
|
{tabs.map((tab) => {
|
||||||
|
const Icon = tab.icon;
|
||||||
|
const isActive = tab.match;
|
||||||
|
return (
|
||||||
|
<Link
|
||||||
|
key={tab.id}
|
||||||
|
href={tab.href}
|
||||||
|
className={`inline-flex items-center gap-2 h-9 px-3.5 crm-radius-control text-[13px] font-semibold whitespace-nowrap transition-colors ${
|
||||||
|
isActive
|
||||||
|
? 'bg-primary text-white shadow-sm'
|
||||||
|
: 'border border-border bg-card text-foreground hover:bg-muted'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
<Icon className="w-4 h-4" />
|
||||||
|
<span>{tab.name}</span>
|
||||||
|
{tab.badge && (
|
||||||
|
<span
|
||||||
|
className={`text-[10px] font-bold px-1.5 py-0.5 rounded ${
|
||||||
|
isActive ? 'bg-white/20 text-white' : 'bg-amber-500/15 text-amber-600'
|
||||||
|
}`}
|
||||||
|
>
|
||||||
|
{tab.badge}
|
||||||
|
</span>
|
||||||
|
)}
|
||||||
|
</Link>
|
||||||
|
);
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
@ -132,6 +132,12 @@ export const API_ENDPOINTS = {
|
||||||
// Shiprocket Logistics
|
// Shiprocket Logistics
|
||||||
SHIPPING_DASHBOARD: '/api/v1/shipping/dashboard',
|
SHIPPING_DASHBOARD: '/api/v1/shipping/dashboard',
|
||||||
|
|
||||||
|
// Delhivery One Logistics
|
||||||
|
DELHIVERY_STATUS: '/api/v1/delhivery/status',
|
||||||
|
DELHIVERY_DASHBOARD: '/api/v1/delhivery/dashboard',
|
||||||
|
DELHIVERY_RATES: '/api/v1/delhivery/rates',
|
||||||
|
DELHIVERY_LABEL_PREVIEW: (orderId: string) => `/api/v1/delhivery/label/preview/${orderId}`,
|
||||||
|
|
||||||
// Reporting Hub
|
// Reporting Hub
|
||||||
REPORTS_EXPORT: '/api/v1/reports/export',
|
REPORTS_EXPORT: '/api/v1/reports/export',
|
||||||
} as const;
|
} as const;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue