diff --git a/packages/app-elements/src/ui/resources/ResourcePaymentMethod.test.tsx b/packages/app-elements/src/ui/resources/ResourcePaymentMethod.test.tsx index 373d655a..3d734e4e 100644 --- a/packages/app-elements/src/ui/resources/ResourcePaymentMethod.test.tsx +++ b/packages/app-elements/src/ui/resources/ResourcePaymentMethod.test.tsx @@ -13,7 +13,7 @@ describe('ResourcePaymentMethod', () => { expect(getByText('Adyen Payment')).toBeVisible() }) - it('should show the expandable show more button', async () => { + it('should not show expandable content if payment_source is available but `showPaymentResponse` is falsy', async () => { const { getByText, queryByText } = render( ) @@ -21,6 +21,22 @@ describe('ResourcePaymentMethod', () => { expect(getByText('Amex credit card')).toBeVisible() expect(getByText('··4242')).toBeVisible() + // expandable content is not enabled + expect(queryByText('Show more')).not.toBeInTheDocument() + expect(queryByText('Show less')).not.toBeInTheDocument() + }) + + it('should show the expandable content (payment_source) when `showPaymentResponse` is set', async () => { + const { getByText, queryByText } = render( + + ) + expect(getByText('Adyen Payment')).toBeVisible() + expect(getByText('Amex credit card')).toBeVisible() + expect(getByText('··4242')).toBeVisible() + // expandable content is enabled expect(getByText('Show more')).toBeVisible() diff --git a/packages/app-elements/src/ui/resources/ResourcePaymentMethod.tsx b/packages/app-elements/src/ui/resources/ResourcePaymentMethod.tsx index 15e8b761..ea9e659e 100644 --- a/packages/app-elements/src/ui/resources/ResourcePaymentMethod.tsx +++ b/packages/app-elements/src/ui/resources/ResourcePaymentMethod.tsx @@ -6,6 +6,7 @@ import { type Order, type PaymentMethod } from '@commercelayer/sdk' +import cn from 'classnames' import { useState, type FC } from 'react' import type { SetNonNullable, SetRequired } from 'type-fest' import { z } from 'zod' @@ -24,13 +25,23 @@ export interface ResourcePaymentMethodProps { SetNonNullable, 'payment_source' > + /** + * When true and if `payment_source.payment_response` is present, enables the expandable content to show more details on the transaction. + */ + showPaymentResponse?: boolean + /** + * Defines the style of the component. Default is `boxed`, with a light gray background and rounded corners. + */ + variant?: 'plain' | 'boxed' } /** * Show info about the payment method from the given Order or CustomerPaymentSource. */ export const ResourcePaymentMethod: FC = ({ - resource + resource, + showPaymentResponse = false, + variant = 'boxed' }) => { const [showMore, setShowMore] = useState(false) const paymentInstrument = paymentInstrumentType.safeParse( @@ -60,7 +71,11 @@ export const ResourcePaymentMethod: FC = ({ } return ( -
+
{paymentMethodName}
@@ -89,7 +104,7 @@ export const ResourcePaymentMethod: FC = ({ {paymentMethodName} )} - {paymentResponse != null && ( + {paymentResponse != null && showPaymentResponse && ( @@ -104,7 +120,7 @@ export const ResourcePaymentMethod: FC = ({
- {showMore && paymentResponse != null ? ( + {showMore && paymentResponse != null && showPaymentResponse ? (