-
Notifications
You must be signed in to change notification settings - Fork 28
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
feat: enable payment methods cloning to another profile of same merchant #1875
Open
gitanjli525
wants to merge
18
commits into
main
Choose a base branch
from
clone-payment-methods-feature
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 11 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
d1e4576
feat: enable payment methods cloning to another profile of same merchant
0b77bf4
feat: enable payment methods cloning to another profile of same merchant
03bcd7f
feat: enable payment methods cloning to another profile of same merchant
8264901
chore: merge main and resolve conflict
f2ccb35
chore: address comment
9de87bd
chore: css changes
28f9da4
chore: css changes
9811c8d
chore: added banner to indicate cloned Payment methods
2d34aff
chore: added banner to indicate cloned Payment methods
aaf8978
chore: merge main and resolve conflict
a2a35d7
chore: css changes for banner
90fba7c
chore: merged main and resolved conflicts
1c9ed7b
chore: merged main and resolved conflicts
c7e02f3
chore: merged main and resolved conflicts
7065ab9
chore: label update
77c2ebb
chore: address comment
52d26c7
chore: change action cell value
f49abbc
Merge branch 'main' of https://github.com/juspay/hyperswitch-control-…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
152 changes: 152 additions & 0 deletions
152
src/screens/Connectors/CloneConnectorPaymentMethods.res
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
module ClonePaymentMethodsModal = { | ||
@react.component | ||
let make = (~setShowModal, ~showModal) => { | ||
let showToast = ToastState.useShowToast() | ||
let (retainCloneModal, setRetainCloneModal) = Recoil.useRecoilState( | ||
HyperswitchAtom.retainCloneModalAtom, | ||
) | ||
let cloneConnector = Recoil.useRecoilValueFromAtom(HyperswitchAtom.cloneConnectorAtom) | ||
let (buttonState, setButtonState) = Recoil.useRecoilState( | ||
HyperswitchAtom.cloneModalButtonStateAtom, | ||
) | ||
let setIsClonePMFlow = Recoil.useSetRecoilState(HyperswitchAtom.isClonePMFlow) | ||
|
||
let onNextClick = _ => { | ||
RescriptReactRouter.push( | ||
GlobalVars.appendDashboardPath(~url=`/connectors/new?name=${cloneConnector}`), | ||
) | ||
setRetainCloneModal(_ => false) | ||
showToast( | ||
~toastType=ToastSuccess, | ||
~message="Payment Methods Cloned Successfully", | ||
~autoClose=true, | ||
) | ||
setIsClonePMFlow(_ => true) | ||
} | ||
|
||
let modalBody = { | ||
<> | ||
<div className="pt-3 m-3 flex justify-between"> | ||
<CardUtils.CardHeader | ||
heading="Clone Payment Methods" | ||
subHeading="" | ||
customSubHeadingStyle="w-full !max-w-none pr-10" | ||
/> | ||
<div | ||
className="h-fit" | ||
onClick={_ => { | ||
setShowModal(_ => false) | ||
setRetainCloneModal(_ => false) | ||
}}> | ||
<Icon name="modal-close-icon" className="cursor-pointer" size=30 /> | ||
</div> | ||
</div> | ||
<hr /> | ||
<div> | ||
<div className="flex flex-col gap-2 py-10 text-sm leading-7 text-gray-600 mx-3"> | ||
<p> | ||
{"Select the target profile where you want to clone payment methods"->React.string} | ||
</p> | ||
<div> | ||
<p> {"Target Profile"->React.string} </p> | ||
<RenderIf condition={retainCloneModal}> | ||
<div className="w-48"> | ||
<ProfileSwitch | ||
showSwitchModal=false setButtonState showHeading=false customMargin="mt-8" | ||
/> | ||
</div> | ||
</RenderIf> | ||
</div> | ||
</div> | ||
<hr className="mt-4" /> | ||
<div className="flex justify-end my-4 mr-4"> | ||
<Button text="Next" onClick={_ => onNextClick()} buttonState buttonType={Primary} /> | ||
</div> | ||
</div> | ||
</> | ||
} | ||
|
||
<div> | ||
<Modal | ||
showModal | ||
closeOnOutsideClick=true | ||
setShowModal | ||
childClass="p-0" | ||
borderBottom=true | ||
modalClass="w-full max-w-xl mx-auto my-auto dark:!bg-jp-gray-lightgray_background"> | ||
{modalBody} | ||
</Modal> | ||
</div> | ||
} | ||
} | ||
|
||
@react.component | ||
let make = (~connectorID, ~connectorName) => { | ||
open APIUtils | ||
open ConnectorUtils | ||
let getURL = useGetURL() | ||
let fetchDetails = useGetMethod() | ||
let showToast = ToastState.useShowToast() | ||
let (initialValues, setInitialValues) = React.useState(_ => JSON.Encode.null) | ||
let (paymentMethodsEnabled, setPaymentMethods) = React.useState(_ => | ||
Dict.make()->JSON.Encode.object->getPaymentMethodEnabled | ||
) | ||
let setPaymentMethodsClone = Recoil.useSetRecoilState(HyperswitchAtom.paymentMethodsClonedAtom) | ||
let setRetainCloneModal = Recoil.useSetRecoilState(HyperswitchAtom.retainCloneModalAtom) | ||
let setCloneConnector = Recoil.useSetRecoilState(HyperswitchAtom.cloneConnectorAtom) | ||
let (showModal, setShowModal) = React.useState(_ => false) | ||
|
||
let setPaymentMethodDetails = async () => { | ||
try { | ||
initialValues->setConnectorPaymentMethods(setPaymentMethods)->ignore | ||
} catch { | ||
| _ => showToast(~message="Failed to Clone Payment methods", ~toastType=ToastError) | ||
} | ||
} | ||
|
||
React.useEffect(() => { | ||
if initialValues != JSON.Encode.null { | ||
setPaymentMethodDetails()->ignore | ||
} | ||
None | ||
}, [initialValues]) | ||
|
||
React.useEffect(() => { | ||
if paymentMethodsEnabled->Array.length > 0 { | ||
let paymentMethodsClone = | ||
paymentMethodsEnabled | ||
->Identity.genericTypeToJson | ||
->JSON.stringify | ||
->LogicUtils.safeParse | ||
->getPaymentMethodEnabled | ||
setPaymentMethodsClone(_ => paymentMethodsClone) | ||
|
||
setShowModal(_ => true) | ||
setRetainCloneModal(_ => true) | ||
} | ||
None | ||
}, [paymentMethodsEnabled]) | ||
|
||
let getConnectorDetails = async () => { | ||
try { | ||
let connectorUrl = getURL(~entityName=CONNECTOR, ~methodType=Get, ~id=Some(connectorID)) | ||
let json = await fetchDetails(connectorUrl) | ||
setInitialValues(_ => json) | ||
} catch { | ||
| _ => Exn.raiseError("Something went wrong") | ||
} | ||
} | ||
|
||
let handleCloneClick = e => { | ||
e->ReactEvent.Mouse.stopPropagation | ||
getConnectorDetails()->ignore | ||
setCloneConnector(_ => connectorName) | ||
} | ||
<> | ||
<div className="flex" onClick={handleCloneClick}> | ||
<p> {"Clone"->React.string} </p> | ||
<img alt="copy" src={`/assets/CopyToClipboard.svg`} /> | ||
</div> | ||
<ClonePaymentMethodsModal showModal setShowModal /> | ||
</> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
add
dev_
as prefixThere 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.
updated @JeevaRamu0104