/** * Previous Shipments page – displays WooCommerce orders shipped via Parcel2Go * in a responsive card grid with pagination. */ import { __ } from '@wordpress/i18n'; import { useMemo, useCallback } from '@wordpress/element'; import { Section, Pagination } from '@woocommerce/components'; import { Button, Card, CardBody, Flex, FlexBlock, Notice, } from '@wordpress/components'; import { getLandingPageUrl } from '../shared/utils'; import { useShipments, useWindowSize } from '../shared/hooks'; import { ShipmentCard, ShipmentsSkeleton } from '../features/shipments'; const ROWS_PER_PAGE = 10; export default function PreviousShipmentsPage() { const { shipments, total, page, loading, error, fetchShipments } = useShipments(ROWS_PER_PAGE); const { isMdOrUp } = useWindowSize(); const handlePageChange = useCallback( (newPage: number) => { fetchShipments(newPage); }, [fetchShipments] ); const cardColumns = isMdOrUp ? 2 : 1; const rows = useMemo(() => { const result: (typeof shipments)[] = []; for (let i = 0; i < shipments.length; i += cardColumns) { result.push(shipments.slice(i, i + cardColumns)); } return result; }, [shipments, cardColumns]); return (
{/* Page header */}

{__('Previous Shipments', 'parcel2go-shipping')}

{__( 'View your shipped orders, download labels, and track deliveries.', 'parcel2go-shipping' )}

{/* Error state */} {error && ( {error} )} {/* Loading state: skeleton cards */} {loading && shipments.length === 0 && ( )} {/* Empty state */} {!loading && !error && shipments.length === 0 && ( 📦

{__( 'No shipments yet', 'parcel2go-shipping' )}

{__( 'Once you ship orders through Parcel2Go, they will appear here. Head to the orders page to get started.', 'parcel2go-shipping' )}

)} {/* Shipment grid */} {shipments.length > 0 && ( {rows.map((row, rowIdx) => ( {row.map((shipment) => ( ))} {/* Filler for incomplete rows to maintain grid alignment */} {row.length < cardColumns && Array.from( { length: cardColumns - row.length }, (_, i) => ( ) )} ))} )} {/* Pagination */} {!loading && total > ROWS_PER_PAGE && ( )}
); }