Skip to content

Commit

Permalink
fix: Quick start changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Riddhiagrawal001 committed Dec 12, 2023
1 parent db743cf commit 2259ca0
Show file tree
Hide file tree
Showing 11 changed files with 104 additions and 139 deletions.
13 changes: 10 additions & 3 deletions src/entryPoints/hyperswitch/WooCommerce/WooCommerceUIUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ module SelectPaymentMethods = {
~setButtonState: (Button.buttonState => Button.buttonState) => unit,
~buttonState,
) => {
open QuickStartUtils
let updateEnumInRecoil = EnumVariantHook.useUpdateEnumInRecoil()
let enumDetails = Recoil.useRecoilValueFromAtom(HyperswitchAtom.enumVariantAtom)
let updateAPIHook = APIUtils.useUpdateMethod()
Expand Down Expand Up @@ -83,9 +84,15 @@ module SelectPaymentMethods = {
enumRecoilUpdateArr->Array.push((body, #FirstProcessorConnected))
}

if !enums.isMultipleConfiguration {
let _ = await Boolean(true)->postEnumDetails(#IsMultipleConfiguration)
enumRecoilUpdateArr->Array.push((Boolean(true), #IsMultipleConfiguration))
if enums.configurationType->Js.String2.length === 0 {
let _ =
await StringEnumType(
#MultipleProcessorWithSmartRouting->connectorChoiceVariantToString,
)->postEnumDetails(#ConfigurationType)
enumRecoilUpdateArr->Array.push((
StringEnumType(#MultipleProcessorWithSmartRouting->connectorChoiceVariantToString),
#ConfigurationType,
))
}

let _ = updateEnumInRecoil(enumRecoilUpdateArr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,7 @@ let make = (~connectProcessorValue: connectProcessor) => {
let (selectedConnector, setSelectedConnector) = React.useState(_ => UnknownConnector(""))
let (initialValues, setInitialValues) = React.useState(_ => Js.Dict.empty()->Js.Json.object_)
let (connectorConfigureState, setConnectorConfigureState) = React.useState(_ => Select_processor)
let (choiceState, setChoiceState) = React.useState(_ =>
typedEnumValue.isMultipleConfiguration
? #MultipleProcessorWithSmartRouting
: #SinglePaymentProcessor
)
let (choiceState, setChoiceState) = React.useState(_ => #NotSelected)
let (smartRoutingChoiceState, setSmartRoutingChoiceState) = React.useState(_ => #DefaultFallback)
let (choiceStateForTestConnector, setChoiceStateForTestConnector) = React.useState(_ =>
#TestApiKeys
Expand Down Expand Up @@ -102,12 +98,10 @@ let make = (~connectProcessorValue: connectProcessor) => {
}
}

let updateEnumForMultipleConfigurationType = async isMultipleConfigSelected => {
let updateEnumForMultipleConfigurationType = async connectorChoiceValue => {
try {
let isMultipleConfigurationType = #IsMultipleConfiguration
let _ = await ConnectorChoice({
isMultipleConfiguration: isMultipleConfigSelected,
})->usePostEnumDetails(isMultipleConfigurationType)
let configurationType = #ConfigurationType
let _ = await StringEnumType(connectorChoiceValue)->usePostEnumDetails(configurationType)
} catch {
| Js.Exn.Error(e) => {
let err = Js.Exn.message(e)->Belt.Option.getWithDefault("Failed to update!")
Expand All @@ -119,14 +113,18 @@ let make = (~connectProcessorValue: connectProcessor) => {
try {
setButtonState(_ => Loading)
if choiceState === #MultipleProcessorWithSmartRouting {
let _ = await updateEnumForMultipleConfigurationType(true)
let _ = await updateEnumForMultipleConfigurationType(
#MultipleProcessorWithSmartRouting->connectorChoiceVariantToString,
)
setQuickStartPageState(_ =>
typedEnumValue.firstProcessorConnected.processorID->Js.String2.length > 0
? ConnectProcessor(CONFIGURE_SECONDARY)
: ConnectProcessor(CONFIGURE_PRIMARY)
)
} else {
let _ = await updateEnumForMultipleConfigurationType(false)
let _ = await updateEnumForMultipleConfigurationType(
#SinglePaymentProcessor->connectorChoiceVariantToString,
)
setQuickStartPageState(_ =>
typedEnumValue.firstProcessorConnected.processorID->Js.String2.length > 0
? ConnectProcessor(CHECKOUT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,14 @@ let make = (
let handleSummaryProceed = () => {
if (
connectorArray->Js.Array2.length === multipleConfigurationArrayLength &&
typedEnumValue.isMultipleConfiguration
typedEnumValue.configurationType->connectorChoiceStringVariantMapper ===
#MultipleProcessorWithSmartRouting
) {
setQuickStartPageState(_ => ConnectProcessor(CONFIGURE_SMART_ROUTING))
} else if !typedEnumValue.isMultipleConfiguration {
} else if (
typedEnumValue.configurationType->connectorChoiceStringVariantMapper ===
#SinglePaymentProcessor
) {
setQuickStartPageState(_ => QuickStartTypes.ConnectProcessor(QuickStartTypes.CHECKOUT))
} else {
setSelectedConnector(_ => UnknownConnector(""))
Expand Down
2 changes: 1 addition & 1 deletion src/screens/HyperSwitch/Home/HomeUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -460,11 +460,11 @@ let getValueMapped = (value, key) => {
| #ConfigureWoocom
| #SetupWoocomWebhook =>
value->getBool(key, false)->Js.Json.boolean
| #ConfigurationType => value->getString(key, "")->Js.Json.string
| #FirstProcessorConnected
| #SecondProcessorConnected
| #StripeConnected
| #PaypalConnected
| #IsMultipleConfiguration
| #IntegrationMethod =>
value->getJsonObjectFromDict(key)
| #TestPayment => value->getJsonObjectFromDict(key)
Expand Down
28 changes: 19 additions & 9 deletions src/screens/HyperSwitch/Home/HomeV2.res
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ module HomePageHorizontalStepper = {
module QuickStart = {
@react.component
let make = (~isMobileView) => {
open QuickStartUtils
let {setDashboardPageState, setQuickStartPageState} = React.useContext(
GlobalProvider.defaultContext,
)
Expand All @@ -90,7 +91,7 @@ module QuickStart = {
let typedConnectorValue = connectorList->getArrayOfConnectorListPayloadType

if (
!typedValueOfEnum.isMultipleConfiguration &&
typedValueOfEnum.configurationType->Js.String2.length === 0 &&
typedValueOfEnum.firstProcessorConnected.processorID->Js.String2.length === 0 &&
typedValueOfEnum.secondProcessorConnected.processorID->Js.String2.length === 0
) {
Expand All @@ -115,17 +116,22 @@ module QuickStart = {
processorName: secondConnectorValue.connector_name,
}

let _isMultipleConnectorSetup = await ConnectorChoice({
isMultipleConfiguration: true,
})->usePostEnumDetails(#IsMultipleConfiguration)
let _connectorChoiceSetup =
await StringEnumType(
#MultipleProcessorWithSmartRouting->connectorChoiceVariantToString,
)->usePostEnumDetails(#ConfigurationType)

let _firstEnumSetupValues =
await ProcesorType(bodyOfFirstConnector)->usePostEnumDetails(#FirstProcessorConnected)
let _secondEnumSetupValues =
await ProcesorType(bodyOfSecondConnector)->usePostEnumDetails(
#SecondProcessorConnected,
)
let _ = updateEnumInRecoil([
(Boolean(true), #IsMultipleConfiguration),
(
StringEnumType(#MultipleProcessorWithSmartRouting->connectorChoiceVariantToString),
#ConfigurationType,
),
(ProcesorType(bodyOfFirstConnector), #FirstProcessorConnected),
(ProcesorType(bodyOfSecondConnector), #SecondProcessorConnected),
])
Expand All @@ -141,13 +147,17 @@ module QuickStart = {
processorName: firstConnectorValue.connector_name,
}

let _isMultipleConnectorSetup = await ConnectorChoice({
isMultipleConfiguration: true,
})->usePostEnumDetails(#IsMultipleConfiguration)
let _connectorChoiceSetup =
await StringEnumType(
#MultipleProcessorWithSmartRouting->connectorChoiceVariantToString,
)->usePostEnumDetails(#ConfigurationType)
let _firstEnumSetupValues =
await ProcesorType(bodyOfFirstConnector)->usePostEnumDetails(#FirstProcessorConnected)
let _ = updateEnumInRecoil([
(ConnectorChoice({isMultipleConfiguration: true}), #IsMultipleConfiguration),
(
StringEnumType(#MultipleProcessorWithSmartRouting->connectorChoiceVariantToString),
#ConfigurationType,
),
(ProcesorType(bodyOfFirstConnector), #FirstProcessorConnected),
])
setQuickStartPageState(_ => ConnectProcessor(CONFIGURE_SECONDARY))
Expand Down
30 changes: 3 additions & 27 deletions src/screens/HyperSwitch/Home/ProdIntent/ProdIntentForm.res
Original file line number Diff line number Diff line change
Expand Up @@ -4,35 +4,13 @@ let make = (~isFromMilestoneCard=false) => {
open ProdVerifyModalUtils

let fetchDetails = useGetMethod()
let updateDetails = useUpdateMethod()

let email = HSLocalStorage.getFromMerchantDetails("email")
let {
showProdIntentForm,
setShowProdIntentForm,
dashboardPageState,
integrationDetails,
setIntegrationDetails,
setIsProdIntentCompleted,
} = React.useContext(GlobalProvider.defaultContext)
let {showProdIntentForm, setShowProdIntentForm, setIsProdIntentCompleted} = React.useContext(
GlobalProvider.defaultContext,
)
let (initialValues, setInitialValues) = React.useState(_ => Js.Dict.empty())

let markAsDone = async () => {
try {
let url = getURL(~entityName=INTEGRATION_DETAILS, ~methodType=Post, ())
let body = HSwitchUtils.constructOnboardingBody(
~dashboardPageState,
~integrationDetails,
~is_done=true,
(),
)
let _ = await updateDetails(url, body, Post)
setIntegrationDetails(_ => body->ProviderHelper.getIntegrationDetails)
} catch {
| _ => ()
}
}

let getProdVerifyDetails = async () => {
open LogicUtils
try {
Expand All @@ -50,8 +28,6 @@ let make = (~isFromMilestoneCard=false) => {
setIsProdIntentCompleted(_ => hideHeader)
if !hideHeader {
valueForProdIntent->Js.Dict.set(POCemail->getStringFromVariant, email->Js.Json.string)
} else if !integrationDetails.account_activation.is_done {
markAsDone()->ignore
}
setInitialValues(_ => valueForProdIntent)
} catch {
Expand Down
24 changes: 1 addition & 23 deletions src/screens/HyperSwitch/Home/ProdIntent/ProdVerifyModal.res
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,7 @@ let make = (~showModal, ~setShowModal, ~initialValues=Js.Dict.empty(), ~getProdV
let showToast = ToastState.useShowToast()
let (screenState, setScreenState) = React.useState(_ => PageLoaderWrapper.Success)
let (isSubmitBtnDisabled, setIsSubmitBtnDisabled) = React.useState(_ => false)
let {
dashboardPageState,
integrationDetails,
setIntegrationDetails,
setShowProdIntentForm,
} = React.useContext(GlobalProvider.defaultContext)

let markAsDone = async () => {
try {
let url = getURL(~entityName=INTEGRATION_DETAILS, ~methodType=Post, ())
let body = HSwitchUtils.constructOnboardingBody(
~dashboardPageState,
~integrationDetails,
~is_done=true,
(),
)
let _ = await updateDetails(url, body, Post)
setIntegrationDetails(_ => body->ProviderHelper.getIntegrationDetails)
} catch {
| _ => ()
}
}
let {setShowProdIntentForm} = React.useContext(GlobalProvider.defaultContext)

let updateProdDetails = async values => {
try {
Expand All @@ -47,7 +26,6 @@ let make = (~showModal, ~setShowModal, ~initialValues=Js.Dict.empty(), ~getProdV
)
setScreenState(_ => Success)
getProdVerifyDetails()->ignore
markAsDone()->ignore
setShowProdIntentForm(_ => false)
} catch {
| _ => setShowModal(_ => false)
Expand Down
32 changes: 4 additions & 28 deletions src/screens/HyperSwitch/Home/QuickStart/GoLive.res
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,9 @@ let make = (~goLive) => {
let (initialValues, setInitialValues) = React.useState(_ => Js.Dict.empty())
let {isProdIntentCompleted} = React.useContext(GlobalProvider.defaultContext)
let (isSubmitBtnDisabled, setIsSubmitBtnDisabled) = React.useState(_ => false)
let {
dashboardPageState,
integrationDetails,
setIntegrationDetails,
setIsProdIntentCompleted,
setQuickStartPageState,
setDashboardPageState,
} = React.useContext(GlobalProvider.defaultContext)

let markAsDone = async () => {
try {
let url = getURL(~entityName=INTEGRATION_DETAILS, ~methodType=Post, ())
let body = HSwitchUtils.constructOnboardingBody(
~dashboardPageState,
~integrationDetails,
~is_done=true,
(),
)
let _ = await updateDetails(url, body, Post)
setIntegrationDetails(_ => body->ProviderHelper.getIntegrationDetails)
setQuickStartPageState(_ => FinalLandingPage)
} catch {
| _ => ()
}
}
let {setIsProdIntentCompleted, setQuickStartPageState, setDashboardPageState} = React.useContext(
GlobalProvider.defaultContext,
)

let getProdVerifyDetails = async () => {
open LogicUtils
Expand All @@ -78,9 +56,8 @@ let make = (~goLive) => {
setIsProdIntentCompleted(_ => hideHeader)
if !hideHeader {
valueForProdIntent->Js.Dict.set(POCemail->getStringFromVariant, email->Js.Json.string)
} else if !integrationDetails.account_activation.is_done {
markAsDone()->ignore
}
setQuickStartPageState(_ => FinalLandingPage)
setInitialValues(_ => valueForProdIntent)
} catch {
| _ => ()
Expand All @@ -95,7 +72,6 @@ let make = (~goLive) => {
let _ = await updateDetails(url, body, Post)

getProdVerifyDetails()->ignore
markAsDone()->ignore
} catch {
| _ => ()
}
Expand Down
7 changes: 3 additions & 4 deletions src/screens/HyperSwitch/Home/QuickStart/QuickStartTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ type sectionHeadingVariant = [
| #DownloadWoocom
| #ConfigureWoocom
| #SetupWoocomWebhook
| #IsMultipleConfiguration
| #ConfigurationType
| #GoLive
| #DownloadTestAPIKeyStripe
| #InstallDeps
Expand All @@ -76,7 +76,6 @@ type routingType = {routing_id: string}
type paymentType = {payment_id: string}

type integrationMethod = {integration_type: string}
type connectorChoice = {isMultipleConfiguration: bool}

type responseType = {
productionAgreement: bool,
Expand All @@ -93,7 +92,6 @@ type responseType = {
downloadWoocom: bool,
configureWoocom: bool,
setupWoocomWebhook: bool,
isMultipleConfiguration: bool,
downloadTestAPIKeyStripe: string,
installDeps: string,
replaceAPIKeys: string,
Expand All @@ -103,15 +101,16 @@ type responseType = {
createPayment: string,
displayCheckout: string,
displayPaymentConfirmation: string,
configurationType: string,
}

type requestObjectType =
| ProcesorType(processorType)
| RoutingType(routingType)
| PaymentType(paymentType)
| IntegrationMethod(integrationMethod)
| ConnectorChoice(connectorChoice)
| Boolean(bool)
| String(string)
| StringEnumType(string)

type valueType = String(string) | Boolean(bool)
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,6 @@ module HorizontalChoiceTile = {
}

module LandingPageChoice = {
open QuickStartTypes
@react.component
let make = (
~choiceState,
Expand All @@ -193,11 +192,7 @@ module LandingPageChoice = {
~customLayoutCss="",
) => {
React.useEffect0(() => {
let defaultValue =
listChoices
->Belt.Array.get(0)
->Belt.Option.getWithDefault(QuickStartUtils.defaultChoiceStateValue)
setChoiceState(_ => defaultValue.variantType)
setChoiceState(_ => #NotSelected)
None
})

Expand Down
Loading

0 comments on commit 2259ca0

Please sign in to comment.