-
Notifications
You must be signed in to change notification settings - Fork 108
feat: unified view for saved and more payment methods screen #1194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
13253ad
656a1b5
958bb4b
94d440a
cdcd4c0
e39c251
32df8c4
9dc62be
1f47f30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -37,9 +37,12 @@ let make = ( | |
| loggerState.setLogError(~value=message, ~eventName=INVALID_FORMAT) | ||
| } | ||
| let (isSaveCardsChecked, setIsSaveCardsChecked) = React.useState(_ => false) | ||
| let {displaySavedPaymentMethodsCheckbox, readOnly} = Recoil.useRecoilValueFromAtom( | ||
| let (showMore, setShowMore) = React.useState(_ => true) | ||
| let {displaySavedPaymentMethodsCheckbox, readOnly, layout} = Recoil.useRecoilValueFromAtom( | ||
| RecoilAtoms.optionAtom, | ||
| ) | ||
| let layoutClass = CardUtils.getLayoutClass(layout) | ||
| let displayMergedSavedMethods = layoutClass.savedMethodsLayout.displayMergedSavedMethods | ||
| let isGuestCustomer = useIsGuestCustomer() | ||
|
|
||
| let {iframeId, clientSecret} = Recoil.useRecoilValueFromAtom(RecoilAtoms.keys) | ||
|
|
@@ -66,38 +69,67 @@ let make = ( | |
| let paymentMethodListValue = Recoil.useRecoilValueFromAtom(PaymentUtils.paymentMethodListValue) | ||
| let {paymentToken: paymentTokenVal, customerId} = paymentToken | ||
|
|
||
| let (cardOptionDetails, dropDownOptionsDetails) = React.useMemo(() => { | ||
| ( | ||
| savedMethods->Array.slice(~start=0, ~end=layoutClass.savedMethodsLayout.maxSavedItems), | ||
| savedMethods->Array.sliceToEnd(~start=layoutClass.savedMethodsLayout.maxSavedItems), | ||
| ) | ||
| }, [savedMethods]) | ||
|
|
||
| let renderSavedCards = (cardsArr: array<PaymentType.customerMethods>) => { | ||
| cardsArr | ||
| ->Array.mapWithIndex((obj, i) => | ||
| <SavedCardItem | ||
| key={i->Int.toString} | ||
| setPaymentToken | ||
| isActive={paymentTokenVal == obj.paymentToken} | ||
| paymentItem=obj | ||
| brandIcon={obj->getPaymentMethodBrand} | ||
| index=i | ||
| savedCardlength | ||
| cvcProps | ||
| setRequiredFieldsBody | ||
| /> | ||
| ) | ||
| ->React.array | ||
| } | ||
|
|
||
| let clickToPayElement = { | ||
| <RenderIf condition={clickToPayConfig.isReady == Some(true)}> | ||
| <ClickToPayAuthenticate | ||
| loggerState | ||
| savedMethods | ||
| isClickToPayAuthenticateError | ||
| setIsClickToPayAuthenticateError | ||
| setPaymentToken | ||
| paymentTokenVal | ||
| cvcProps | ||
| getVisaCards | ||
| setIsClickToPayRememberMe | ||
| closeComponentIfSavedMethodsAreEmpty | ||
| /> | ||
| </RenderIf> | ||
| } | ||
|
|
||
| let mergedViewBottomElement = { | ||
| <div | ||
| className="PickerItemContainer" tabIndex={0} role="region" ariaLabel="Saved payment methods"> | ||
| {renderSavedCards(cardOptionDetails)} | ||
| <div | ||
| className={`transition-all duration-300 ease-in-out overflow-hidden | ||
| ${showMore ? "max-h-0 opacity-0" : "max-h-screen opacity-100"} | ||
| `}> | ||
| {renderSavedCards(dropDownOptionsDetails)} | ||
| </div> | ||
| clickToPayElement | ||
| </div> | ||
| } | ||
|
|
||
| let bottomElement = { | ||
| <div | ||
| className="PickerItemContainer" tabIndex={0} role="region" ariaLabel="Saved payment methods"> | ||
| {savedMethods | ||
| ->Array.mapWithIndex((obj, i) => | ||
| <SavedCardItem | ||
| key={i->Int.toString} | ||
| setPaymentToken | ||
| isActive={paymentTokenVal == obj.paymentToken} | ||
| paymentItem=obj | ||
| brandIcon={obj->getPaymentMethodBrand} | ||
| index=i | ||
| savedCardlength | ||
| cvcProps | ||
| setRequiredFieldsBody | ||
| /> | ||
| ) | ||
| ->React.array} | ||
| <RenderIf condition={clickToPayConfig.isReady == Some(true)}> | ||
| <ClickToPayAuthenticate | ||
| loggerState | ||
| savedMethods | ||
| isClickToPayAuthenticateError | ||
| setIsClickToPayAuthenticateError | ||
| setPaymentToken | ||
| paymentTokenVal | ||
| cvcProps | ||
| getVisaCards | ||
| setIsClickToPayRememberMe | ||
| closeComponentIfSavedMethodsAreEmpty | ||
| /> | ||
| </RenderIf> | ||
| <RenderIf condition={!displayMergedSavedMethods}> {renderSavedCards(savedMethods)} </RenderIf> | ||
| clickToPayElement | ||
|
||
| </div> | ||
| } | ||
|
|
||
|
|
@@ -336,14 +368,23 @@ let make = ( | |
| let enableSavedPaymentShimmer = React.useMemo(() => { | ||
| savedCardlength === 0 && | ||
| !showPaymentMethodsScreen && | ||
| (loadSavedCards === PaymentType.LoadingSavedCards || clickToPayConfig.isReady->Option.isNone) | ||
| }, (savedCardlength, loadSavedCards, showPaymentMethodsScreen, clickToPayConfig.isReady)) | ||
| (loadSavedCards === PaymentType.LoadingSavedCards || clickToPayConfig.isReady->Option.isNone) && | ||
| !displayMergedSavedMethods | ||
| }, ( | ||
| savedCardlength, | ||
| loadSavedCards, | ||
| showPaymentMethodsScreen, | ||
| clickToPayConfig.isReady, | ||
| displayMergedSavedMethods, | ||
| )) | ||
|
Comment on lines
436
to
+447
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Try to simplify this condition for better readability. |
||
|
|
||
| <div className="flex flex-col overflow-auto h-auto no-scrollbar animate-slowShow"> | ||
| {if enableSavedPaymentShimmer { | ||
| <PaymentElementShimmer.SavedPaymentCardShimmer /> | ||
| } else { | ||
| <RenderIf condition={!showPaymentMethodsScreen}> {bottomElement} </RenderIf> | ||
| <RenderIf condition={!showPaymentMethodsScreen}> | ||
| {displayMergedSavedMethods ? mergedViewBottomElement : bottomElement} | ||
| </RenderIf> | ||
| }} | ||
|
||
| <RenderIf condition={conditionsForShowingSaveCardCheckbox}> | ||
| <div className="pt-4 pb-2 flex items-center justify-start"> | ||
|
|
@@ -360,7 +401,7 @@ let make = ( | |
| } | ||
| /> | ||
| </RenderIf> | ||
| <RenderIf condition={!enableSavedPaymentShimmer}> | ||
| <RenderIf condition={!enableSavedPaymentShimmer && !displayMergedSavedMethods}> | ||
| <div | ||
| className="Label flex flex-row gap-3 items-end cursor-pointer mt-4" | ||
| style={ | ||
|
|
@@ -386,5 +427,6 @@ let make = ( | |
| {React.string(localeString.morePaymentMethods)} | ||
| </div> | ||
| </RenderIf> | ||
| <ShowMoreButton displayMergedSavedMethods dropDownOptionsDetails showMore setShowMore /> | ||
| </div> | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,24 @@ | ||||||||||
| @react.component | ||||||||||
| let make = (~displayMergedSavedMethods, ~dropDownOptionsDetails, ~showMore, ~setShowMore) => { | ||||||||||
| let {themeObj} = Recoil.useRecoilValueFromAtom(RecoilAtoms.configAtom) | ||||||||||
|
|
||||||||||
| <RenderIf condition={displayMergedSavedMethods && dropDownOptionsDetails->Array.length > 0}> | ||||||||||
| <div | ||||||||||
| className="Label flex flex-row gap-1 items-end cursor-pointer mt-3" | ||||||||||
| style={ | ||||||||||
| fontSize: "14px", | ||||||||||
| float: "left", | ||||||||||
| fontWeight: "500", | ||||||||||
| width: "fit-content", | ||||||||||
| color: themeObj.colorPrimary, | ||||||||||
| } | ||||||||||
|
||||||||||
| onClick={_ => { | ||||||||||
| setShowMore(_ => !showMore) | ||||||||||
| }}> | ||||||||||
|
||||||||||
| onClick={_ => { | |
| setShowMore(_ => !showMore) | |
| }}> | |
| onClick={_ => setShowMore(prev => !prev) }> |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -60,6 +60,7 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod | |||||||||||||||||
| }, (clickToPayConfig, isClickToPayAuthenticateError)) | ||||||||||||||||||
|
|
||||||||||||||||||
| let layoutClass = CardUtils.getLayoutClass(layout) | ||||||||||||||||||
| let displayMergedSavedMethods = layoutClass.savedMethodsLayout.displayMergedSavedMethods | ||||||||||||||||||
|
|
||||||||||||||||||
| let (getVisaCards, closeComponentIfSavedMethodsAreEmpty) = ClickToPayHook.useClickToPay( | ||||||||||||||||||
| ~areClickToPayUIScriptsLoaded, | ||||||||||||||||||
|
|
@@ -278,6 +279,11 @@ let make = (~cardProps, ~expiryProps, ~cvcProps, ~paymentType: CardThemeType.mod | |||||||||||||||||
| }, [selectedOption]) | ||||||||||||||||||
| useSubmitPaymentData(submitCallback) | ||||||||||||||||||
| React.useEffect(() => { | ||||||||||||||||||
| if displayMergedSavedMethods && selectedOption == "saved_methods" { | ||||||||||||||||||
| setShowPaymentMethodsScreen(_ => false) | ||||||||||||||||||
| } else if displayMergedSavedMethods { | ||||||||||||||||||
| setShowPaymentMethodsScreen(_ => true) | ||||||||||||||||||
| } | ||||||||||||||||||
|
||||||||||||||||||
| if displayMergedSavedMethods && selectedOption == "saved_methods" { | |
| setShowPaymentMethodsScreen(_ => false) | |
| } else if displayMergedSavedMethods { | |
| setShowPaymentMethodsScreen(_ => true) | |
| } | |
| let showScreen = | |
| displayMergedSavedMethods && selectedOption !== "saved_methods"; | |
| setShowPaymentMethodsScreen(showScreen); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would not be equivalent to the previous case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added this
if displayMergedSavedMethods {
setShowPaymentMethodsScreen(_ => selectedOption != "saved_methods")
}
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we simplify this? It's too many conditions inside a prop - not readable
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we simplify this? It's too many conditions inside a prop - not readable
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be a react component