Skip to content

Commit

Permalink
feat(payment): STRIPE-444 New Stripe UPE (Spike)
Browse files Browse the repository at this point in the history
  • Loading branch information
PavlenkoM committed Sep 18, 2024
1 parent 868cb3d commit 1af8268
Show file tree
Hide file tree
Showing 15 changed files with 256 additions and 170 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ const PaymentMethodListItem: FunctionComponent<PaymentMethodListItemProps> = ({
<ChecklistItem
content={renderPaymentMethod}
htmlId={`radio-${value}`}
isCustomItem={method.initializationData?.accordion} // TODO: accordion key will be changed to more relevant after changes on BCapp side
isDisabled={isDisabled}
label={renderPaymentMethodTitle}
value={value}
Expand Down
98 changes: 0 additions & 98 deletions packages/core/src/app/ui/accordion/Accordion.spec.tsx

This file was deleted.

68 changes: 0 additions & 68 deletions packages/core/src/app/ui/accordion/AccordionItem.tsx

This file was deleted.

3 changes: 2 additions & 1 deletion packages/core/src/app/ui/form/Checklist.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import React, {
useMemo,
} from 'react';

import { Accordion } from '@bigcommerce/checkout/ui';

import { connectFormik, ConnectFormikProps } from '../../common/form';
import { Accordion } from '../accordion';

export interface ChecklistProps {
children: ReactNode;
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/app/ui/form/ChecklistItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { FieldProps } from 'formik';
import { kebabCase } from 'lodash';
import React, { FunctionComponent, memo, ReactNode, useCallback, useContext } from 'react';

import { AccordionItem, AccordionItemHeaderProps } from '../accordion';
import { AccordionItem, AccordionItemHeaderProps } from '@bigcommerce/checkout/ui';

import BasicFormField from './BasicFormField';
import { ChecklistContext } from './Checklist';
Expand All @@ -12,12 +12,14 @@ import ChecklistItemInput from './ChecklistItemInput';
export interface ChecklistItemProps {
content?: ReactNode;
htmlId?: string;
isCustomItem?: boolean;
isDisabled?: boolean;
label: ReactNode | ((isSelected: boolean) => ReactNode);
value: string;
}

const ChecklistItem: FunctionComponent<ChecklistItemProps> = ({
isCustomItem,
isDisabled,
value,
content,
Expand Down Expand Up @@ -72,6 +74,7 @@ const ChecklistItem: FunctionComponent<ChecklistItemProps> = ({
headerClassName="form-checklist-header"
headerClassNameSelected="form-checklist-header--selected"
headerContent={renderHeaderContent}
isCustomItem={isCustomItem}
itemId={value}
>
{content}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,3 +212,13 @@
will-change: $loading-skeleton-will-change;
}
}

.accordion-item-body-full-size {
margin: 0;
overflow: hidden;

.paymentMethod--hosted,
.widget {
padding: 0;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { PaymentInitializeOptions } from '@bigcommerce/checkout-sdk';
import { noop, some } from 'lodash';
import React, { FunctionComponent, useCallback, useMemo } from 'react';
import React, {
FunctionComponent,
useCallback,
useContext,
useEffect,
useMemo,
useRef,
} from 'react';

import { getAppliedStyles } from '@bigcommerce/checkout/dom-utils';
import { HostedWidgetPaymentComponent } from '@bigcommerce/checkout/hosted-widget-integration';
Expand All @@ -13,6 +20,7 @@ import {
PaymentMethodResolveId,
toResolvableComponent,
} from '@bigcommerce/checkout/payment-integration-api';
import { AccordionContext } from '@bigcommerce/checkout/ui';

const StripeUPEPaymentMethod: FunctionComponent<PaymentMethodProps> = ({
paymentForm,
Expand All @@ -22,9 +30,19 @@ const StripeUPEPaymentMethod: FunctionComponent<PaymentMethodProps> = ({
onUnhandledError = noop,
...rest
}) => {
const collapseStripeElement = useRef<() => void>();
const { onToggle, selectedItemId } = useContext(AccordionContext);
const containerId = `stripe-${method.id}-component-field`;
const paymentContext = paymentForm;

useEffect(() => {
if (selectedItemId?.includes('stripeupe-')) {
return;
}

collapseStripeElement.current?.();
}, [selectedItemId]);

const renderSubmitButton = useCallback(() => {
paymentContext.hidePaymentSubmitButton(method, false);
}, [paymentContext, method]);
Expand Down Expand Up @@ -69,6 +87,10 @@ const StripeUPEPaymentMethod: FunctionComponent<PaymentMethodProps> = ({
return getAppliedStyles(parentContainer, properties);
};

const accordionCollapseListener = (collapseElement: () => void) => {
collapseStripeElement.current = collapseElement;
};

const initializeStripePayment = useCallback(
async (options: PaymentInitializeOptions) => {
const formInput = getStylesFromElement(`${containerId}--input`, [
Expand Down Expand Up @@ -97,6 +119,8 @@ const StripeUPEPaymentMethod: FunctionComponent<PaymentMethodProps> = ({
},
onError: onUnhandledError,
render: renderSubmitButton,
toggleSelectedMethod: onToggle,
accordionCollapseListener,
},
});
},
Expand All @@ -107,6 +131,7 @@ const StripeUPEPaymentMethod: FunctionComponent<PaymentMethodProps> = ({
method,
paymentContext,
renderSubmitButton,
onToggle,
],
);

Expand Down
Loading

0 comments on commit 1af8268

Please sign in to comment.