/** * Order complete / fulfilled view – design aligned with success screen: * optional P2G logo, centered title, success message, and action buttons. * P2G logo only appears when the order has p2g meta (shipped with Parcel2Go). */ import { __ } from '@wordpress/i18n'; import { Flex, FlexItem, Button, ButtonGroup, Spinner, Card, CardBody, } from '@wordpress/components'; import { download, help } from '@wordpress/icons'; import type { Order } from '../../types'; import { getCourierLogo } from '../../shared/utils/getAsset'; import { getLandingPageUrl } from '../../shared/utils'; import { useLabelDownload, useShippingLabelReady } from '../../shared/hooks'; const P2G_HELP_URL = 'https://www.parcel2go.com/help-centre/parcels/question/general/how-do-i-contact-parcel2go'; export interface OrderCompleteViewProps { order: Order; orderLabel: string; onBack: () => void; isFulfilled: boolean; p2gOrderLineIds?: string[]; /** Booking in this session returned a label hash (order refetch may be stale). */ labelHashSavedThisSession?: boolean; } export default function OrderCompleteView({ order, orderLabel, onBack, isFulfilled, p2gOrderLineIds = [], labelHashSavedThisSession = false, }: OrderCompleteViewProps) { const hasParcel2GoBooking = Boolean(order.p2g?.orderId); const p2gLogo = hasParcel2GoBooking ? getCourierLogo('p2g') : undefined; const transactionId = String(order.p2g?.orderId ?? '').replace(/^P2G/i, ''); const displayOrderLineIds = ( p2gOrderLineIds.length > 0 ? p2gOrderLineIds : (order.p2g?.orderLineIds ?? []) ) .map((orderLineId) => String(orderLineId).trim()) .filter(Boolean) .map((orderLineId) => /^P2G/i.test(orderLineId) ? orderLineId : `P2G${orderLineId}` ); const { showLabelDownload, isResolvingLabel } = useShippingLabelReady( order.id, { labelHashPresent: order.p2g?.hasLabelHash === true || labelHashSavedThisSession, shouldFetchLabelFromApi: !labelHashSavedThisSession && order.p2g?.canSyncLabelHash === true, } ); const { labelSize, setLabelSize, downloadLabel, loading, error, labelSizeOptions, } = useLabelDownload(order.id); const handleShipMore = () => { window.location.assign(getLandingPageUrl()); }; return ( {/* Top: P2G logo only when order has p2g meta */} {p2gLogo && ( Parcel2Go )} {/* Centered content */}

{__('Order Complete', 'parcel2go-shipping')}

{__( 'Your shipping order has been processed successfully.', 'parcel2go-shipping' )}

{hasParcel2GoBooking && ( <> {transactionId && (

{__('TransactionID', 'parcel2go-shipping')}{' '} {transactionId}

)} {displayOrderLineIds.length > 0 && (

{__('P2G Order no', 'parcel2go-shipping')}{' '} {displayOrderLineIds.join(', ')}

)}

{isFulfilled ? __( 'Ready for shipment', 'parcel2go-shipping' ) : __( 'Booking in progress', 'parcel2go-shipping' )}

)} {/* Success message box */}

{__( 'Order processed successfully.', 'parcel2go-shipping' )}{' '} {__( "Your order has been booked and is ready to be shipped. We've automatically marked the order as complete in your WooCommerce store.", 'parcel2go-shipping' )}

{isResolvingLabel && !showLabelDownload && ( {__('Loading label…', 'parcel2go-shipping')} )} {showLabelDownload && ( {__('Label size', 'parcel2go-shipping')} {labelSizeOptions.map((option) => ( ))} {error && (

{error}

)}
)} {isFulfilled && ( )} {!isFulfilled && ( )}
); }