|
| 1 | +import { COUNTRY_SELECT_ITEMS } from "@/components/checkout/checkout.constants"; |
| 2 | +import type { CheckoutStepSlug } from "@/components/checkout/checkout.constants"; |
| 3 | +import { resolveCheckoutStepHref } from "@/components/checkout/checkout-route.utils"; |
| 4 | +import type { CheckoutController } from "@/components/checkout/use-checkout-controller"; |
| 5 | +import { CheckoutCartStepSection } from "@/components/checkout/sections/checkout-cart-step-section"; |
| 6 | +import { CheckoutDetailsStepSection } from "@/components/checkout/sections/checkout-details-step-section"; |
| 7 | +import { CheckoutOrderSummarySection } from "@/components/checkout/sections/checkout-order-summary-section"; |
| 8 | +import { CheckoutShippingPaymentStepSection } from "@/components/checkout/sections/checkout-shipping-payment-step-section"; |
| 9 | +import { CheckoutSummaryStepSection } from "@/components/checkout/sections/checkout-summary-step-section"; |
| 10 | +import { resolveProviderLabel } from "@/components/checkout/checkout.utils"; |
| 11 | + |
| 12 | +type CheckoutStepContentProps = { |
| 13 | + activeStep: CheckoutStepSlug; |
| 14 | + controller: CheckoutController; |
| 15 | +}; |
| 16 | + |
| 17 | +export function CheckoutStepContent({ |
| 18 | + activeStep, |
| 19 | + controller, |
| 20 | +}: CheckoutStepContentProps) { |
| 21 | + const cartStepHref = resolveCheckoutStepHref("kosik"); |
| 22 | + const shippingStepHref = resolveCheckoutStepHref("doprava-platba"); |
| 23 | + const detailsStepHref = resolveCheckoutStepHref("udaje"); |
| 24 | + const summaryStepHref = resolveCheckoutStepHref("suhrn"); |
| 25 | + const selectedPaymentProviderId = controller.hasPayment |
| 26 | + ? (controller.checkoutPaymentQuery.paymentProviders[0]?.id ?? undefined) |
| 27 | + : undefined; |
| 28 | + const selectedPaymentLabel = |
| 29 | + typeof selectedPaymentProviderId === "string" && selectedPaymentProviderId.length > 0 |
| 30 | + ? resolveProviderLabel(selectedPaymentProviderId) |
| 31 | + : undefined; |
| 32 | + |
| 33 | + const orderSummarySection = ( |
| 34 | + <CheckoutOrderSummarySection |
| 35 | + cartItems={controller.cartItems} |
| 36 | + cartSubtotalAmount={controller.cartSubtotalAmount} |
| 37 | + cartTotalAmount={controller.cartTotalAmount} |
| 38 | + currencyCode={controller.currencyCode} |
| 39 | + hasPayment={controller.hasPayment} |
| 40 | + hasShipping={controller.hasShipping} |
| 41 | + selectedOptionName={controller.checkoutShippingQuery.selectedOption?.name ?? undefined} |
| 42 | + selectedShippingPrice={controller.selectedShippingPrice} |
| 43 | + /> |
| 44 | + ); |
| 45 | + |
| 46 | + if (activeStep === "kosik") { |
| 47 | + return ( |
| 48 | + <div className="checkout-step-grid"> |
| 49 | + <div className="space-y-350"> |
| 50 | + <CheckoutCartStepSection |
| 51 | + cartId={controller.cartQuery.cart?.id} |
| 52 | + cartItems={controller.cartItems} |
| 53 | + cartSubtotalAmount={controller.cartSubtotalAmount} |
| 54 | + currencyCode={controller.currencyCode} |
| 55 | + nextStepHref={shippingStepHref} |
| 56 | + /> |
| 57 | + </div> |
| 58 | + <aside className="space-y-300 xl:sticky xl:top-400 xl:self-start"> |
| 59 | + {orderSummarySection} |
| 60 | + </aside> |
| 61 | + </div> |
| 62 | + ); |
| 63 | + } |
| 64 | + |
| 65 | + if (activeStep === "doprava-platba") { |
| 66 | + return ( |
| 67 | + <div className="checkout-step-grid"> |
| 68 | + <div className="space-y-350"> |
| 69 | + <CheckoutShippingPaymentStepSection |
| 70 | + backStepHref={cartStepHref} |
| 71 | + canContinue={controller.hasShipping && controller.hasPayment} |
| 72 | + nextStepHref={detailsStepHref} |
| 73 | + paymentProps={{ |
| 74 | + canInitiatePayment: controller.checkoutPaymentQuery.canInitiatePayment, |
| 75 | + hasPayment: controller.hasPayment, |
| 76 | + isBusy: controller.isBusy, |
| 77 | + isInitiatingPayment: controller.checkoutPaymentQuery.isInitiatingPayment, |
| 78 | + onSelectPaymentProvider: controller.handleSelectPaymentProvider, |
| 79 | + paymentProviders: controller.checkoutPaymentQuery.paymentProviders, |
| 80 | + selectedPaymentProviderId, |
| 81 | + }} |
| 82 | + shippingProps={{ |
| 83 | + currencyCode: controller.currencyCode, |
| 84 | + hasShipping: controller.hasShipping, |
| 85 | + isBusy: controller.isBusy, |
| 86 | + onSelectShipping: controller.handleSelectShipping, |
| 87 | + selectedShippingMethodId: |
| 88 | + controller.checkoutShippingQuery.selectedShippingMethodId, |
| 89 | + shippingOptions: controller.checkoutShippingQuery.shippingOptions, |
| 90 | + shippingPrices: controller.checkoutShippingQuery.shippingPrices, |
| 91 | + }} |
| 92 | + /> |
| 93 | + </div> |
| 94 | + <aside className="space-y-300 xl:sticky xl:top-400 xl:self-start"> |
| 95 | + {orderSummarySection} |
| 96 | + </aside> |
| 97 | + </div> |
| 98 | + ); |
| 99 | + } |
| 100 | + |
| 101 | + if (activeStep === "udaje") { |
| 102 | + return ( |
| 103 | + <div className="checkout-step-grid"> |
| 104 | + <div className="space-y-350"> |
| 105 | + <CheckoutDetailsStepSection |
| 106 | + addressProps={{ |
| 107 | + addressForm: controller.addressForm, |
| 108 | + countryItems: COUNTRY_SELECT_ITEMS, |
| 109 | + createAccountConsent: controller.createAccountConsent, |
| 110 | + hasCustomerSupportNote: controller.hasCustomerSupportNote, |
| 111 | + hasDifferentShippingAddress: controller.hasDifferentShippingAddress, |
| 112 | + hasStoredAddress: controller.hasStoredAddress, |
| 113 | + isCompanyPurchase: controller.isCompanyPurchase, |
| 114 | + isBusy: controller.isBusy, |
| 115 | + isSavingAddress: controller.updateCartAddressMutation.isPending, |
| 116 | + onCreateAccountConsentChange: controller.setCreateAccountConsent, |
| 117 | + onCustomerSupportNoteToggle: controller.setHasCustomerSupportNote, |
| 118 | + onDifferentShippingAddressChange: |
| 119 | + controller.setHasDifferentShippingAddress, |
| 120 | + onIsCompanyPurchaseChange: controller.setIsCompanyPurchase, |
| 121 | + onSaveAddress: controller.handleSaveAddress, |
| 122 | + onUpdateAddressField: controller.updateAddressField, |
| 123 | + ready: Boolean(controller.cartQuery.cart?.id), |
| 124 | + }} |
| 125 | + backStepHref={shippingStepHref} |
| 126 | + canContinue={controller.hasStoredAddress} |
| 127 | + nextStepHref={summaryStepHref} |
| 128 | + /> |
| 129 | + </div> |
| 130 | + <aside className="space-y-300 xl:sticky xl:top-400 xl:self-start"> |
| 131 | + {orderSummarySection} |
| 132 | + </aside> |
| 133 | + </div> |
| 134 | + ); |
| 135 | + } |
| 136 | + |
| 137 | + return ( |
| 138 | + <div className="checkout-step-grid"> |
| 139 | + <div className="space-y-350"> |
| 140 | + <CheckoutSummaryStepSection |
| 141 | + completeProps={{ |
| 142 | + addressForm: controller.addressForm, |
| 143 | + canCompleteOrder: controller.canCompleteOrder, |
| 144 | + cartTotalAmount: controller.cartTotalAmount, |
| 145 | + currencyCode: controller.currencyCode, |
| 146 | + detailsStepHref, |
| 147 | + hasPayment: controller.hasPayment, |
| 148 | + hasShipping: controller.hasShipping, |
| 149 | + hasStoredAddress: controller.hasStoredAddress, |
| 150 | + heurekaConsent: controller.heurekaConsent, |
| 151 | + isCompletingOrder: controller.completeCartMutation.isPending, |
| 152 | + marketingConsent: controller.marketingConsent, |
| 153 | + onHeurekaConsentChange: controller.setHeurekaConsent, |
| 154 | + onMarketingConsentChange: controller.setMarketingConsent, |
| 155 | + onCompleteOrder: controller.handleCompleteOrder, |
| 156 | + paymentLabel: selectedPaymentLabel, |
| 157 | + shippingLabel: controller.checkoutShippingQuery.selectedOption?.name ?? undefined, |
| 158 | + shippingStepHref, |
| 159 | + }} |
| 160 | + /> |
| 161 | + </div> |
| 162 | + <aside className="space-y-300 xl:sticky xl:top-400 xl:self-start"> |
| 163 | + {orderSummarySection} |
| 164 | + </aside> |
| 165 | + </div> |
| 166 | + ); |
| 167 | +} |
0 commit comments