Skip to content

Commit

Permalink
filter disabled options
Browse files Browse the repository at this point in the history
  • Loading branch information
jhesgodi committed May 21, 2024
1 parent dd7db55 commit e395887
Showing 1 changed file with 15 additions and 8 deletions.
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 e395887

Please sign in to comment.