/** * Reusable notice listing what must be completed before booking (store, customer address, item weights). * Renders as a list for clarity. Use on landing, order ship page, and service-quotes. */ import { __ } from '@wordpress/i18n'; import { Notice, Icon } from '@wordpress/components'; import { cautionFilled } from '@wordpress/icons'; import type { InternationalMissing } from '../utils'; export interface BookingPrereqsNoticeProps { /** Missing store/collection address fields (e.g. from validateAddresses). */ storeMissing: string[]; /** Missing customer/shipping address fields (e.g. from validateAddresses). */ customerMissing: string[]; /** When delivery is international: grouped by Settings vs products (link shown in front of each group). */ internationalMissing?: InternationalMissing | null; /** Whether every order line item has a weight (only relevant when orderId is set). */ orderHasWeight: boolean; /** Order ID for "edit order" links; null when there is no order (e.g. landing page). */ orderId: number | null; /** URL to the plugin settings page. */ settingsUrl: string; /** Function to build the WooCommerce edit-order URL. Omit when orderId is null (e.g. landing page). */ getEditOrderUrl?: (orderId: number) => string; } const emptyInternational: InternationalMissing = { settings: [], products: [] }; export default function BookingPrereqsNotice({ storeMissing, customerMissing, internationalMissing = emptyInternational, orderHasWeight, orderId, settingsUrl, getEditOrderUrl, }: BookingPrereqsNoticeProps) { const hasStoreIssues = storeMissing.length > 0; const hasCustomerIssues = customerMissing.length > 0; const intl = internationalMissing ?? emptyInternational; const hasInternationalSettings = intl.settings.length > 0; const hasInternationalProducts = intl.products.length > 0; const hasWeightIssues = orderId != null && !orderHasWeight; const items: React.ReactNode[] = []; const listItemStyle = { display: 'flex', alignItems: 'flex-start', gap: 8, marginBottom: 4 }; if (hasStoreIssues) { items.push(
  • {__('Store details (collection address):', 'parcel2go-shipping')}{' '} {storeMissing.join(', ')}.{' '} {__('Fix in Settings', 'parcel2go-shipping')}
  • ); } if (hasCustomerIssues && orderId != null) { const editUrl = getEditOrderUrl?.(orderId) ?? settingsUrl; items.push(
  • {__('Customer shipping address:', 'parcel2go-shipping')}{' '} {customerMissing.join(', ')}.{' '} {__('Edit order', 'parcel2go-shipping')}
  • ); } if (hasWeightIssues) { const editUrl = orderId != null ? getEditOrderUrl?.(orderId) ?? settingsUrl : settingsUrl; items.push(
  • {__('Item weights: set weight for each product on the order.', 'parcel2go-shipping')}{' '} {__('Edit order', 'parcel2go-shipping')}
  • ); } if (hasInternationalSettings) { items.push(
  • {__('Settings', 'parcel2go-shipping')} {': '} {intl.settings.join(', ')}.
  • ); } if (hasInternationalProducts) { const editUrl = orderId != null ? getEditOrderUrl?.(orderId) ?? settingsUrl : settingsUrl; items.push(
  • {orderId != null ? __('Edit order', 'parcel2go-shipping') : __('Products', 'parcel2go-shipping')} {': '} {intl.products.join(', ')}.
  • ); } if (items.length === 0) { return null; } return ( {__('Complete the following before booking:', 'parcel2go-shipping')} ); }