Skip to content

Commit

Permalink
refactor: resolve conflicts
Browse files Browse the repository at this point in the history
  • Loading branch information
longyulongyu committed Nov 7, 2023
1 parent b811bcc commit 7cf54e0
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 55 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ test('should call onSelect if openFirstStoredPaymentMethod is set and there is n
isLoading={false}
onSelect={onSelectMock}
openFirstStoredPaymentMethod={true}
paymentMethods={[]}
/>
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,49 @@ import PaymentMethodsContainer, { PaymentMethodsContainerProps } from './Payment
import { useEffect } from 'preact/hooks';

interface PaymentMethodListProps extends Omit<PaymentMethodsContainerProps, 'label' | 'classNameModifiers'> {
instantPaymentMethods?: UIElement[];
storedPaymentMethods?: UIElement[];
openFirstStoredPaymentMethod?: boolean;
openFirstPaymentMethod?: boolean;
order?: Order;
orderStatus?: OrderStatus;
onOrderCancel?: (order) => void;
instantPaymentMethods?: UIElement[];
storedPaymentMethods?: UIElement[];
openFirstStoredPaymentMethod?: boolean;
openFirstPaymentMethod?: boolean;
order?: Order;
orderStatus?: OrderStatus;
onOrderCancel?: (order) => void;
}

const PaymentMethodList = ({
paymentMethods = [],
instantPaymentMethods = [],
storedPaymentMethods=[],
paymentMethods = [], // Non-stored payments
instantPaymentMethods = [],
storedPaymentMethods = [],
openFirstStoredPaymentMethod,
openFirstPaymentMethod,
showRemovePaymentMethodButton,
orderStatus = null,
order,
orderStatus = null,
onOrderCancel,
onSelect = () => {},
...rest
}: PaymentMethodListProps) => {
const { i18n } = useCoreContext();
const brandLogoConfiguration = useBrandLogoConfiguration(paymentMethods);
const hasInstantPaymentMethods = instantPaymentMethods.length > 0;
const hasStoredPaymentMethods = storedPaymentMethods.length > 0;
const pmListLabel = hasInstantPaymentMethods || hasStoredPaymentMethods ? i18n.get('paymentMethodsList.otherPayments.label') : '';

const hasInstantPaymentMethods = instantPaymentMethods.length > 0;
const hasStoredPaymentMethods = storedPaymentMethods.length > 0;
const pmListLabel = hasInstantPaymentMethods || hasStoredPaymentMethods ? i18n.get('paymentMethodsList.otherPayments.label') : '';

useEffect(() => {
useEffect(() => {
// Open first PaymentMethodItem
const firstStoredPayment = storedPaymentMethods[0];
const firstNonStoredPayment = paymentMethods[0];
const firstStoredPayment = storedPaymentMethods[0];
const firstNonStoredPayment = paymentMethods[0];

if (firstStoredPayment || firstNonStoredPayment) {
const shouldOpenFirstStored = openFirstStoredPaymentMethod && getProp(firstStoredPayment, 'props.oneClick') === true;
if (shouldOpenFirstStored) {
onSelect(firstStoredPayment);
return;
}
if (firstStoredPayment || firstNonStoredPayment) {
const shouldOpenFirstStored = openFirstStoredPaymentMethod && getProp(firstStoredPayment, 'props.oneClick') === true;
if (shouldOpenFirstStored) {
onSelect(firstStoredPayment);
return;
}

if (openFirstPaymentMethod) {
onSelect(firstNonStoredPayment);
if (openFirstPaymentMethod) {
onSelect(firstNonStoredPayment);
}
}
}

}, []);

return (
Expand All @@ -71,25 +68,27 @@ const PaymentMethodList = ({

{hasInstantPaymentMethods && <InstantPaymentMethods paymentMethods={instantPaymentMethods} />}

{hasStoredPaymentMethods && (
<PaymentMethodsContainer
{...rest}
label={i18n.get('paymentMethodsList.storedPayments.label')}
classNameModifiers={['storedPayments']}
paymentMethods={storedPaymentMethods}
></PaymentMethodsContainer>
)}
{hasStoredPaymentMethods && (
<PaymentMethodsContainer
{...rest}
label={i18n.get('paymentMethodsList.storedPayments.label')}
classNameModifiers={['storedPayments']}
paymentMethods={storedPaymentMethods}
onSelect={onSelect}
></PaymentMethodsContainer>
)}

{!!paymentMethods.length && (
<PaymentMethodsContainer
{...rest}
label={pmListLabel}
classNameModifiers={['otherPayments']}
paymentMethods={paymentMethods}
></PaymentMethodsContainer>
)}
</Fragment>
);
{!!paymentMethods.length && (
<PaymentMethodsContainer
{...rest}
label={pmListLabel}
classNameModifiers={['otherPayments']}
paymentMethods={paymentMethods}
onSelect={onSelect}
></PaymentMethodsContainer>
)}
</Fragment>
);
};

export default PaymentMethodList;
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,14 @@ export interface PaymentMethodsContainerProps {
function PaymentMethodsContainer({
label,
classNameModifiers = [],
paymentMethods,
activePaymentMethod,
cachedPaymentMethods,
paymentMethods = [],
activePaymentMethod = null,
cachedPaymentMethods = {},
isLoading = false,
isDisablingPaymentMethod = false,
showRemovePaymentMethodButton,
onSelect,
onDisableStoredPaymentMethod,
isDisablingPaymentMethod,
isLoading
onDisableStoredPaymentMethod = () => {},
onSelect
}: PaymentMethodsContainerProps) {
const { i18n } = useCoreContext();
const selectListId: string = useMemo(() => `select-${uuid()}`, []);
Expand Down
2 changes: 1 addition & 1 deletion packages/lib/src/components/Trustly/Trustly.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { h } from 'preact';
import CoreProvider from '../../core/Context/CoreProvider';
import RedirectElement from '../Redirect';
import RedirectButton from '../internal/RedirectButton';
import {TxVariants} from "../tx-variants";
import { TxVariants } from '../tx-variants';
import './Trustly.scss';

class TrustlyElement extends RedirectElement {
Expand Down
1 change: 1 addition & 0 deletions packages/lib/src/language/locales/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"state": "State",
"field.title.optional": "(optional)",
"issuerList.selectField.contextualText": "Select your bank to continue",
"issuerList.selectField.label": "Bank selection",
"privacyPolicy": "Privacy policy",
"afterPay.agreement": "I agree with the %@ of AfterPay",
"paymentConditions": "payment conditions",
Expand Down

0 comments on commit 7cf54e0

Please sign in to comment.