baby_in_magento

bg

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