-
Notifications
You must be signed in to change notification settings - Fork 201
@W-19751635 SPM UX changes in checkout #3365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
0aa0b28
9a3763c
e23fb53
2833d67
c84358e
ad80503
02df580
6085d68
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,7 +5,7 @@ | |
| * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause | ||
| */ | ||
| import React, {useState} from 'react' | ||
| import {FormattedMessage, FormattedNumber, useIntl} from 'react-intl' | ||
| import {FormattedMessage, useIntl} from 'react-intl' | ||
| import PropTypes from 'prop-types' | ||
| import { | ||
| Box, | ||
|
|
@@ -17,13 +17,11 @@ import { | |
| Text, | ||
| Tooltip | ||
| } from '@salesforce/retail-react-app/app/components/shared/ui' | ||
| import {useCurrentBasket} from '@salesforce/retail-react-app/app/hooks/use-current-basket' | ||
| import {LockIcon, PaypalIcon} from '@salesforce/retail-react-app/app/components/icons' | ||
| import CreditCardFields from '@salesforce/retail-react-app/app/components/forms/credit-card-fields' | ||
| import {useCurrency} from '@salesforce/retail-react-app/app/hooks' | ||
| import {getCreditCardIcon} from '@salesforce/retail-react-app/app/utils/cc-utils' | ||
|
|
||
| const INITIAL_DISPLAYED_SAVED_PAYMENT_INSTRUMENTS = 1 | ||
| const INITIAL_DISPLAYED_SAVED_PAYMENT_INSTRUMENTS = 3 | ||
|
|
||
| const PaymentCardSummary = ({payment}) => { | ||
| const CardIcon = getCreditCardIcon(payment?.paymentCard?.cardType) | ||
|
|
@@ -54,20 +52,22 @@ const PaymentForm = ({ | |
| selectedPaymentMethod | ||
| }) => { | ||
| const {formatMessage} = useIntl() | ||
| const {data: basket} = useCurrentBasket() | ||
| const {currency} = useCurrency() | ||
| const [showAllPaymentInstruments, setShowAllPaymentInstruments] = useState(false) | ||
|
|
||
| const hasSavedPaymentInstruments = savedPaymentInstruments?.length > 0 | ||
| const savedCount = savedPaymentInstruments?.length || 0 | ||
| const totalItems = savedCount + 2 // saved + credit card + paypal | ||
| const n = showAllPaymentInstruments ? totalItems : INITIAL_DISPLAYED_SAVED_PAYMENT_INSTRUMENTS | ||
|
||
|
|
||
| const displayedSavedCount = Math.min(savedCount, n) | ||
|
||
| const displayedSavedPaymentInstruments = | ||
| savedPaymentInstruments?.slice( | ||
| 0, | ||
| showAllPaymentInstruments | ||
| ? savedPaymentInstruments.length | ||
| : INITIAL_DISPLAYED_SAVED_PAYMENT_INSTRUMENTS | ||
| ) || [] | ||
| const isDisplayingAllPaymentInstruments = | ||
| displayedSavedPaymentInstruments?.length === (savedPaymentInstruments?.length || 0) | ||
| savedPaymentInstruments?.slice(0, displayedSavedCount) || [] | ||
|
|
||
| const showCreditCard = n > displayedSavedCount | ||
sf-mkosak marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const displayedAfterCC = displayedSavedCount + (showCreditCard ? 1 : 0) | ||
| const showPaypal = n > displayedAfterCC | ||
|
|
||
| const showViewAllButton = | ||
| totalItems > INITIAL_DISPLAYED_SAVED_PAYMENT_INSTRUMENTS && !showAllPaymentInstruments | ||
|
|
||
| return ( | ||
| <form onSubmit={form.handleSubmit(onSubmit)}> | ||
|
|
@@ -101,78 +101,79 @@ const PaymentForm = ({ | |
| </Box> | ||
| ))} | ||
|
|
||
| <Box | ||
| py={3} | ||
| px={[4, 4, 6]} | ||
| bg="gray.50" | ||
| borderBottom="1px solid" | ||
| borderColor="gray.100" | ||
| > | ||
| <Radio value="cc"> | ||
| <Flex justify="space-between"> | ||
| <Stack direction="row" align="center"> | ||
| <Text fontWeight="bold"> | ||
| <FormattedMessage | ||
| defaultMessage="Credit Card" | ||
| id="payment_selection.heading.credit_card" | ||
| /> | ||
| </Text> | ||
| <Tooltip | ||
| hasArrow | ||
| placement="top" | ||
| label={formatMessage({ | ||
| defaultMessage: | ||
| 'This is a secure SSL encrypted payment.', | ||
| id: 'payment_selection.tooltip.secure_payment' | ||
| })} | ||
| > | ||
| <LockIcon color="gray.700" boxSize={5} /> | ||
| </Tooltip> | ||
| </Stack> | ||
| <Text fontWeight="bold"> | ||
| <FormattedNumber | ||
| value={basket?.orderTotal} | ||
| style="currency" | ||
| currency={currency} | ||
| /> | ||
| </Text> | ||
| </Flex> | ||
| </Radio> | ||
| </Box> | ||
| <Collapse in={selectedPaymentMethod === 'cc'} animateOpacity> | ||
| <Box p={[4, 4, 6]} borderBottom="1px solid" borderColor="gray.100"> | ||
| <Stack spacing={6}> | ||
| <Stack spacing={6}> | ||
| <CreditCardFields form={form} /> | ||
| </Stack> | ||
| {children && <Box pt={2}>{children}</Box>} | ||
| </Stack> | ||
| </Box> | ||
| </Collapse> | ||
|
|
||
| <Box py={3} px={[4, 4, 6]} bg="gray.50" borderColor="gray.100"> | ||
| <Radio value="paypal"> | ||
| <Box py="2px"> | ||
| <PaypalIcon width="auto" height="20px" /> | ||
| {showCreditCard && ( | ||
| <> | ||
| <Box | ||
| py={3} | ||
| px={[4, 4, 6]} | ||
| bg="gray.50" | ||
| borderBottom="1px solid" | ||
| borderColor="gray.100" | ||
| > | ||
| <Radio value="cc"> | ||
| <Flex justify="space-between"> | ||
| <Stack direction="row" align="center"> | ||
| <Text fontWeight="bold"> | ||
| <FormattedMessage | ||
| defaultMessage="Credit Card" | ||
| id="payment_selection.heading.credit_card" | ||
| /> | ||
| </Text> | ||
| <Tooltip | ||
| hasArrow | ||
| placement="top" | ||
| label={formatMessage({ | ||
| defaultMessage: | ||
| 'This is a secure SSL encrypted payment.', | ||
| id: 'payment_selection.tooltip.secure_payment' | ||
| })} | ||
| > | ||
| <LockIcon color="gray.700" boxSize={5} /> | ||
| </Tooltip> | ||
| </Stack> | ||
| </Flex> | ||
| </Radio> | ||
| </Box> | ||
| </Radio> | ||
| </Box> | ||
| <Collapse in={selectedPaymentMethod === 'cc'} animateOpacity> | ||
| <Box | ||
| p={[4, 4, 6]} | ||
| borderBottom="1px solid" | ||
| borderColor="gray.100" | ||
| > | ||
| <Stack spacing={6}> | ||
| <Stack spacing={6}> | ||
| <CreditCardFields form={form} /> | ||
| </Stack> | ||
| {children && <Box pt={2}>{children}</Box>} | ||
| </Stack> | ||
| </Box> | ||
| </Collapse> | ||
| </> | ||
| )} | ||
|
|
||
| {showPaypal && ( | ||
| <Box py={3} px={[4, 4, 6]} bg="gray.50" borderColor="gray.100"> | ||
| <Radio value="paypal"> | ||
| <Box py="2px"> | ||
| <PaypalIcon width="auto" height="20px" /> | ||
| </Box> | ||
| </Radio> | ||
| </Box> | ||
| )} | ||
| </RadioGroup> | ||
| </Box> | ||
| {!isDisplayingAllPaymentInstruments && hasSavedPaymentInstruments && ( | ||
| {showViewAllButton && savedCount > 0 && ( | ||
| <Box py={3} px={[4, 4, 6]}> | ||
| <button | ||
| onClick={() => | ||
| setShowAllPaymentInstruments(!showAllPaymentInstruments) | ||
| } | ||
| type="button" | ||
| data-testid="view-all-saved-payments" | ||
| onClick={() => setShowAllPaymentInstruments(true)} | ||
| > | ||
| <FormattedMessage | ||
| defaultMessage="View All ({count} more)" | ||
| id="payment_selection.button.view_all" | ||
| values={{ | ||
| count: | ||
| savedPaymentInstruments?.length - | ||
| INITIAL_DISPLAYED_SAVED_PAYMENT_INSTRUMENTS | ||
| count: Math.max(totalItems - n, 0) | ||
| }} | ||
| /> | ||
| </button> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.