Skip to content

Commit

Permalink
fix: [Sale WIdget] Do not render more options section when all opti…
Browse files Browse the repository at this point in the history
…ons are disabled (#1813)
  • Loading branch information
jhesgodi committed May 22, 2024
1 parent 14f3c4a commit 6d25d98
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ export function CoinsDrawer({
size = 'small';
}

const otherPaymentOptions = [SalePaymentTypes.DEBIT, SalePaymentTypes.CREDIT];
const withOtherOptions = !otherPaymentOptions.every((type) => disabledPaymentTypes?.includes(type));

return (
<Drawer
size="full"
Expand Down Expand Up @@ -124,8 +127,7 @@ export function CoinsDrawer({
/>
)}
>
{(disabledPaymentTypes?.includes(SalePaymentTypes.CREDIT)
&& disabledPaymentTypes?.includes(SalePaymentTypes.DEBIT)) ?? (
{withOtherOptions && (
<Divider
size="small"
rc={<Caption />}
Expand All @@ -137,10 +139,9 @@ export function CoinsDrawer({
<PaymentOptions
onClick={onPayWithCard}
size={size}
paymentOptions={[
SalePaymentTypes.DEBIT,
SalePaymentTypes.CREDIT,
].filter((type) => !disabledPaymentTypes?.includes(type))}
hideDisabledOptions
paymentOptions={otherPaymentOptions}
disabledOptions={disabledPaymentTypes}
captions={{
[SalePaymentTypes.DEBIT]: t(
'views.PAYMENT_METHODS.options.debit.caption',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Box, MenuItemSize } from '@biom3/react';
import { SalePaymentTypes } from '@imtbl/checkout-sdk';
import { listItemVariants, listVariants } from 'lib/animation/listAnimation';
import { motion } from 'framer-motion';
import { useMemo } from 'react';
import { PaymentOption } from './PaymentOption';

const defaultPaymentOptions: SalePaymentTypes[] = [
Expand All @@ -17,13 +18,24 @@ export interface PaymentOptionsProps {
paymentOptions?: SalePaymentTypes[];
captions?: Partial<Record<SalePaymentTypes, string>>;
size?: MenuItemSize;
hideDisabledOptions?: boolean;
}

export function PaymentOptions(props: PaymentOptionsProps) {
const {
disabledOptions = [], paymentOptions, onClick, captions, size,
disabledOptions = [],
paymentOptions,
onClick,
captions,
size,
hideDisabledOptions,
} = props;
const options = paymentOptions || defaultPaymentOptions;
const options = useMemo(
() => (paymentOptions || defaultPaymentOptions).filter(
(option) => !hideDisabledOptions || !disabledOptions.includes(option),
),
[paymentOptions, disabledOptions, hideDisabledOptions],
);

return (
<Box
Expand All @@ -47,12 +59,7 @@ export function PaymentOptions(props: PaymentOptionsProps) {
onClick={onClick}
disabled={disabledOptions.includes(type)}
caption={captions?.[type]}
rc={(
<motion.div
custom={idx}
variants={listItemVariants}
/>
)}
rc={<motion.div custom={idx} variants={listItemVariants} />}
/>
))}
</Box>
Expand Down

0 comments on commit 6d25d98

Please sign in to comment.