Skip to content

Commit

Permalink
feat: sub steps (#56)
Browse files Browse the repository at this point in the history
Co-authored-by: Lokesh Jain <[email protected]>
Co-authored-by: Jeeva Ramachandran <[email protected]>
  • Loading branch information
3 people authored Dec 12, 2023
1 parent ff1b90b commit 16a3e18
Show file tree
Hide file tree
Showing 7 changed files with 121 additions and 25 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ let make = (
let (currentStep, setCurrentStep) = React.useState(_ => DownloadTestAPIKey)
let {setQuickStartPageState} = React.useContext(GlobalProvider.defaultContext)
let isLastStep = currentStep === DisplayPaymentConfirmation
let updateEnumInRecoil = EnumVariantHook.useUpdateEnumInRecoil()

let theme = switch ThemeProvider.useTheme() {
| Dark => "vs-dark"
Expand All @@ -25,10 +26,18 @@ let make = (
buttonState={Normal}
buttonType={PrimaryOutline}
text="Back"
onClick={_ =>
currentStep === DownloadTestAPIKey
? setQuickStartPageState(_ => IntegrateApp(CHOOSE_INTEGRATION))
: setCurrentStep(_ => getNavigationStepForStandardIntegration(~currentStep, ()))}
onClick={_ => {
let prevStep = getNavigationStepForStandardIntegration(~currentStep, ())
if currentStep === DownloadTestAPIKey {
setQuickStartPageState(_ => IntegrateApp(CHOOSE_INTEGRATION))
} else {
let _ = updateEnumInRecoil([
(String("pending"), currentStep->getPolyMorphicVariantOfIntegrationSubStep),
(String("ongoing"), prevStep->getPolyMorphicVariantOfIntegrationSubStep),
])
setCurrentStep(_ => prevStep)
}
}}
buttonSize=Small
/>

Expand All @@ -40,9 +49,13 @@ let make = (
if isLastStep {
markAsDone()->ignore
} else {
setCurrentStep(_ =>
getNavigationStepForStandardIntegration(~currentStep, ~forward=true, ())
)
let nextStep = getNavigationStepForStandardIntegration(~currentStep, ~forward=true, ())
let _ = updateEnumInRecoil([
(String("completed"), currentStep->getPolyMorphicVariantOfIntegrationSubStep),
(String("ongoing"), nextStep->getPolyMorphicVariantOfIntegrationSubStep),
])

setCurrentStep(_ => nextStep)
}
}}
buttonSize=Small
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,26 @@ let getNavigationStepForStandardIntegration = (
| DisplayPaymentConfirmation => forward ? DisplayPaymentConfirmation : DisplayCheckout
}
}

let getPolyMorphicVariantOfIntegrationSubStep: standardIntegrationSteps => QuickStartTypes.sectionHeadingVariant = (
currentStep: standardIntegrationSteps,
) => {
switch currentStep {
| DownloadTestAPIKey => #DownloadTestAPIKey
| CreatePayment => #CreatePayment
| DisplayCheckout => #DisplayCheckout
| DisplayPaymentConfirmation => #DisplayPaymentConfirmation
}
}

let getPolyMorphicVariantOfMigrateFromStripe: migrateFromStripeSteps => QuickStartTypes.sectionHeadingVariant = (
currentStep: migrateFromStripeSteps,
) => {
switch currentStep {
| DownloadAPIKey => #DownloadTestAPIKeyStripe
| InstallDeps => #InstallDeps
| ReplaceAPIKeys => #ReplaceAPIKeys
| ReconfigureCheckout => #ReconfigureCheckout
| LoadCheckout => #LoadCheckout
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ let make = (
let (currentStep, setCurrentStep) = React.useState(_ => DownloadAPIKey)
let {setQuickStartPageState} = React.useContext(GlobalProvider.defaultContext)
let isLastStep = currentStep === LoadCheckout
let updateEnumInRecoil = EnumVariantHook.useUpdateEnumInRecoil()

let theme = switch ThemeProvider.useTheme() {
| Dark => "vs-dark"
Expand All @@ -25,10 +26,18 @@ let make = (
buttonState={Normal}
buttonType={PrimaryOutline}
text="Back"
onClick={_ =>
currentStep === DownloadAPIKey
? setQuickStartPageState(_ => IntegrateApp(CHOOSE_INTEGRATION))
: setCurrentStep(_ => getNavigationStepForMigrateFromStripe(~currentStep, ()))}
onClick={_ => {
let prevStep = getNavigationStepForMigrateFromStripe(~currentStep, ())
if currentStep === DownloadAPIKey {
setQuickStartPageState(_ => IntegrateApp(CHOOSE_INTEGRATION))
} else {
let _ = updateEnumInRecoil([
(String("pending"), currentStep->getPolyMorphicVariantOfMigrateFromStripe),
(String("ongoing"), prevStep->getPolyMorphicVariantOfMigrateFromStripe),
])
setCurrentStep(_ => prevStep)
}
}}
buttonSize=Small
/>

Expand All @@ -40,9 +49,12 @@ let make = (
if isLastStep {
markAsDone()->ignore
} else {
setCurrentStep(_ =>
getNavigationStepForMigrateFromStripe(~currentStep, ~forward=true, ())
)
let nextStep = getNavigationStepForMigrateFromStripe(~currentStep, ~forward=true, ())
let _ = updateEnumInRecoil([
(String("completed"), currentStep->getPolyMorphicVariantOfMigrateFromStripe),
(String("ongoing"), nextStep->getPolyMorphicVariantOfMigrateFromStripe),
])
setCurrentStep(_ => nextStep)
}
}}
buttonSize=Small
Expand Down
20 changes: 20 additions & 0 deletions src/screens/HyperSwitch/Home/QuickStart/QuickStartTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ type sectionHeadingVariant = [
| #TestPayment
| #IntegrationMethod
| #IntegrationCompleted
| #DownloadTestAPIKey
| #CreatePayment
| #DisplayCheckout
| #DisplayPaymentConfirmation
| #StripeConnected
| #PaypalConnected
| #SPRoutingConfigured
Expand All @@ -56,6 +60,11 @@ type sectionHeadingVariant = [
| #SetupWoocomWebhook
| #IsMultipleConfiguration
| #GoLive
| #DownloadTestAPIKeyStripe
| #InstallDeps
| #ReplaceAPIKeys
| #ReconfigureCheckout
| #LoadCheckout
]

type processorType = {
Expand Down Expand Up @@ -85,13 +94,24 @@ type responseType = {
configureWoocom: bool,
setupWoocomWebhook: bool,
isMultipleConfiguration: bool,
downloadTestAPIKeyStripe: string,
installDeps: string,
replaceAPIKeys: string,
reconfigureCheckout: string,
loadCheckout: string,
downloadTestAPIKey: string,
createPayment: string,
displayCheckout: string,
displayPaymentConfirmation: string,
}

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

type valueType = String(string) | Boolean(bool)
42 changes: 33 additions & 9 deletions src/screens/HyperSwitch/Home/QuickStart/QuickStartUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,13 @@ let getTypedValueFromDict = valueString => {
->getDictfromDict(#IntegrationMethod->getStringFromVariant)
->getIntegrationType,
integrationCompleted: value->getBool(#IntegrationCompleted->getStringFromVariant, false),
downloadTestAPIKey: value->getString(#DownloadTestAPIKey->getStringFromVariant, ""),
createPayment: value->getString(#CreatePayment->getStringFromVariant, ""),
displayCheckout: value->getString(#DisplayCheckout->getStringFromVariant, ""),
displayPaymentConfirmation: value->getString(
#DisplayPaymentConfirmation->getStringFromVariant,
"",
),
stripeConnected: value
->getDictfromDict(#StripeConnected->getStringFromVariant)
->getProcessorType,
Expand All @@ -183,6 +190,11 @@ let getTypedValueFromDict = valueString => {
configureWoocom: value->getBool(#ConfigureWoocom->getStringFromVariant, false),
setupWoocomWebhook: value->getBool(#SetupWoocomWebhook->getStringFromVariant, false),
isMultipleConfiguration: value->getBool(#IsMultipleConfiguration->getStringFromVariant, false),
downloadTestAPIKeyStripe: value->getString(#DownloadTestAPIKeyStripe->getStringFromVariant, ""),
installDeps: value->getString(#InstallDeps->getStringFromVariant, ""),
replaceAPIKeys: value->getString(#ReplaceAPIKeys->getStringFromVariant, ""),
reconfigureCheckout: value->getString(#ReconfigureCheckout->getStringFromVariant, ""),
loadCheckout: value->getString(#LoadCheckout->getStringFromVariant, ""),
}
typedValue
}
Expand Down Expand Up @@ -231,6 +243,17 @@ let getStatusValue = (comparator: valueType, enumVariant, dashboardPageState) =>
boolValue ? COMPLETED : dashboardPageState === enumVariant ? ONGOING : PENDING
}
}

let getStatusFromString = statusString => {
open HSSelfServeSidebar
switch statusString->Js.String2.toUpperCase {
| "PENDING" => PENDING
| "COMPLETED" => COMPLETED
| "ONGOING" => ONGOING
| _ => PENDING
}
}

let sidebarTextBasedOnVariant = choiceState =>
switch choiceState {
| #MigrateFromStripe => "Hyperswitch For Stripe Users"
Expand Down Expand Up @@ -276,23 +299,23 @@ let getSidebarOptionsForIntegrateYourApp: (
subOptions: [
{
title: "Download Test API Keys",
status: PENDING,
status: enumValue.downloadTestAPIKeyStripe->getStatusFromString,
},
{
title: "Install Dependencies",
status: PENDING,
status: enumValue.installDeps->getStatusFromString,
},
{
title: "Replace API keys",
status: PENDING,
status: enumValue.replaceAPIKeys->getStatusFromString,
},
{
title: "Reconfigure Checkout Form",
status: PENDING,
status: enumValue.reconfigureCheckout->getStatusFromString,
},
{
title: "Load Hyperswitch Checkout",
status: PENDING,
status: enumValue.loadCheckout->getStatusFromString,
},
],
},
Expand All @@ -317,19 +340,19 @@ let getSidebarOptionsForIntegrateYourApp: (
subOptions: [
{
title: "Download Test API Key",
status: PENDING,
status: enumValue.downloadTestAPIKey->getStatusFromString,
},
{
title: "Create a Payment",
status: PENDING,
status: enumValue.createPayment->getStatusFromString,
},
{
title: "Display Hyperswitch Checkout",
status: PENDING,
status: enumValue.displayCheckout->getStatusFromString,
},
{
title: "Display Payment Confirmation",
status: PENDING,
status: enumValue.displayPaymentConfirmation->getStatusFromString,
},
],
},
Expand Down Expand Up @@ -571,6 +594,7 @@ let generateBodyBasedOnType = (parentVariant: sectionHeadingVariant, value: requ
]->getJsonFromArrayOfJson

| Boolean(_) => (parentVariant :> string)->Js.Json.string
| String(str) => str->Js.Json.string
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/screens/HyperSwitch/Hooks/EnumVariantHook.res
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ let useUpdateEnumInRecoil = () => {
let booleanDict = [((enumVariant :> string), true->Js.Json.boolean)]->Js.Dict.fromArray
enumDictsArray->Array.push(booleanDict)
}
| String(str) => {
let stringDict = [((enumVariant :> string), str->Js.Json.string)]->Js.Dict.fromArray
enumDictsArray->Array.push(stringDict)
}
| _ => enumDictsArray->Array.push(bodyValForApi->getDictFromJsonObject)
}
})
Expand Down

0 comments on commit 16a3e18

Please sign in to comment.