/**
* Completion Step - Step 4 of ScanForm creation
*/
import { Button, Flex, Notice } from '@wordpress/components';
import { __, sprintf } from '@wordpress/i18n';
import { isDomesticShipment, isSafePdfUrl } from 'utils/scan-form';
import type { ScanFormLabel } from 'types';
interface CompletionStepProps {
successMessage: string;
processedLabelIds: number[];
pdfUrls: string[];
processedLabelBatches: number[][];
partialFailureMessage?: string | null;
partialFailureLabelIds?: number[];
getLabelInfo: ( labelId: number ) => ScanFormLabel | null;
}
export const CompletionStep = ( {
successMessage,
processedLabelIds,
pdfUrls,
processedLabelBatches,
partialFailureMessage,
partialFailureLabelIds,
getLabelInfo,
}: CompletionStepProps ) => {
return (
<>
{ successMessage }
{ partialFailureMessage && (
{ partialFailureMessage }
{ partialFailureLabelIds &&
partialFailureLabelIds.length > 0 && (
{ partialFailureLabelIds.map( ( labelId ) => {
const label = getLabelInfo( labelId );
return label ? (
-
{ sprintf(
/* translators: %1$s is order number, %2$s is tracking number, %3$s is service name */
__(
'Order #%1$s - %2$s - %3$s',
'woocommerce-shipping'
),
label.order_number ?? '',
label.tracking ?? '',
label.service_name
) }
) : (
-
{ sprintf(
/* translators: %d is label ID */
__(
'Label ID: %d',
'woocommerce-shipping'
),
labelId
) }
);
} ) }
) }
) }
{ __( 'Processed Labels:', 'woocommerce-shipping' ) }
{ processedLabelIds.map( ( labelId ) => {
const label = getLabelInfo( labelId );
return label ? (
-
{ sprintf(
/* translators: %1$s is order number, %2$s is tracking number, %3$s is service name */
__(
'Order #%1$s - %2$s - %3$s',
'woocommerce-shipping'
),
label.order_number ?? '',
label.tracking ?? '',
label.service_name
) }
) : (
-
{ sprintf(
/* translators: %d is label ID */
__(
'Label ID: %d',
'woocommerce-shipping'
),
labelId
) }
);
} ) }
{ pdfUrls.length > 0 && (
{ pdfUrls.map( ( url, index ) => {
if ( ! isSafePdfUrl( url ) ) {
return null;
}
const batch = processedLabelBatches[ index ] ?? [];
const firstLabel =
batch.length > 0
? getLabelInfo( batch[ 0 ] )
: null;
const isDomestic = firstLabel
? isDomesticShipment( firstLabel )
: true;
const batchLabel = isDomestic
? __( 'Domestic', 'woocommerce-shipping' )
: __( 'International', 'woocommerce-shipping' );
return (
);
} ) }
) }
>
);
};