Skip to content
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

fix: Added configure return url after business profile #82

Merged
merged 8 commits into from
Dec 11, 2023
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ let labelField = FormRenderer.makeFieldInfo(
(),
)

type modalState = Loading | Edit
type modalState = Loading | Edit | Successful

let validateEmptyValue = (key, errors) => {
switch key {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,30 @@
module WarningArea = {
@react.component
let make = (~warningText) => {
<h1 className="text-orange-950 bg-orange-100 border w-full py-2 px-4 rounded-md ">
<span className="text-orange-950 font-bold text-fs-14 mr-2"> {"NOTE:"->React.string} </span>
{warningText->React.string}
</h1>
}
}
module AddEntryBtn = {
@react.component
let make = (~onSubmit, ~modalState, ~showModal, ~setShowModal, ~list, ~isFromSettings=true) => {
let make = (
~onSubmit,
~modalState,
~showModal,
~setShowModal,
~list,
~isFromSettings=true,
~updatedProfileId,
~setModalState,
) => {
open HSwitchUtils
open BusinessMappingUtils
let initialValues = [("profile_name", "Default"->Js.Json.string)]->Js.Dict.fromArray
let initialValues =
[
("profile_name", `default${list->Js.Array2.length->string_of_int}`->Js.Json.string),
]->Js.Dict.fromArray
let modalBody =
<div>
{switch modalState {
Expand Down Expand Up @@ -37,9 +58,34 @@ module AddEntryBtn = {
</div>
</LabelVisibilityContext>
</Form>
| Successful =>
<div className="flex flex-col gap-6 justify-center items-end mx-4">
<WarningArea
warningText="Warning! Now that you've configured more than one profile, you must mandatorily pass 'profile_id' in payments API request every time"
/>
<p className="text-grey-700">
{"Business Profile successfully created! Set up your payments settings like webhooks, return url for your new profile before trying a payment."->React.string}
</p>
<Button
text={"Configure payment settings"}
buttonType=Primary
onClick={_ => {
if updatedProfileId->Js.String2.length > 0 {
RescriptReactRouter.replace(`/payment-settings/${updatedProfileId}`)
setModalState(_ => Edit)
}
}}
customButtonStyle="!w-1/3 mt-6"
/>
</div>
}}
</div>

let modalHeaderText = switch modalState {
| Edit | Loading => "Add Business Profile Name"
| Successful => "Configure payment settings"
}

<div>
<UIUtils.RenderIf condition=isFromSettings>
<Button
Expand All @@ -52,7 +98,7 @@ module AddEntryBtn = {
</UIUtils.RenderIf>
<Modal
showModal
modalHeading="Add Business Profile Name"
modalHeading=modalHeaderText
setShowModal
closeOnOutsideClick=true
modalClass="w-full max-w-2xl m-auto !bg-white dark:!bg-jp-gray-lightgray_background">
Expand All @@ -78,6 +124,7 @@ let make = (
let (showModal, setShowModal) = React.useState(_ => false)
let (modalState, setModalState) = React.useState(_ => Edit)
let (screenState, setScreenState) = React.useState(_ => PageLoaderWrapper.Success)
let (updatedProfileId, setUpdatedProfileId) = React.useState(_ => "")

let businessProfileValues =
HyperswitchAtom.businessProfilesAtom
Expand All @@ -90,7 +137,10 @@ let make = (
try {
setScreenState(_ => PageLoaderWrapper.Loading)
let url = getURL(~entityName=BUSINESS_PROFILE, ~methodType=Post, ())
let _ = await updateDetails(url, body, Post)
let response = await updateDetails(url, body, Post)
setUpdatedProfileId(_ =>
response->LogicUtils.getDictFromJsonObject->LogicUtils.getString("profile_id", "")
)
fetchBusinessProfiles()->ignore
showToast(~message="Your Entry added successfully", ~toastType=ToastState.ToastSuccess, ())
if !isFromSettings {
Expand All @@ -100,9 +150,12 @@ let make = (
} catch {
| _ => setScreenState(_ => PageLoaderWrapper.Error(""))
}
isFromSettings ? setShowModal(_ => false) : setShowModalFromOtherScreen(_ => false)
setModalState(_ => Edit)
setShowModal(_ => false)

if !isFromSettings {
setShowModalFromOtherScreen(_ => false)
}
setModalState(_ => Successful)

Js.Nullable.null
}

Expand All @@ -114,11 +167,16 @@ let make = (
<PageLoaderWrapper screenState>
<UIUtils.RenderIf condition=isFromSettings>
<div className="relative h-full">
<div className="flex flex-col-reverse md:flex-col">
<div className="flex flex-col-reverse md:flex-col gap-2">
<PageUtils.PageHeading
title="Business Profiles"
subTitle="Add and manage profiles to represent different businesses across countries."
/>
<UIUtils.RenderIf condition={businessProfileValues->Js.Array2.length > 1}>
<WarningArea
warningText="Warning! Now that you've configured more than one profile, you must mandatorily pass 'profile_id' in payments API request every time"
/>
</UIUtils.RenderIf>
<LoadedTable
title="Business profiles"
hideTitle=true
Expand All @@ -133,7 +191,15 @@ let make = (
currrentFetchCount={businessProfileValues->Js.Array2.length}
/>
<div className="absolute right-0 -top-3">
<AddEntryBtn onSubmit modalState showModal setShowModal list={businessProfileValues} />
<AddEntryBtn
onSubmit
modalState
showModal
setShowModal
list={businessProfileValues}
updatedProfileId
setModalState
/>
</div>
</div>
</div>
Expand All @@ -146,6 +212,8 @@ let make = (
showModal={showModalFromOtherScreen}
setShowModal={setShowModalFromOtherScreen}
list={businessProfileValues}
updatedProfileId
setModalState
/>
</UIUtils.RenderIf>
</PageLoaderWrapper>
Expand Down