You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

207 lines
6.3 KiB

import React, { useRef } from 'react';
import { useAnimatedPresence } from '../../hooks/use-animated-presence';
import { useHardwareBackHandler } from '../../hooks/use-hardware-back-handler';
import { tr } from '../../lib/cookies';
import type { ApiShipment } from '../../lib/shopApi';
import { copyToClipboard } from '../../lib/webview-actions';
interface ShipmentTrackingSheetProps {
shipment: ApiShipment | null;
onClose: () => void;
onCopied?: () => void;
}
export const ShipmentTrackingSheet: React.FC<ShipmentTrackingSheetProps> = ({
shipment,
onClose,
onCopied,
}) => {
const isOpen = Boolean(shipment);
const { shouldRender, isClosing } = useAnimatedPresence(isOpen, 200);
const lastShipmentRef = useRef<ApiShipment | null>(shipment);
if (shipment) {
lastShipmentRef.current = shipment;
}
const activeShipment = shipment || lastShipmentRef.current;
useHardwareBackHandler(() => {
onClose();
return true;
}, isOpen);
if (!shouldRender || !activeShipment) return null;
const handleCopyTracking = async () => {
if (!activeShipment.tracking_code) return;
const ok = await copyToClipboard(activeShipment.tracking_code);
if (ok && onCopied) onCopied();
};
return (
<div
className={`habib-sheet-backdrop${isClosing ? ' is-closing' : ''}`}
onClick={onClose}
style={{
position: 'fixed',
inset: 0,
backgroundColor: 'rgba(17, 17, 17, 0.9)',
zIndex: 60,
display: 'flex',
flexDirection: 'column',
justifyContent: 'flex-end',
}}
>
<div
className={`habib-bottom-sheet${isClosing ? ' is-closing' : ''}`}
onClick={(e) => e.stopPropagation()}
style={{
padding: '22px var(--page-px) calc(24px + var(--safe-bottom, 0px))',
display: 'flex',
flexDirection: 'column',
gap: '16px',
maxHeight: '85dvh',
overflowY: 'auto',
}}
>
<div
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
}}
>
<span
style={{
fontFamily: 'var(--font-sans)',
fontWeight: 700,
fontSize: '15px',
color: '#111111',
}}
>
{tr('Shipment Tracking')} • {activeShipment.booth_name}
</span>
<button
type="button"
className="habib-icon-btn"
onClick={onClose}
aria-label={tr('Close')}
style={{
width: '24px',
height: '24px',
cursor: 'pointer',
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
}}
>
<img
src="/assets/images/icon-modal-close-cross.svg"
alt=""
style={{ width: '11.67px', height: '11.67px' }}
/>
</button>
</div>
<div
style={{
padding: '12px',
borderRadius: '12px',
backgroundColor: '#f3f3f3',
display: 'flex',
flexDirection: 'column',
gap: '8px',
}}
>
<div style={{ display: 'flex', justifyContent: 'space-between', fontSize: '12px' }}>
<span style={{ color: '#747474', fontWeight: 600 }}>{tr('Carrier')}</span>
<span style={{ color: '#111111', fontWeight: 700 }}>
{activeShipment.carrier_name || 'Habib Global Post'}
</span>
</div>
{activeShipment.tracking_code && (
<div
style={{
display: 'flex',
alignItems: 'center',
justifyContent: 'space-between',
fontSize: '12px',
}}
>
<span style={{ color: '#747474', fontWeight: 600 }}>{tr('Tracking code')}</span>
<button
type="button"
onClick={handleCopyTracking}
style={{
color: '#d78e06',
fontWeight: 700,
fontSize: '12px',
cursor: 'pointer',
}}
>
{activeShipment.tracking_code} ({tr('Copy')})
</button>
</div>
)}
<div style={{ display: 'flex', justifyContent: 'space-between', fontSize: '12px' }}>
<span style={{ color: '#747474', fontWeight: 600 }}>{tr('Estimated Delivery')}</span>
<span style={{ color: '#111111', fontWeight: 700 }}>
{tr(activeShipment.estimated_delivery_label || '2-3 business day')}
</span>
</div>
</div>
<div style={{ display: 'flex', flexDirection: 'column', gap: '12px' }}>
{(activeShipment.events || []).map((ev, idx) => (
<div
key={ev.id || idx}
style={{
display: 'flex',
alignItems: 'flex-start',
gap: '10px',
}}
>
<div
style={{
width: '12px',
height: '12px',
marginTop: '3px',
borderRadius: '50%',
backgroundColor: idx === 0 ? '#0eb13c' : '#d78e06',
flexShrink: 0,
}}
/>
<div style={{ display: 'flex', flexDirection: 'column', gap: '2px' }}>
<span style={{ fontSize: '13px', fontWeight: 700, color: '#111111' }}>
{tr(ev.title)}
</span>
<span style={{ fontSize: '11px', color: '#747474' }}>
{ev.location ? `${ev.location} • ` : ''}
{ev.formatted_time}
</span>
</div>
</div>
))}
</div>
<button
type="button"
className="habib-cta-btn"
onClick={onClose}
style={{
width: '100%',
height: '48px',
borderRadius: '11px',
color: '#fbfbfc',
fontFamily: 'var(--font-sans)',
fontWeight: 700,
fontSize: '15px',
cursor: 'pointer',
}}
>
{tr('Close')}
</button>
</div>
</div>
);
};