feat: add api service module for backend communication and authentication
Some checks failed
Beta CI/CD Pipeline / build-and-test (push) Failing after 44s
Beta CI/CD Pipeline / deploy-beta (push) Has been skipped

This commit is contained in:
vickytechkey 2026-10-12 18:25:39 +05:30
parent ce4f824468
commit 7f02b4cd4f
4 changed files with 389 additions and 42 deletions

View file

@ -9,7 +9,11 @@ import {
CheckCircle2,
Calendar,
Truck,
Edit
Edit,
Info,
ShieldCheck,
Check,
Lock
} from 'lucide-react';
import { OrderItem } from '../../types/seller';
import { useSeller } from '../../context/SellerContext';
@ -21,14 +25,36 @@ interface ReschedulePickupViewProps {
}
export const ReschedulePickupView: React.FC<ReschedulePickupViewProps> = ({ onBack, onTabChange, order }) => {
const { orders, onboarding, user } = useSeller();
const { orders, onboarding, user, reschedulePickup } = useSeller();
const readyOrders = orders.filter(o => o.status === 'ready_to_ship');
const locationName = onboarding.tradeName || onboarding.city || user?.storeName || user?.name || 'Artisan Workshop Hub';
const [reason, setReason] = useState('curing');
const [otherReasonText, setOtherReasonText] = useState('');
const [slot, setSlot] = useState('morning');
const [dateType, setDateType] = useState('tomorrow');
// Target single order or first ready_to_ship order
const targetOrder = order || readyOrders[0] || null;
// Resolve Carrier Identity
const courier = String(targetOrder?.courierPartner || '').toUpperCase();
const awb = String(targetOrder?.awbNumber || '').toUpperCase();
const isDelhivery = courier.includes('DELHI') || awb.startsWith('DELHI') || awb.startsWith('698') || /^\d{10,14}$/.test(awb);
const isEkart = !isDelhivery && (courier.includes('EKART') || awb.startsWith('EKART') || awb.startsWith('ELIT') || awb.startsWith('500'));
const isShadowfax = !isDelhivery && !isEkart;
const carrierDisplayName = isDelhivery ? 'Delhivery Logistics' : (isEkart ? 'Ekart Logistics' : 'Shadowfax Logistics');
// Compute tomorrow's date format YYYY-MM-DD
const tomorrow = new Date(Date.now() + 86400000);
const tomorrowStr = tomorrow.toISOString().split('T')[0];
const todayStr = new Date().toISOString().split('T')[0];
const [pickupDate, setPickupDate] = useState<string>(tomorrowStr);
const [slot, setSlot] = useState<string>('afternoon');
const [reason, setReason] = useState<string>('curing');
const [otherReasonText, setOtherReasonText] = useState<string>('');
const [driverNotes, setDriverNotes] = useState<string>('');
const [isSubmitting, setIsSubmitting] = useState<boolean>(false);
const [submitSuccess, setSubmitSuccess] = useState<string | null>(null);
const [submitError, setSubmitError] = useState<string | null>(null);
const reasons = [
{ id: 'curing', label: 'Handcrafts Still Drying / Finishing', desc: 'Extra time needed for kiln curing or natural dye drying.' },
@ -39,12 +65,52 @@ export const ReschedulePickupView: React.FC<ReschedulePickupViewProps> = ({ onBa
{ id: 'other', label: 'Other Reason', desc: 'Briefly let the logistics team know what changed.' }
];
const slots = [
{ id: 'morning', label: 'Morning (10:00 AM – 1:00 PM)', desc: 'Delhivery Express & Air Linehaul', tag: 'Fastest Delivery' },
{ id: 'afternoon', label: 'Afternoon (2:00 PM – 5:00 PM)', desc: 'Standard ground carrier sweep', tag: 'Standard', tagBg: 'transparent' },
{ id: 'evening', label: 'Evening (5:00 PM – 7:00 PM)', desc: 'Regional depot consolidation run', tag: 'Evening Run', tagBg: 'transparent' }
const delhiverySlots = [
{ id: 'morning', label: 'Morning Slot', time: '10:00 AM – 1:00 PM', value: '10:00:00', desc: 'Early pickup for priority flight & express linehaul', tag: 'Express Cutoff', tagColor: '#0284c7' },
{ id: 'afternoon', label: 'Afternoon Slot', time: '2:00 PM – 5:00 PM', value: '14:00:00', desc: 'Standard warehouse dispatch & ground linehaul', tag: 'Recommended', tagColor: '#16a34a' },
{ id: 'evening', label: 'Evening Slot', time: '5:00 PM – 7:00 PM', value: '17:00:00', desc: 'Regional consolidation run before depot departure', tag: 'Late Run', tagColor: '#9333ea' }
];
const handleConfirmSchedule = async () => {
setIsSubmitting(true);
setSubmitError(null);
setSubmitSuccess(null);
const targetOrderId = targetOrder?.id || (readyOrders[0]?.id);
if (!targetOrderId) {
setSubmitError('No ready to ship order selected for scheduling.');
setIsSubmitting(false);
return;
}
const effectiveTime = isDelhivery
? (slot === 'morning' ? '10:00:00' : slot === 'evening' ? '17:00:00' : '14:00:00')
: (isEkart ? 'Standard Hub Sweep' : 'Automated Cutoff Sweep');
const effectiveReason = reason === 'other' ? (otherReasonText || 'Other merchant reason') : (reasons.find(r => r.id === reason)?.label || reason);
const payload = {
pickup_date: pickupDate,
pickup_time: effectiveTime,
reason: effectiveReason,
notes: driverNotes || effectiveReason,
package_count: targetOrder ? 1 : readyOrders.length
};
try {
const res = await reschedulePickup(targetOrderId, payload);
const msg = res?.message || `Courier pickup confirmed for ${pickupDate}!`;
setSubmitSuccess(msg);
setTimeout(() => {
onBack();
}, 1500);
} catch (e: any) {
setSubmitError(e.message || 'Failed to schedule pickup with courier.');
} finally {
setIsSubmitting(false);
}
};
return (
<div className="reschedule-view" style={{ maxWidth: '1400px', margin: '0 auto', animation: 'fadeIn 0.2s ease-in-out' }}>
@ -61,13 +127,31 @@ export const ReschedulePickupView: React.FC<ReschedulePickupViewProps> = ({ onBa
<div className="is-flex flex-direction-column md-flex-row md-items-center justify-content-between gap-4 pt-1 mb-4">
<div>
<h1 className="title is-size-2 mb-1" style={{ letterSpacing: '-0.02em', color: '#1c1b1b' }}>Reschedule Courier Pickup</h1>
<p className="is-size-6" style={{ color: '#564243', maxWidth: '42rem' }}>Choose a new pickup date and time that fits your workshop schedule.</p>
<div className="is-flex is-align-items-center gap-3 mb-1">
<h1 className="title is-size-2 mb-0" style={{ letterSpacing: '-0.02em', color: '#1c1b1b' }}>Schedule Courier Pickup</h1>
{/* Carrier Badge */}
<span className="is-inline-flex is-align-items-center gap-2 px-3 py-1 has-text-weight-bold is-size-7" style={{
borderRadius: '9999px',
backgroundColor: isDelhivery ? '#e0f2fe' : (isEkart ? '#fef3c7' : '#f3e8ff'),
color: isDelhivery ? '#0369a1' : (isEkart ? '#92400e' : '#6b21a8')
}}>
<Truck size={14} /> {carrierDisplayName}
</span>
</div>
<p className="is-size-6" style={{ color: '#564243', maxWidth: '42rem' }}>
{isDelhivery && 'Delhivery supports custom pickup date and hour slots. Choose your preferred arrival window.'}
{isEkart && 'Ekart Logistics allows choosing a preferred dispatch date. Sweeps occur during standard daily runs.'}
{isShadowfax && 'Shadowfax operates automated warehouse sweeps based on registered dispatch cutoff times.'}
</p>
</div>
<div className="is-inline-flex is-align-items-center gap-3 px-4 py-2 shadow-sm" style={{ backgroundColor: '#ffffff', borderRadius: '9999px', border: '1px solid #eae7e7', color: '#1c1b1b', fontSize: '13px' }}>
<Package size={18} style={{ color: '#9d4225' }} />
<span>
Batch of <strong className="has-text-weight-semibold">{readyOrders.length} Order{readyOrders.length === 1 ? '' : 's'}</strong> ready
{targetOrder ? (
<>Order <strong className="has-text-weight-semibold">{targetOrder.orderNumber}</strong> ({targetOrder.awbNumber || 'Ready'})</>
) : (
<>Batch of <strong className="has-text-weight-semibold">{readyOrders.length} Order{readyOrders.length === 1 ? '' : 's'}</strong></>
)}
</span>
</div>
</div>
@ -83,7 +167,7 @@ export const ReschedulePickupView: React.FC<ReschedulePickupViewProps> = ({ onBa
<RefreshCw size={16} className="mr-2" /> Handover
</button>
<button className="button is-rounded is-small px-4 transition-all is-flex is-align-items-center shadow-sm" style={{ backgroundColor: '#791b2c', color: '#ffffff', fontWeight: 600, border: 'none' }}>
<Clock size={16} className="mr-2" /> Reschedule
<Clock size={16} className="mr-2" /> Schedule Pickup
</button>
<button onClick={() => onTabChange?.('report_damage')} className="button is-rounded is-small px-4 transition-all is-flex is-align-items-center" style={{ backgroundColor: 'transparent', color: '#564243', fontWeight: 500, border: 'none' }}>
<AlertTriangle size={16} className="mr-2" /> Report transit damage
@ -98,13 +182,48 @@ export const ReschedulePickupView: React.FC<ReschedulePickupViewProps> = ({ onBa
<div className="column is-8 is-flex is-flex-direction-column gap-6">
{/* Feedback notifications */}
{submitSuccess && (
<div className="notification is-success is-light p-4" style={{ borderRadius: '12px' }}>
<div className="is-flex is-align-items-center gap-2">
<CheckCircle2 size={18} />
<span><strong>Success!</strong> {submitSuccess}</span>
</div>
</div>
)}
{submitError && (
<div className="notification is-danger is-light p-4" style={{ borderRadius: '12px' }}>
<div className="is-flex is-align-items-center gap-2">
<AlertTriangle size={18} />
<span><strong>Error:</strong> {submitError}</span>
</div>
</div>
)}
{/* Carrier Feature Capability Notice Banner */}
<div className="p-4 is-flex is-align-items-flex-start gap-3 shadow-sm" style={{
borderRadius: '12px',
backgroundColor: isDelhivery ? '#f0fdf4' : (isEkart ? '#fffbeb' : '#f5f3ff'),
border: `1px solid ${isDelhivery ? '#bbf7d0' : (isEkart ? '#fde68a' : '#ddd6fe')}`
}}>
<Info size={20} style={{ color: isDelhivery ? '#15803d' : (isEkart ? '#b45309' : '#6d28d9'), marginTop: '2px', flexShrink: 0 }} />
<div className="is-size-7" style={{ color: '#1c1b1b' }}>
<span className="has-text-weight-bold" style={{ color: isDelhivery ? '#15803d' : (isEkart ? '#b45309' : '#6d28d9') }}>
Assigned Carrier: {carrierDisplayName}
</span>
<p className="mt-1" style={{ color: '#4b5563' }}>
{isDelhivery && '✅ Both preferred date and specific pickup time slots are enabled. Delhivery will dispatch a sweep agent specifically for your selected arrival slot.'}
{isEkart && 'ℹ️ Preferred Dispatch Date is enabled. Note that Ekart Logistics operates standard morning & evening hub sweep rounds; exact hour booking is handled via daily courier sweeps.'}
{isShadowfax && 'ℹ️ Automated Dispatch Mode. Shadowfax assigns pickup riders automatically based on daily cut-off SLA times. Your dispatch request will be synced with the carrier.'}
</p>
</div>
</div>
{/* Step 1 */}
{/* Step 1: Reason Selection */}
<div className="card p-6 is-flex is-flex-direction-column gap-4 shadow-sm" style={{ borderRadius: '16px', backgroundColor: '#ffffff', border: '1px solid rgba(234, 231, 231, 0.6)' }}>
<div className="is-flex is-flex-direction-column gap-1">
<span className="is-size-7 has-text-weight-bold is-uppercase" style={{ letterSpacing: '0.04em', color: '#5a0118' }}>Step 1</span>
<h2 className="is-size-5 has-text-weight-semibold" style={{ color: '#1c1b1b' }}>1. Why do you need to reschedule?</h2>
<h2 className="is-size-5 has-text-weight-semibold" style={{ color: '#1c1b1b' }}>1. Reason for Scheduling / Adjusting Pickup</h2>
</div>
<div className="columns is-multiline is-variable is-3 mt-1">
@ -130,7 +249,7 @@ export const ReschedulePickupView: React.FC<ReschedulePickupViewProps> = ({ onBa
{r.id === 'other' && isSelected && (
<input
type="text"
placeholder="Please specify..."
placeholder="Please specify reason..."
value={otherReasonText}
onChange={(e) => setOtherReasonText(e.target.value)}
onClick={(e) => e.stopPropagation()}
@ -154,19 +273,160 @@ export const ReschedulePickupView: React.FC<ReschedulePickupViewProps> = ({ onBa
</div>
</div>
{/* Step 2 */}
<div className="card p-6 is-flex is-flex-direction-column gap-3 shadow-sm" style={{ borderRadius: '16px', backgroundColor: '#ffffff', border: '1px solid rgba(234, 231, 231, 0.6)' }}>
{/* Step 2: Date & Slot Selection (Dynamic as per Carrier) */}
<div className="card p-6 is-flex is-flex-direction-column gap-5 shadow-sm" style={{ borderRadius: '16px', backgroundColor: '#ffffff', border: '1px solid rgba(234, 231, 231, 0.6)' }}>
<div className="is-flex is-flex-direction-column gap-1">
<span className="is-size-7 has-text-weight-bold is-uppercase" style={{ letterSpacing: '0.04em', color: '#5a0118' }}>Step 2</span>
<h2 className="is-size-5 has-text-weight-semibold" style={{ color: '#1c1b1b' }}>2. Instructions for Driver (Optional)</h2>
<div className="is-flex is-align-items-center justify-content-between">
<h2 className="is-size-5 has-text-weight-semibold" style={{ color: '#1c1b1b' }}>2. Select Preferred Date & Pickup Window</h2>
<span className="tag is-rounded is-small has-text-weight-medium" style={{
backgroundColor: isDelhivery ? '#e0f2fe' : (isEkart ? '#fef3c7' : '#f3e8ff'),
color: isDelhivery ? '#0369a1' : (isEkart ? '#92400e' : '#6b21a8')
}}>
{isDelhivery ? 'Date + Time Slot Enabled' : (isEkart ? 'Date Selection Enabled' : 'Automated Cutoff Sweep')}
</span>
</div>
</div>
{/* 2A: Pickup Date Selector */}
<div>
<label className="label is-size-7 has-text-weight-semibold" style={{ color: '#1c1b1b' }}>
Pickup Date {isShadowfax && '(Automatic Next Sweep Cycle)'}
</label>
<div className="is-flex is-align-items-center gap-3">
<div className="control has-icons-left" style={{ width: '100%', maxWidth: '320px' }}>
<input
type="date"
className="input is-rounded"
value={pickupDate}
min={todayStr}
disabled={isShadowfax}
onChange={(e) => setPickupDate(e.target.value)}
style={{ fontSize: '14px', border: '1px solid #dcd9d9', opacity: isShadowfax ? 0.7 : 1 }}
/>
<span className="icon is-small is-left">
<Calendar size={16} style={{ color: '#791b2c' }} />
</span>
</div>
<div className="buttons are-small mb-0">
<button
type="button"
className={`button is-rounded ${pickupDate === todayStr ? 'is-dark' : 'is-light'}`}
disabled={isShadowfax}
onClick={() => setPickupDate(todayStr)}
>
Today
</button>
<button
type="button"
className={`button is-rounded ${pickupDate === tomorrowStr ? 'is-dark' : 'is-light'}`}
disabled={isShadowfax}
onClick={() => setPickupDate(tomorrowStr)}
>
Tomorrow
</button>
</div>
</div>
{isShadowfax && (
<p className="help mt-1" style={{ color: '#6b7280' }}>
Shadowfax sweep schedules run on standard morning cut-off windows for origin pincode.
</p>
)}
</div>
{/* 2B: Time Slot Selector */}
<div>
<div className="is-flex is-align-items-center justify-content-between mb-2">
<label className="label is-size-7 has-text-weight-semibold mb-0" style={{ color: '#1c1b1b' }}>
Courier Arrival Slot
</label>
{!isDelhivery && (
<span className="is-size-7 is-inline-flex is-align-items-center gap-1" style={{ color: '#6b7280' }}>
<Lock size={12} /> Managed by carrier logistics
</span>
)}
</div>
{isDelhivery ? (
/* Delhivery: Fully Interactive Slot Options */
<div className="columns is-multiline is-variable is-3">
{delhiverySlots.map((s) => {
const isSelected = slot === s.id;
return (
<div className="column is-4" key={s.id}>
<div
className="p-4 cursor-pointer transition-all h-100 is-flex is-flex-direction-column justify-content-between"
style={{
borderRadius: '12px',
backgroundColor: isSelected ? 'rgba(255, 218, 219, 0.25)' : 'rgba(246, 243, 242, 0.5)',
border: isSelected ? '2px solid #791b2c' : '1px solid rgba(234, 231, 231, 0.8)',
boxShadow: isSelected ? '0 4px 12px rgba(121, 27, 44, 0.08)' : 'none'
}}
onClick={() => setSlot(s.id)}
>
<div>
<div className="is-flex is-align-items-center justify-content-between mb-2">
<span className="tag is-rounded is-small has-text-weight-bold" style={{ backgroundColor: `${s.tagColor}15`, color: s.tagColor }}>
{s.tag}
</span>
{isSelected ? <CheckCircle2 size={16} style={{ color: '#791b2c' }} /> : <Clock size={16} style={{ color: '#9ca3af' }} />}
</div>
<h4 className="has-text-weight-bold is-size-6" style={{ color: '#1c1b1b' }}>{s.label}</h4>
<p className="has-text-weight-semibold is-size-7 mt-1" style={{ color: '#5a0118' }}>{s.time}</p>
<p className="is-size-7 mt-1" style={{ color: '#6b7280', fontSize: '11px' }}>{s.desc}</p>
</div>
</div>
</div>
);
})}
</div>
) : isEkart ? (
/* Ekart: Date Enabled, Fixed Daily Sweeps */
<div className="p-4" style={{ borderRadius: '12px', backgroundColor: '#f9fafb', border: '1px dashed #d1d5db' }}>
<div className="is-flex is-align-items-center gap-3">
<Truck size={24} style={{ color: '#92400e' }} />
<div>
<h4 className="has-text-weight-semibold is-size-6" style={{ color: '#1f2937' }}>
Ekart Standard Hub Sweep Routine
</h4>
<p className="is-size-7 mt-1" style={{ color: '#4b5563' }}>
Ekart picks up packages during regular daily runs (<strong>Morning: 10:00 AM – 1:00 PM</strong> and <strong>Evening: 4:00 PM – 7:00 PM</strong>) for the selected date <strong>{pickupDate}</strong>.
</p>
</div>
</div>
</div>
) : (
/* Shadowfax: Automated Cutoff */
<div className="p-4" style={{ borderRadius: '12px', backgroundColor: '#f9fafb', border: '1px dashed #d1d5db' }}>
<div className="is-flex is-align-items-center gap-3">
<Clock size={24} style={{ color: '#6b21a8' }} />
<div>
<h4 className="has-text-weight-semibold is-size-6" style={{ color: '#1f2937' }}>
Shadowfax Automated Pickup Cycle
</h4>
<p className="is-size-7 mt-1" style={{ color: '#4b5563' }}>
Shadowfax allocates field executives dynamically per order SLA. The dispatch window is automatically locked and confirmed with carrier dispatch HQ.
</p>
</div>
</div>
</div>
)}
</div>
</div>
{/* Step 3: Instructions for Driver */}
<div className="card p-6 is-flex is-flex-direction-column gap-3 shadow-sm" style={{ borderRadius: '16px', backgroundColor: '#ffffff', border: '1px solid rgba(234, 231, 231, 0.6)' }}>
<div className="is-flex is-flex-direction-column gap-1">
<span className="is-size-7 has-text-weight-bold is-uppercase" style={{ letterSpacing: '0.04em', color: '#5a0118' }}>Step 3</span>
<h2 className="is-size-5 has-text-weight-semibold" style={{ color: '#1c1b1b' }}>3. Instructions for Driver (Optional)</h2>
</div>
<div className="is-flex is-align-items-center gap-3 px-4 py-3 mt-2" style={{ borderRadius: '12px', backgroundColor: '#f6f3f2' }}>
<Edit size={18} style={{ color: '#564243' }} />
<input
type="text"
placeholder="Any notes for the driver? (e.g. Call before arrival, use side gate)"
placeholder="Any notes for the driver? (e.g. Call before arrival, packaging fragile craft, use side gate)"
value={driverNotes}
onChange={(e) => setDriverNotes(e.target.value)}
style={{ background: 'transparent', border: 'none', outline: 'none', width: '100%', color: '#1c1b1b', fontSize: '13px' }}
/>
</div>
@ -174,52 +434,85 @@ export const ReschedulePickupView: React.FC<ReschedulePickupViewProps> = ({ onBa
</div>
{/* Right Column: Summary Card */}
<div className="column is-4">
<div className="is-flex is-flex-direction-column gap-5 sticky-top">
<div className="card p-6 is-flex is-flex-direction-column gap-4 shadow-sm" style={{ borderRadius: '16px', backgroundColor: '#ffffff', border: '1px solid rgba(234, 231, 231, 0.6)' }}>
<div className="is-flex is-align-items-center justify-content-between pb-3" style={{ borderBottom: '1px solid rgba(234, 231, 231, 0.6)' }}>
<span className="is-size-5 has-text-weight-semibold" style={{ color: '#1c1b1b' }}>Reschedule Summary</span>
<span className="is-size-5 has-text-weight-semibold" style={{ color: '#1c1b1b' }}>Pickup Summary</span>
<Truck size={20} style={{ color: '#5a0118' }} />
</div>
<div className="is-flex is-flex-direction-column is-size-7" style={{ gap: '0.75rem' }}>
<div className="is-flex is-align-items-flex-start justify-content-between" style={{ gap: '1rem' }}>
<span style={{ color: '#564243', flexShrink: 0 }}>Consignment</span>
<span style={{ color: '#564243', flexShrink: 0 }}>Assigned Courier</span>
<span className="has-text-weight-semibold has-text-right" style={{ color: '#1c1b1b' }}>
{order ? '1 Package' : `${readyOrders.length} Package${readyOrders.length === 1 ? '' : 's'}`}
{carrierDisplayName}
</span>
</div>
<div className="is-flex is-align-items-flex-start justify-content-between" style={{ gap: '1rem' }}>
<span style={{ color: '#564243', flexShrink: 0 }}>Consignment</span>
<span className="has-text-weight-semibold has-text-right" style={{ color: '#1c1b1b' }}>
{targetOrder ? `Order #${targetOrder.orderNumber}` : `${readyOrders.length} Ready Packages`}
</span>
</div>
{targetOrder?.awbNumber && targetOrder.awbNumber !== 'Pending' && (
<div className="is-flex is-align-items-flex-start justify-content-between" style={{ gap: '1rem' }}>
<span style={{ color: '#564243', flexShrink: 0 }}>AWB Tracking</span>
<span className="is-family-monospace has-text-weight-semibold has-text-right" style={{ color: '#0369a1' }}>
{targetOrder.awbNumber}
</span>
</div>
)}
<div className="is-flex is-align-items-flex-start justify-content-between" style={{ gap: '1rem' }}>
<span style={{ color: '#564243', flexShrink: 0 }}>Pickup Location</span>
<span className="has-text-weight-semibold has-text-right" style={{ color: '#1c1b1b' }}>{locationName}</span>
</div>
<div className="is-flex is-align-items-flex-start justify-content-between" style={{ gap: '1rem' }}>
<span style={{ color: '#564243', flexShrink: 0 }}>Selected New Slot</span>
<span style={{ color: '#564243', flexShrink: 0 }}>Scheduled Date</span>
<span className="has-text-weight-semibold has-text-right" style={{ color: '#5a0118' }}>
{dateType === 'tomorrow' ? 'Tomorrow' : 'Custom'},<br/>{slot === 'morning' ? '10:00 AM – 1:00 PM' : slot === 'afternoon' ? '2:00 PM – 5:00 PM' : '5:00 PM – 7:00 PM'}
{pickupDate}
</span>
</div>
<div className="is-flex is-align-items-flex-start justify-content-between" style={{ gap: '1rem' }}>
<span style={{ color: '#564243', flexShrink: 0 }}>Arrival Window</span>
<span className="has-text-weight-semibold has-text-right" style={{ color: '#5a0118' }}>
{isDelhivery
? (slot === 'morning' ? '10:00 AM – 1:00 PM' : slot === 'evening' ? '5:00 PM – 7:00 PM' : '2:00 PM – 5:00 PM')
: (isEkart ? 'Standard Daily Hub Sweep' : 'Automated Cutoff Sweep')}
</span>
</div>
</div>
<div className="p-4 mt-2 is-flex is-align-items-flex-start" style={{ gap: '0.75rem', borderRadius: '12px', backgroundColor: 'rgba(255, 218, 219, 0.2)' }}>
<CheckCircle2 size={20} style={{ color: '#5a0118', flexShrink: 0, marginTop: '2px' }} />
<ShieldCheck size={20} style={{ color: '#5a0118', flexShrink: 0, marginTop: '2px' }} />
<div className="is-flex is-flex-direction-column">
<span className="is-size-7 has-text-weight-bold is-uppercase" style={{ letterSpacing: '0.04em', color: '#5a0118' }}>Tradhox Artisan Promise</span>
<p className="is-size-7 mt-1" style={{ color: '#1c1b1b' }}>100% protection on courier adjustments. No penalties for handmade delays.</p>
<span className="is-size-7 has-text-weight-bold is-uppercase" style={{ letterSpacing: '0.04em', color: '#5a0118' }}>Tradhox Seller Protection</span>
<p className="is-size-7 mt-1" style={{ color: '#1c1b1b' }}>Carrier sweeps are audited live in the shipping microservice. Dispatch SLAs are protected.</p>
</div>
</div>
<div className="is-flex is-flex-direction-column pt-3" style={{ gap: '0.75rem' }}>
<button onClick={onBack} className="button is-rounded shadow-sm" style={{ height: 'auto', minHeight: '48px', whiteSpace: 'normal', padding: '10px 16px', lineHeight: '1.3', backgroundColor: '#791b2c', color: '#ffffff', fontWeight: 600, border: 'none', transition: 'all 0.2s' }}>
Confirm Rescheduled Pickup
<button
onClick={handleConfirmSchedule}
disabled={isSubmitting}
className={`button is-rounded shadow-sm ${isSubmitting ? 'is-loading' : ''}`}
style={{ height: 'auto', minHeight: '48px', whiteSpace: 'normal', padding: '10px 16px', lineHeight: '1.3', backgroundColor: '#791b2c', color: '#ffffff', fontWeight: 600, border: 'none', transition: 'all 0.2s' }}
>
Confirm Scheduled Pickup
</button>
<button onClick={onBack} className="button is-rounded" style={{ height: 'auto', minHeight: '44px', whiteSpace: 'normal', padding: '10px 16px', lineHeight: '1.3', backgroundColor: '#f6f3f2', color: '#564243', fontWeight: 600, border: 'none', transition: 'all 0.2s' }}>
Keep Original Scheduled Pickup
<button
onClick={onBack}
disabled={isSubmitting}
className="button is-rounded"
style={{ height: 'auto', minHeight: '44px', whiteSpace: 'normal', padding: '10px 16px', lineHeight: '1.3', backgroundColor: '#f6f3f2', color: '#564243', fontWeight: 600, border: 'none', transition: 'all 0.2s' }}
>
Keep Original Schedule
</button>
</div>
<p className="has-text-centered pt-2" style={{ fontSize: '13px', color: '#564243', lineHeight: 1.4 }}>
Buyer notifications will be automatically updated with the revised dispatch schedule.
Carrier dispatch and tracking manifests will automatically update with this arrival schedule.
</p>
</div>
</div>

View file

@ -35,7 +35,7 @@ interface SellerContextType {
trackOrder: (orderId: string, awb?: string) => Promise<any>;
cancelOrderPickup: (orderId: string, reason?: string) => Promise<any>;
getOrderLabel: (orderId: string) => Promise<any>;
reschedulePickup: (orderId: string, slot: string, reason: string) => void;
reschedulePickup: (orderId: string, payload: any) => Promise<any>;
// Returns & Reverse Shipping with QC
returnsList: any[];
@ -580,10 +580,21 @@ export const SellerProvider: React.FC<{ children: React.ReactNode }> = ({ childr
}
};
const reschedulePickup = (orderId: string, slot: string, _reason: string) => {
setOrders(prev =>
prev.map(ord => (ord.id === orderId ? { ...ord, pickupSlot: slot } : ord))
);
const reschedulePickup = async (orderId: string, payload: any, legacyReason?: string) => {
let reqData: any;
if (typeof payload === 'string') {
const tomorrowStr = new Date(Date.now() + 86400000).toISOString().split('T')[0];
reqData = {
pickup_date: tomorrowStr,
pickup_time: payload,
notes: legacyReason || ''
};
} else {
reqData = payload;
}
const res = await api.scheduleOrderPickup(orderId, reqData);
await fetchData();
return res;
};
const actionReturn = async (returnId: string, action: 'Approved' | 'Rejected') => {

View file

@ -29,6 +29,7 @@ export const OrdersPage: React.FC = () => {
const [showManifest, setShowManifest] = useState(false);
const [showReschedule, setShowReschedule] = useState(false);
const [selectedOrderForReschedule, setSelectedOrderForReschedule] = useState<OrderItem | null>(null);
const [showReportDamage, setShowReportDamage] = useState(false);
// Modals state
@ -257,19 +258,27 @@ export const OrdersPage: React.FC = () => {
if (showReschedule) {
return (
<ReschedulePickupView
onBack={() => setShowReschedule(false)}
order={selectedOrderForReschedule || orders.find(o => o.status === 'ready_to_ship')}
onBack={() => {
setShowReschedule(false);
setSelectedOrderForReschedule(null);
}}
onTabChange={(tab) => {
if (tab === 'overall') {
setShowReschedule(false);
setSelectedOrderForReschedule(null);
setActiveTab('all');
} else if (tab === 'ready_for_pickup') {
setShowReschedule(false);
setSelectedOrderForReschedule(null);
setActiveTab('ready_to_ship');
} else if (tab === 'handover') {
setShowReschedule(false);
setSelectedOrderForReschedule(null);
setShowManifest(true);
} else if (tab === 'report_damage') {
setShowReschedule(false);
setSelectedOrderForReschedule(null);
setShowReportDamage(true);
}
}}
@ -308,6 +317,7 @@ export const OrdersPage: React.FC = () => {
onBack={() => setActiveOrder(null)}
onPrintLabel={() => handleFetchPrintLabel(activeOrder)}
onReschedule={() => {
setSelectedOrderForReschedule(activeOrder);
setActiveOrder(null);
setShowReschedule(true);
}}
@ -622,6 +632,17 @@ export const OrdersPage: React.FC = () => {
</>
) : ord.status === 'ready_to_ship' ? (
<>
<button
onClick={() => {
setSelectedOrderForReschedule(ord);
setShowReschedule(true);
}}
className="button is-small is-rounded is-warning is-light"
disabled={isLoading}
title="Schedule or adjust courier pickup window"
>
<Clock size={14} className="mr-1" /> Schedule Pickup
</button>
<button
onClick={() => handleFetchPrintLabel(ord)}
className="button is-small is-rounded is-trad-primary shadow-sm"

View file

@ -438,6 +438,28 @@ export const api = {
return res.json();
},
getPickupCapabilities: async (carrier?: string) => {
const query = carrier ? `?carrier=${encodeURIComponent(carrier)}` : '';
const res = await fetch(`${BASE_URL}/shipping/forward/schedule-pickup/${query}`, {
headers: getAuthHeaders()
});
if (!res.ok) throw new Error('Failed to fetch pickup capabilities');
return res.json();
},
scheduleOrderPickup: async (id: string | number, payload: { pickup_date: string; pickup_time?: string; reason?: string; notes?: string; package_count?: number }) => {
const res = await fetch(`${BASE_URL}/orders/${id}/schedule_pickup/`, {
method: 'POST',
headers: getAuthHeaders(),
body: JSON.stringify(payload)
});
if (!res.ok) {
const errText = await parseApiError(res, 'Failed to schedule pickup');
throw new Error(errText);
}
return res.json();
},
getOrderLabel: async (id: string | number) => {
const res = await fetch(`${BASE_URL}/orders/${id}/print_label/`, {
headers: getAuthHeaders()