Advertisement
baby_in_magento

vgrg

Apr 2nd, 2024
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 31.57 KB | None | 0 0
  1. import React, { Fragment, useEffect, useState, useRef } from 'react';
  2. import { shape, string } from 'prop-types';
  3. import { FormattedMessage, useIntl } from 'react-intl';
  4. import { AlertCircle as AlertCircleIcon } from 'react-feather';
  5. import { Link } from 'react-router-dom';
  6. import { useWindowSize, useToasts } from '@magento/peregrine';
  7. import {
  8. CHECKOUT_STEP,
  9. useCheckoutPage
  10. } from '@magento/peregrine/lib/talons/CheckoutPage/useCheckoutPage';
  11. import { useStyle } from '@magento/venia-ui/lib/classify';
  12. import Button from '@magento/venia-ui/lib/components/Button';
  13. import { StoreTitle } from '@magento/venia-ui/lib/components/Head';
  14. import Icon from '@magento/venia-ui/lib/components/Icon';
  15. import { fullPageLoadingIndicator } from '@magento/venia-ui/lib/components/LoadingIndicator';
  16. import StockStatusMessage from '@magento/venia-ui/lib/components/StockStatusMessage';
  17. import AddressBook from './AddressBook';
  18. import GuestSignIn from '@magento/venia-ui/lib/components/CheckoutPage/GuestSignIn';
  19. import OrderSummary from './OrderSummary';
  20. import PaymentInformation from './PaymentInformation';
  21. import payments from './PaymentInformation/paymentMethodCollection';
  22. import PriceAdjustments from '@magento/venia-ui/lib/components/CheckoutPage/PriceAdjustments';
  23. import ShippingMethod from '../CheckoutPage/ShippingMethod';
  24. import ShippingInformation from './ShippingInformation';
  25. import Auth from './Auth';
  26. import OrderConfirmationPage from '@magento/venia-ui/lib/components/CheckoutPage/OrderConfirmationPage';
  27. import ItemsReview from './ItemsReview';
  28.  
  29. import GoogleReCaptcha from '@magento/venia-ui/lib/components/GoogleReCaptcha';
  30.  
  31. import defaultClasses from './checkoutPage.module.css';
  32. import ScrollAnchor from '@magento/venia-ui/lib/components/ScrollAnchor/scrollAnchor';
  33.  
  34. import GiftOptions from './GiftOptions';
  35. import downarrow from './GiftOptions/images/down_arrow.svg';
  36. import Payment from './Payment';
  37. import { gql, useQuery } from '@apollo/client';
  38. import { useSelector } from 'react-redux';
  39. import apiClient from '../../api';
  40. import { useAccountMenu } from '../../talons/Header/useAccountMenu';
  41. import { useUserContext } from '@magento/peregrine/lib/context/user';
  42. import { BrowserPersistence } from '@magento/peregrine/lib/util';
  43.  
  44. import { usePriceSummary } from '@magento/peregrine/lib/talons/CartPage/PriceSummary/usePriceSummary';
  45.  
  46. const errorIcon = <Icon src={AlertCircleIcon} size={20} />;
  47. const storage = new BrowserPersistence();
  48. const CheckoutPage = props => {
  49. const { classes: propClasses } = props;
  50. const { formatMessage } = useIntl();
  51. const talonProps = useCheckoutPage();
  52.  
  53. const totalProps = usePriceSummary();
  54.  
  55. const {
  56. flatData
  57. } = totalProps;
  58.  
  59. const {
  60. total
  61. } = flatData;
  62.  
  63. const [addedInstructions, setaddedInstructions] = useState('');
  64. const [showInstructions, setShowInstructions] = useState(false);
  65. const [hideInstructions, setHideInstructions] = useState(true);
  66. const [signIn, setSignIn] = useState(false);
  67. const {
  68. /**
  69. * Enum, one of:
  70. * SHIPPING_ADDRESS, SHIPPING_METHOD, PAYMENT, REVIEW
  71. */
  72. activeContent,
  73. availablePaymentMethods,
  74. cartItems,
  75. checkoutStep,
  76. customer,
  77. error,
  78. guestSignInUsername,
  79. handlePlaceOrder,
  80. hasError,
  81. isCartEmpty,
  82. isGuestCheckout,
  83. isLoading,
  84. isUpdating,
  85. orderDetailsData,
  86. orderDetailsLoading,
  87. orderNumber,
  88. placeOrderLoading,
  89. placeOrderButtonClicked,
  90. setCheckoutStep,
  91. setGuestSignInUsername,
  92. setIsUpdating,
  93. setShippingInformationDone,
  94. scrollShippingInformationIntoView,
  95. setShippingMethodDone,
  96. scrollShippingMethodIntoView,
  97. setPaymentInformationDone,
  98. shippingInformationRef,
  99. shippingMethodRef,
  100. resetReviewOrderButtonClicked,
  101. handleReviewOrder,
  102. reviewOrderButtonClicked,
  103. recaptchaWidgetProps,
  104. toggleAddressBookContent,
  105. toggleSignInContent
  106. } = talonProps;
  107. const isCalledRef = useRef(false);
  108. const [guestCheckout, setGuestCheckout] = useState(isGuestCheckout);
  109.  
  110. const [showGiftOptions, setShowGiftOptions] = useState(false);
  111.  
  112. const shippingInfo = JSON.parse(localStorage.getItem('shipping_data'));
  113.  
  114. const handleSignIn = () => {
  115. setSignIn(true);
  116. setGuestCheckout(false);
  117. setShowGiftOptions(false);
  118. }
  119.  
  120. const [{ isSignedIn }] = useUserContext();
  121.  
  122. const GET_CART_DETAILS = gql` query GetCartDetails($cartId: String!) {
  123. cart(cart_id: $cartId) {
  124. id
  125. items {
  126. ... on SimpleCartItem {
  127. uid
  128. id
  129. customizable_options {
  130. label
  131. type
  132. values {
  133. label
  134. value
  135. price {
  136. value
  137. }
  138. }
  139. }
  140. }
  141. }
  142. }
  143. }
  144. `;
  145.  
  146.  
  147. const cart = useSelector((state) => state.cart);
  148. const { cartId } = cart;
  149.  
  150. const { data, loading } = useQuery(
  151. GET_CART_DETAILS,
  152. {
  153. fetchPolicy: 'cache-and-network',
  154. nextFetchPolicy: 'cache-first',
  155. skip: !cartId,
  156. variables: {
  157. cartId: cartId
  158. }
  159. }
  160. );
  161. const [, { addToast }] = useToasts();
  162.  
  163. useEffect(() => {
  164. if (hasError) {
  165. const message =
  166. error && error.message
  167. ? error.message
  168. : formatMessage({
  169. id: 'checkoutPage.errorSubmit',
  170. defaultMessage:
  171. 'Oops! An error occurred while submitting. Please try again.'
  172. });
  173. addToast({
  174. type: 'error',
  175. icon: errorIcon,
  176. message,
  177. dismissable: true,
  178. timeout: 7000
  179. });
  180.  
  181. if (process.env.NODE_ENV !== 'production') {
  182. console.error(error);
  183. }
  184. }
  185. }, [addToast, error, formatMessage, hasError]);
  186.  
  187. const classes = useStyle(defaultClasses, propClasses);
  188.  
  189. const windowSize = useWindowSize();
  190. const isMobile = windowSize.innerWidth <= 960;
  191.  
  192. const [isExp, setExp] = useState(false);
  193.  
  194. let checkoutContent;
  195.  
  196. const talonInstructionProps = useAccountMenu({});
  197. const { currentUser } = talonInstructionProps;
  198.  
  199. const getInstructions = async () => {
  200. try {
  201. const response = await apiClient.get(apiClient.Urls.getInstructions, {
  202. quoteId: cartId
  203. });
  204. if (response.success) {
  205. setaddedInstructions(response.data.cart_instructions)
  206. }
  207. } catch (error) {
  208. console.log('error', error);
  209. }
  210.  
  211. };
  212.  
  213. const checkoutMeta = () => {
  214. fbq('track', 'InitiateCheckout', {
  215. 'value': total?.value,
  216. 'currency': total.currency
  217. });
  218. }
  219.  
  220. const checkoutGoogle = () => {
  221. gtag('event', 'begin_checkout', {
  222. 'value': total?.value,
  223. 'currency': total.currency
  224. });
  225. }
  226.  
  227. useEffect(() => {
  228. getInstructions();
  229. checkoutMeta();
  230. checkoutGoogle();
  231. }, []);
  232.  
  233. const handleInputChange = (e) => {
  234. setaddedInstructions(e.target.value);
  235. }
  236. const handleInstructions = () => {
  237. setShowInstructions(!showInstructions)
  238. setHideInstructions(true);
  239. }
  240. const getAddInstructions = async () => {
  241. try {
  242. const response = await apiClient.post(apiClient.Urls.addInstructions, {
  243. quoteId: cartId,
  244. instructions: addedInstructions
  245. });
  246. if (response.success) {
  247. setaddedInstructions(response.data.cart_instructions);
  248. setHideInstructions(!hideInstructions);
  249. }
  250. } catch (error) {
  251. console.log('error', error);
  252. }
  253.  
  254. };
  255.  
  256.  
  257.  
  258. const heading = isGuestCheckout
  259. ? formatMessage({
  260. id: 'checkoutPage.guestCheckout',
  261. defaultMessage: 'Guest Checkout'
  262. })
  263. : formatMessage({
  264. id: 'checkoutPage.checkout',
  265. defaultMessage: 'Checkout'
  266. });
  267.  
  268. if (orderNumber && orderDetailsData) {
  269. return (
  270. <OrderConfirmationPage
  271. data={orderDetailsData}
  272. orderNumber={orderNumber}
  273. />
  274. );
  275. } else if (isLoading) {
  276. return fullPageLoadingIndicator;
  277. } else if (isCartEmpty) {
  278. checkoutContent = (
  279. <div className={classes.empty_cart_container}>
  280. <div className={classes.heading_container}>
  281. <h1
  282. aria-live="polite"
  283. className={classes.heading}
  284. data-cy="ChekoutPage-heading"
  285. >
  286. {heading}
  287. </h1>
  288. </div>
  289. <h3>
  290. <FormattedMessage
  291. id={'checkoutPage.emptyMessage'}
  292. defaultMessage={'There are no items in your cart.'}
  293. />
  294. </h3>
  295. </div>
  296. );
  297. } else {
  298. const signInContainerVisible =
  299. isGuestCheckout && checkoutStep !== CHECKOUT_STEP.REVIEW;
  300. const signInContainerElement = signInContainerVisible ? (
  301. <div className={classes.signInContainer}>
  302. <span className={classes.signInLabel}>
  303. <FormattedMessage
  304. id={'checkoutPage.signInLabel'}
  305. defaultMessage={'Sign in for Express Checkout'}
  306. />
  307. </span>
  308. <Button
  309. className={classes.signInButton}
  310. data-cy="CheckoutPage-signInButton"
  311. onClick={toggleSignInContent}
  312. priority="normal"
  313. >
  314. <FormattedMessage
  315. id={'checkoutPage.signInButton'}
  316. defaultMessage={'Sign In'}
  317. />
  318. </Button>
  319. </div>
  320. ) : null;
  321.  
  322. const shippingMethodSection =
  323. checkoutStep >= CHECKOUT_STEP.SHIPPING_METHOD ? (
  324. <ShippingMethod
  325. pageIsUpdating={isUpdating}
  326. onSave={setShippingMethodDone}
  327. onSuccess={scrollShippingMethodIntoView}
  328. setPageIsUpdating={setIsUpdating}
  329. />
  330. ) : (
  331. <h3 className={classes.shipping_method_heading}>
  332. <FormattedMessage
  333. id={'checkoutPage.shippingMethodStep'}
  334. defaultMessage={'2. Shipping Method'}
  335. />
  336. </h3>
  337. );
  338.  
  339. const formErrors = [];
  340. const paymentMethods = Object.keys(payments);
  341.  
  342. // If we have an implementation, or if this is a "zero" checkout,
  343. // we can allow checkout to proceed.
  344. const isPaymentAvailable = !!availablePaymentMethods.find(
  345. ({ code }) => code === 'free' || paymentMethods.includes(code)
  346. );
  347.  
  348. if (!isPaymentAvailable) {
  349. formErrors.push(
  350. new Error(
  351. formatMessage({
  352. id: 'checkoutPage.noPaymentAvailable',
  353. defaultMessage: 'Payment is currently unavailable.'
  354. })
  355. )
  356. );
  357. }
  358.  
  359. const paymentInformationSection =
  360. checkoutStep >= CHECKOUT_STEP.PAYMENT ? (
  361. <PaymentInformation
  362. onSave={setPaymentInformationDone}
  363. checkoutError={error}
  364. resetShouldSubmit={resetReviewOrderButtonClicked}
  365. setCheckoutStep={setCheckoutStep}
  366. shouldSubmit={reviewOrderButtonClicked}
  367. />
  368. ) : (
  369. <h3 className={classes.payment_information_heading}>
  370. <FormattedMessage
  371. id={'checkoutPage.paymentInformationStep'}
  372. defaultMessage={'3. Payment Information'}
  373. />
  374. </h3>
  375. );
  376.  
  377. const priceAdjustmentsSection =
  378. checkoutStep === CHECKOUT_STEP.PAYMENT ? (
  379. <div className={classes.price_adjustments_container}>
  380. <PriceAdjustments setPageIsUpdating={setIsUpdating} />
  381. </div>
  382. ) : null;
  383.  
  384. const reviewOrderButton =
  385. checkoutStep === CHECKOUT_STEP.PAYMENT ? (
  386. <Button
  387. onClick={handleReviewOrder}
  388. priority="high"
  389. className={classes.review_order_button}
  390. data-cy="CheckoutPage-reviewOrderButton"
  391. disabled={
  392. reviewOrderButtonClicked ||
  393. isUpdating ||
  394. !isPaymentAvailable
  395. }
  396. >
  397. <FormattedMessage
  398. id={'checkoutPage.reviewOrder'}
  399. defaultMessage={'Review Order'}
  400. />
  401. </Button>
  402. ) : null;
  403.  
  404. const itemsReview =
  405. checkoutStep === CHECKOUT_STEP.REVIEW ? (
  406. <div className={classes.items_review_container}>
  407. <ItemsReview />
  408. </div>
  409. ) : null;
  410.  
  411. const placeOrderButton =
  412. checkoutStep === CHECKOUT_STEP.REVIEW ? (
  413. <Button
  414. onClick={handlePlaceOrder}
  415. priority="high"
  416. className={classes.place_order_button}
  417. data-cy="CheckoutPage-placeOrderButton"
  418. disabled={
  419. isUpdating ||
  420. placeOrderLoading ||
  421. orderDetailsLoading ||
  422. placeOrderButtonClicked
  423. }
  424. >
  425. <FormattedMessage
  426. id={'checkoutPage.placeOrder'}
  427. defaultMessage={'Place Order'}
  428. />
  429. </Button>
  430. ) : null;
  431.  
  432. // If we're on mobile we should only render price summary in/after review.
  433. const shouldRenderPriceSummary = !(
  434. isMobile && checkoutStep < CHECKOUT_STEP.REVIEW
  435. );
  436.  
  437. const orderSummary = shouldRenderPriceSummary ? (
  438. <div
  439. className={
  440. classes.summaryContainer +
  441. (signInContainerVisible
  442. ? ' ' + classes.signInContainerVisible
  443. : '') +
  444. (recaptchaWidgetProps.shouldRender
  445. ? ' ' + classes.reCaptchaMargin
  446. : '')
  447. }
  448. >
  449. <ItemsReview />
  450. <OrderSummary isUpdating={isUpdating} />
  451. </div>
  452. ) : null;
  453.  
  454. // let headerText;
  455.  
  456. // if (isGuestCheckout) {
  457. // headerText = formatMessage({
  458. // id: 'checkoutPage.guestCheckout',
  459. // defaultMessage: 'Guest Checkout'
  460. // });
  461. // } else if (customer.default_shipping) {
  462. // headerText = formatMessage({
  463. // id: 'checkoutPage.reviewAndPlaceOrder',
  464. // defaultMessage: 'Review and Place Order'
  465. // });
  466. // } else {
  467. // headerText = formatMessage(
  468. // {
  469. // id: 'checkoutPage.greeting',
  470. // defaultMessage: 'Welcome {firstname}!'
  471. // },
  472. // { firstname: customer.firstname }
  473. // );
  474. // }
  475.  
  476. const checkoutContentClass =
  477. activeContent === 'checkout'
  478. ? classes.checkoutContent
  479. : classes.checkoutContent_hidden;
  480.  
  481. const stockStatusMessageElement = (
  482. <Fragment>
  483. <FormattedMessage
  484. id={'checkoutPage.stockStatusMessage'}
  485. defaultMessage={
  486. 'An item in your cart is currently out-of-stock and must be removed in order to Checkout. Please return to your cart to remove the item.'
  487. }
  488. />
  489. <Link className={classes.cartLink} to={'/cart'}>
  490. <FormattedMessage
  491. id={'checkoutPage.returnToCart'}
  492. defaultMessage={'Return to Cart'}
  493. />
  494. </Link>
  495. </Fragment>
  496. );
  497. checkoutContent = (
  498. <div className={checkoutContentClass}>
  499. <div className={classes.heading_container}>
  500. {/* <FormError
  501. classes={{
  502. root: classes.formErrors
  503. }}
  504. errors={formErrors}
  505. /> */}
  506. <StockStatusMessage
  507. cartItems={cartItems}
  508. message={stockStatusMessageElement}
  509. />
  510.  
  511. </div>
  512. {signInContainerElement}
  513. <div className={classes.shipping_information_container}>
  514. <ScrollAnchor ref={shippingInformationRef}>
  515. <ShippingInformation
  516. onSave={setShippingInformationDone}
  517. onSuccess={scrollShippingInformationIntoView}
  518. toggleActiveContent={toggleAddressBookContent}
  519. toggleSignInContent={toggleSignInContent}
  520. setGuestSignInUsername={setGuestSignInUsername}
  521. cartItems={cartItems}
  522. cart={cart}
  523. isCalledRef={isCalledRef}
  524. />
  525. </ScrollAnchor>
  526. </div>
  527. <div className={classes.shipping_method_container}>
  528. <ScrollAnchor ref={shippingMethodRef}>
  529. {shippingMethodSection}
  530. </ScrollAnchor>
  531. </div>
  532. <div className={classes.payment_information_container}>
  533. {paymentInformationSection}
  534. </div>
  535. {priceAdjustmentsSection}
  536. {reviewOrderButton}
  537. {itemsReview}
  538. {orderSummary}
  539. {placeOrderButton}
  540. <GoogleReCaptcha {...recaptchaWidgetProps} />
  541. </div>
  542. );
  543. }
  544. const addressBookElement = !isGuestCheckout || isGuestCheckout ?
  545. <AddressBook
  546. activeContent={activeContent}
  547. toggleActiveContent={toggleAddressBookContent}
  548. onSuccess={scrollShippingInformationIntoView}
  549. onSave={setShippingInformationDone}
  550. /> : null;
  551.  
  552.  
  553. const signInElement = isGuestCheckout ? (
  554. <GuestSignIn
  555. key={guestSignInUsername}
  556. isActive={activeContent === 'signIn'}
  557. toggleActiveContent={toggleSignInContent}
  558. initialValues={{ email: guestSignInUsername }}
  559. />
  560. ) : null;
  561.  
  562.  
  563.  
  564.  
  565. const StepTitle = ({ title }) => {
  566. return (
  567. <h1 className='text-[#181A1D] text-[18px] font-lato'>{title}</h1>
  568. )
  569. }
  570.  
  571. const login = (
  572. <div className='border-[#F5E7EE] border-2 border-solid bg-[#fff] rounded-xl px-[20px] relative py-[16px]'>
  573. <StepTitle title={'1. Login'} />
  574. <Auth setGuestCheckout={setGuestCheckout} setShowGiftOptions={setShowGiftOptions} isGuestCheckout={isGuestCheckout}/>
  575. </div>
  576. );
  577.  
  578. const giftoptions = (
  579. <GiftOptions customer={customer} showInstructions={showInstructions} setShowInstructions={setShowInstructions} cartId={cartId} showGiftOptions={showGiftOptions}/>
  580. );
  581.  
  582. const orderDetailsForMobile = (
  583. <div className='border-[#F5E7EE] border-2 border-solid bg-[#fff] rounded-xl py-[16px] mt-[20px]'>
  584. <div className='flex flex-row justify-between cursor-pointer px-[20px]' onClick={() => setExp(!isExp)}>
  585. <h1 className='text-[#181A1D] text-[18px] font-lato'>{'4. Order details'}</h1>
  586. <img src={downarrow} />
  587. </div>
  588. {isExp ?
  589. <div className='w-1/3 checkout_page_sub page_checkout'>
  590. <ItemsReview />
  591. <OrderSummary isUpdating={isUpdating} />
  592. </div> :
  593. <div className='flex flex-row justify-between pt-[15px] px-[20px]'>
  594. <span className='leading-4'>Order Total</span>
  595. {/* <span className='leading-4 font-bold'>{total}</span> */}
  596. </div>}
  597. </div>
  598. )
  599. const addingInstructions = (
  600. <div className='border-[#F5E7EE] border-2 border-solid bg-[#fff] rounded-xl px-[20px] py-[16px] mt-[20px]'>
  601. <label for='instructions' class="flex flex-row justify-between cursor-pointer"
  602. onClick={handleInstructions}><h1 class="text-[#181A1D] text-[18px] font-lato">3. Add Instructions</h1>
  603. {
  604. currentUser && currentUser.firstname || showGiftOptions ? <img src={downarrow} /> : null
  605. }
  606. </label>
  607.  
  608. {showInstructions && <>
  609. {
  610. currentUser && currentUser.firstname || currentUser?.firstname == "" ? <>{
  611. hideInstructions ? <div className='mt-3'><textarea id='instructions' name='instructions' class="w-full p-[15px] border-[#F5E7EE] border-[1px] border-solid rounded-[4px] login_field mt-4 mb-2" placeholder='Enter Instructions' onChange={handleInputChange} value={addedInstructions}></textarea>
  612. <button className="bg-[#181A1D] w-1/2 py-[12px] text-[#fff] rounded-[4px] text-[12px] tracking-[2.4px] uppercase add_instructions" onClick={getAddInstructions}>Add Instructions</button></div> :
  613. <div className='flex justify-between items-center ml-[1rem] mt-2'>
  614. <span>Instructions : <span className='text-[#848482]'>{addedInstructions ? addedInstructions : null}</span></span>
  615. {/* <button className="bg-[#181A1D] w-[100px] py-[12px] text-[#fff] rounded-[4px] text-[12px] tracking-[2.4px] uppercase" onClick={editInstructions}>Edit</button> */}
  616. </div>
  617. } </> : null
  618. }
  619.  
  620. </>}
  621.  
  622. </div>
  623. );
  624.  
  625. const shippingAddress = (
  626. <div className='border-[#F5E7EE] border-2 border-solid bg-[#fff] rounded-xl px-[20px] py-[16px] mt-[20px] relative'>
  627. <StepTitle title={'4. Shipping Address'} />
  628. {isSignedIn ?
  629. <ShippingInformation
  630. onSave={setShippingInformationDone}
  631. onSuccess={scrollShippingInformationIntoView}
  632. toggleActiveContent={toggleAddressBookContent}
  633. toggleSignInContent={toggleSignInContent}
  634. setGuestSignInUsername={setGuestSignInUsername}
  635. cartItems={cartItems}
  636. isCalledRef={isCalledRef}
  637. /> : null}
  638. <div className='hidden'>
  639. <ShippingMethod
  640. pageIsUpdating={isUpdating}
  641. onSave={setShippingMethodDone}
  642. onSuccess={scrollShippingMethodIntoView}
  643. setPageIsUpdating={setIsUpdating}
  644. />
  645. </div>
  646. {isSignedIn ? addressBookElement : null}
  647. </div>
  648. )
  649.  
  650.  
  651. const paymentMethodList = (
  652. <div className='border-[#F5E7EE] border-2 border-solid bg-[#fff] rounded-xl px-[20px] py-[16px] mt-[20px]'>
  653. <StepTitle title={'5. Payment method'} />
  654. {customer && checkoutStep == 3 ?
  655. <Payment /> : null}
  656. </div>
  657. );
  658.  
  659. // Guest checkout
  660.  
  661. const ShippingAddress = (
  662. <div className='border-[#F5E7EE] border-2 border-solid bg-[#fff] rounded-xl px-[20px] py-[16px] mt-[20px] relative'>
  663. <StepTitle title={'1. Shipping Address'} />
  664. {isGuestCheckout ?
  665. <ShippingInformation
  666. onSave={setShippingInformationDone}
  667. onSuccess={scrollShippingInformationIntoView}
  668. toggleActiveContent={toggleAddressBookContent}
  669. toggleSignInContent={toggleSignInContent}
  670. setGuestSignInUsername={setGuestSignInUsername}
  671. cartId={cartId}
  672. setShowGiftOptions={setShowGiftOptions}
  673. cartItems={cartItems}
  674. cart={cart}
  675. isCalledRef={isCalledRef}
  676. /> : null}
  677. <div className='hidden'>
  678. <ShippingMethod
  679. pageIsUpdating={isUpdating}
  680. onSave={setShippingMethodDone}
  681. onSuccess={scrollShippingMethodIntoView}
  682. setPageIsUpdating={setIsUpdating}
  683. isGuestCheckout={isGuestCheckout}
  684. setShowGiftOptions={setShowGiftOptions}
  685. showGiftOptions={showGiftOptions}
  686. />
  687. </div>
  688. {isGuestCheckout ? addressBookElement : null}
  689. </div>
  690. )
  691.  
  692. const paymentInformation = (
  693. <div className='border-[#F5E7EE] border-2 border-solid bg-[#fff] rounded-xl px-[20px] relative py-[16px] mt-[20px]'>
  694. <StepTitle title={'4. Payment Information'} />
  695. {isGuestCheckout && setShippingInformationDone && checkoutStep && checkoutStep == 3 ?
  696. <Payment shippingInfo={shippingInfo} isGuestCheckout={isGuestCheckout}/> : null}
  697. </div>
  698. )
  699.  
  700. if (isSignedIn && isCartEmpty) {
  701. return fullPageLoadingIndicator;
  702. }
  703.  
  704. if (isCartEmpty) {
  705. return (
  706. <div className={classes.empty_cart_container}>
  707. <div class="pl-[15px]">
  708. <h1 class="text-[24px] text-[#774E4F] mb-[10px]" style={{ fontFamily: 'ivymode, sans-serif', fontWeight: 500 }}>Checkout</h1>
  709. </div>
  710. <h3 class="pl-[15px]">
  711. <FormattedMessage
  712. id={'checkoutPage.emptyMessage'}
  713. defaultMessage={'There are no items in your cart.'}
  714. />
  715. </h3>
  716. </div>
  717. );
  718. }
  719.  
  720.  
  721. return (
  722. <div data-cy="CheckoutPage-root" className='p-[1rem] checkout_page_root'>
  723. <StoreTitle>
  724. {formatMessage({
  725. id: 'checkoutPage.titleCheckout',
  726. defaultMessage: 'Checkout'
  727. })}
  728. </StoreTitle>
  729. {
  730. guestCheckout ? (
  731. <div className='flex flex-row checkout_page_main'>
  732. <div className='w-2/3 pr-[20px] checkout_page_sub'>
  733. <main className='border-[#EFE6DB] border-b-2 flex justify-between items-center pb-[10px]'>
  734. <div>
  735. <h1 className='text-[24px] text-[#181A1D]' style={{
  736. fontFamily: 'ivymode, sans-serif',
  737. fontWeight: 500,
  738. }}>Guest Checkout</h1>
  739. </div>
  740. <div>
  741. <Button
  742. className={"font-lato text-[12px] text-[#fff] bg-[#181A1D] py-[10px] px-[2rem] tracking-[2.4px] uppercase mr-4 rounded search_button"}
  743. data-cy="CheckoutPage-signInButton"
  744. onClick={handleSignIn}
  745. priority="normal"
  746. >
  747. <FormattedMessage
  748. id={'checkoutPage.signInButton'}
  749. defaultMessage={'Sign In'}
  750. />
  751. </Button>
  752. </div>
  753. </main>
  754. <div className='bg-[#FCFAFB] rounded-xl p-[14px] mt-[10px] secure-checkout'>
  755. {ShippingAddress}
  756. {giftoptions}
  757. {addingInstructions}
  758. {paymentInformation}
  759. </div>
  760.  
  761. </div>
  762. {isMobile ? null :
  763. <div className='w-1/3 checkout_page_sub page_checkout'>
  764. <ItemsReview />
  765. <OrderSummary isUpdating={isUpdating} />
  766. </div>}
  767. </div>
  768. ) :
  769. <>
  770. {
  771. signIn || isSignedIn ? (
  772. <div className='flex flex-row checkout_page_main'>
  773. <div className='w-2/3 pr-[20px] checkout_page_sub'>
  774. <div className='border-[#EFE6DB] border-b-2'>
  775. <h1 className='text-[24px] text-[#181A1D] mb-[10px]' style={{
  776. fontFamily: 'ivymode, sans-serif',
  777. fontWeight: 500,
  778. }}>Secure checkout</h1>
  779. </div>
  780. <div className='bg-[#FCFAFB] rounded-xl p-[14px] mt-[10px] secure-checkout'>
  781. {login}
  782. {giftoptions}
  783. {addingInstructions}
  784. {shippingAddress}
  785. {isMobile ? orderDetailsForMobile : null}
  786. {paymentMethodList}
  787. </div>
  788.  
  789. </div>
  790. {isMobile ? null :
  791. <div className='w-1/3 checkout_page_sub page_checkout'>
  792. <ItemsReview />
  793. <OrderSummary isUpdating={isUpdating} />
  794. </div>}
  795. </div>
  796. ) : null
  797. }
  798. </>
  799. }
  800.  
  801. </div>
  802. );
  803. };
  804.  
  805. export default CheckoutPage;
  806.  
  807. CheckoutPage.propTypes = {
  808. classes: shape({
  809. root: string,
  810. checkoutContent: string,
  811. checkoutContent_hidden: string,
  812. heading_container: string,
  813. heading: string,
  814. cartLink: string,
  815. stepper_heading: string,
  816. shipping_method_heading: string,
  817. payment_information_heading: string,
  818. signInContainer: string,
  819. signInLabel: string,
  820. signInButton: string,
  821. empty_cart_container: string,
  822. shipping_information_container: string,
  823. shipping_method_container: string,
  824. payment_information_container: string,
  825. price_adjustments_container: string,
  826. items_review_container: string,
  827. summaryContainer: string,
  828. formErrors: string,
  829. review_order_button: string,
  830. place_order_button: string,
  831. signInContainerVisible: string,
  832. reCaptchaMargin: string
  833. })
  834. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement