diff --git a/packages/hosted-widget-integration/.eslintrc.json b/packages/hosted-widget-integration/.eslintrc.json
index 23eeef33ce..284c30644a 100644
--- a/packages/hosted-widget-integration/.eslintrc.json
+++ b/packages/hosted-widget-integration/.eslintrc.json
@@ -2,6 +2,7 @@
"extends": ["../../.eslintrc.json"],
"rules": {
"@typescript-eslint/no-unsafe-call": "off",
- "@typescript-eslint/no-unnecessary-condition": "off"
+ "@typescript-eslint/no-unnecessary-condition": "off",
+ "react-hooks/exhaustive-deps": "off"
}
}
diff --git a/packages/hosted-widget-integration/src/EditButton.tsx b/packages/hosted-widget-integration/src/EditButton.tsx
new file mode 100644
index 0000000000..4e0bf7672c
--- /dev/null
+++ b/packages/hosted-widget-integration/src/EditButton.tsx
@@ -0,0 +1,31 @@
+import classNames from 'classnames';
+import React, { type ReactNode } from 'react';
+
+import { preventDefault } from '@bigcommerce/checkout/dom-utils';
+import { TranslatedString } from '@bigcommerce/checkout/locale';
+
+interface EditButtonProps {
+ buttonId: string | undefined;
+ shouldShowEditButton: boolean | undefined;
+}
+
+export const EditButton = ({ buttonId, shouldShowEditButton }: EditButtonProps): ReactNode => {
+ if (shouldShowEditButton) {
+ const translatedString =
+ +
+ ); + } + + return null; +}; diff --git a/packages/hosted-widget-integration/src/HostedWidgetPaymentComponent.tsx b/packages/hosted-widget-integration/src/HostedWidgetPaymentComponent.tsx index ed9301eff0..cc7a38e69d 100644 --- a/packages/hosted-widget-integration/src/HostedWidgetPaymentComponent.tsx +++ b/packages/hosted-widget-integration/src/HostedWidgetPaymentComponent.tsx @@ -10,27 +10,31 @@ import { type PaymentMethod, type PaymentRequestOptions, } from '@bigcommerce/checkout-sdk'; -import classNames from 'classnames'; import { find, noop } from 'lodash'; -import React, { Component, type ReactNode } from 'react'; +import React, { + type ReactElement, + type ReactNode, + useCallback, + useEffect, + useRef, + useState, +} from 'react'; import { type ObjectSchema } from 'yup'; -import { preventDefault } from '@bigcommerce/checkout/dom-utils'; import { AccountInstrumentFieldset, assertIsCardInstrument, CardInstrumentFieldset, isBankAccountInstrument, + isCardInstrument, StoreInstrumentFieldset, } from '@bigcommerce/checkout/instrument-utils'; -import { TranslatedString } from '@bigcommerce/checkout/locale'; import { type PaymentFormValues } from '@bigcommerce/checkout/payment-integration-api'; import { LoadingOverlay } from '@bigcommerce/checkout/ui'; -export interface HostedWidgetComponentState { - isAddingNewCard: boolean; - selectedInstrumentId?: string; -} +import { EditButton } from './EditButton'; +import { PaymentDescriptor } from './PaymentDescriptor'; +import { PaymentWidget } from './PaymentWidget'; export interface PaymentContextProps { disableSubmit(method: PaymentMethod, disabled?: boolean): void; @@ -103,429 +107,378 @@ export interface HostedWidgetComponentProps extends WithCheckoutHostedWidgetPaym signInCustomer?(): void; } -interface HostedWidgetPaymentMethodState { - isAddingNewCard: boolean; - selectedInstrumentId?: string; -} +const HostedWidgetPaymentComponent = ({ + instruments, + hideWidget = false, + isInitializing = false, + isAccountInstrument, + isInstrumentFeatureAvailable: isInstrumentFeatureAvailableProp, + isLoadingInstruments, + shouldHideInstrumentExpiryDate = false, + shouldShow = true, + hideVerificationFields, + method, + storedCardValidationSchema, + isPaymentDataRequired, + setValidationSchema, + loadInstruments, + onUnhandledError = noop, + deinitializeCustomer, + deinitializePayment, + setSubmit, + initializeCustomer, + initializePayment, + signInCustomer, + isSignedIn, + isSignInRequired, + isInstrumentCardNumberRequired, + validateInstrument, + containerId, + hideContentWhenSignedOut = false, + renderCustomPaymentForm, + additionalContainerClassName, + shouldRenderCustomInstrument = false, + paymentDescriptor, + shouldShowDescriptor, + shouldShowEditButton, + buttonId, + setFieldValue, +}: HostedWidgetComponentProps & PaymentContextProps): ReactElement => { + const [isAddingNewCard, setIsAddingNewCard] = useState(false); + const [selectedInstrumentId, setSelectedInstrumentId] = useState- { - // eslint-disable-next-line jsx-a11y/anchor-is-valid, jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions - - {translatedString} - - } -
+ if (initializePayment) { + return initializePayment( + { gatewayId: method.gateway, methodId: method.id }, + selectedCardInstrument, ); } - } - - private renderPaymentDescriptorIfAvailable() { - const { shouldShowDescriptor, paymentDescriptor } = this.props; + }; - if (shouldShowDescriptor && paymentDescriptor) { - return