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

feat: Add forgot password feature flag #40

Merged
merged 5 commits into from
Nov 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions config/FeatureFlag.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"stripe_plus_paypal": false,
"woocommerce": false,
"open_sdk": false,
"home_page": false,
"switch_merchant": false,
"audit_trail": false,
"system_metrics": false,
Expand All @@ -21,5 +20,6 @@
"verify_connector": false,
"mixpanel": false,
"business_profile": false,
"generate_report": false
"generate_report": false,
"forgot_password": false
}
8 changes: 4 additions & 4 deletions src/entryPoints/hyperswitch/FeatureFlagUtils.res
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
type featureFlag = {
default: bool,
productionAccess: bool,
testLiveToggle: bool,
magicLink: bool,
quickStart: bool,
stripePlusPayPal: bool,
wooCommerce: bool,
openSDK: bool,
homePage: bool,
switchMerchant: bool,
testLiveMode: option<bool>,
auditTrail: bool,
Expand All @@ -22,21 +22,21 @@ type featureFlag = {
businessProfile: bool,
mixPanel: bool,
verifyConnector: bool,
default: bool,
forgetPassword: bool,
}

let featureFlagType = (featureFlags: Js.Json.t) => {
open LogicUtils
let dict = featureFlags->getDictFromJsonObject
let typedFeatureFlag: featureFlag = {
default: dict->getBool("default", true),
productionAccess: dict->getBool("production_access", false),
testLiveToggle: dict->getBool("test_live_toggle", false),
magicLink: dict->getBool("magic_link", false),
quickStart: dict->getBool("quick_start", false),
stripePlusPayPal: dict->getBool("stripe_plus_paypal", false),
wooCommerce: dict->getBool("woocommerce", false),
openSDK: dict->getBool("open_sdk", false),
homePage: dict->getBool("home_page", false),
switchMerchant: dict->getBool("switch_merchant", false),
testLiveMode: dict->getOptionBool("test_live_mode"),
auditTrail: dict->getBool("audit_trail", false),
Expand All @@ -52,7 +52,7 @@ let featureFlagType = (featureFlags: Js.Json.t) => {
businessProfile: dict->getBool("business_profile", false),
mixPanel: dict->getBool("mixpanel", false),
verifyConnector: dict->getBool("verify_connector", false),
default: dict->getBool("default", true),
forgetPassword: dict->getBool("forgot_password", false),
}
typedFeatureFlag
}
2 changes: 2 additions & 0 deletions src/screens/HyperSwitch/Settings/HSwitchSettings.res
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ module PersonalSettings = {
->FeatureFlagUtils.featureFlagType
let personalSettings = if featureFlagDetails.sampleData {
[businessSettings, businessUnits, deleteSampleData]
} else if featureFlagDetails.businessProfile {
[businessSettings, businessUnits]
} else {
[businessSettings]
}
Expand Down
40 changes: 21 additions & 19 deletions src/screens/login/HSwitchLoginFlow/HyperSwitchAuth.res
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ let make = (~setAuthStatus: HyperSwitchAuthTypes.authStatus => unit, ~authType,
let showToast = ToastState.useShowToast()
let updateDetails = useUpdateMethod(~showErrorToast=false, ())
let (email, setEmail) = React.useState(_ => "")
let {magicLink: isMagicLinkEnabled} =
let {magicLink: isMagicLinkEnabled, forgetPassword} =
HyperswitchAtom.featureFlagAtom
->Recoil.useRecoilValueFromAtom
->LogicUtils.safeParse
Expand Down Expand Up @@ -139,9 +139,7 @@ let make = (~setAuthStatus: HyperSwitchAuthTypes.authStatus => unit, ~authType,
}
}

let onSubmit = (values, _) => {
open Promise

let onSubmit = async (values, _) => {
let valuesDict = values->getDictFromJsonObject
let email = valuesDict->getString("email", "")
setEmail(_ => email)
Expand All @@ -151,39 +149,44 @@ let make = (~setAuthStatus: HyperSwitchAuthTypes.authStatus => unit, ~authType,
| (true, SignUP) | (true, LoginWithEmail) => {
let body = getEmailBody(email, ~country, ())

getUserWithEmail(body)
getUserWithEmail(body)->ignore
}
| (true, ForgetPassword) =>
let body = email->getEmailBody()

setForgetPassword(body)

| (true, ResendVerifyEmail) =>
let body = email->getEmailBody()
resendVerifyEmail(body)
resendVerifyEmail(body)->ignore

| (false, SignUP) => {
let password = getString(valuesDict, "password", "")
let body = getEmailPasswordBody(email, password, country)

getUserWithEmailPassword(body, email)
getUserWithEmailPassword(body, email)->ignore
}
| (_, LoginWithPassword) => {
let password = getString(valuesDict, "password", "")
let body = getEmailPasswordBody(email, password, country)

getUserWithEmailPassword(body, email)
getUserWithEmailPassword(body, email)->ignore
}
| (_, ResetPassword) => {
let queryDict = url.search->getDictFromUrlSearchParams
let password_reset_token = queryDict->Js.Dict.get("token")->Belt.Option.getWithDefault("")
let password = getString(valuesDict, "create_password", "")
let body = getResetpasswordBodyJson(password, password_reset_token)
setResetPassword(body)
setResetPassword(body)->ignore
}

| _ => Js.Nullable.null->resolve
| _ => ()
}

switch (forgetPassword, authType) {
| (true, ForgetPassword) =>
let body = email->getEmailBody()

setForgetPassword(body)->ignore
| _ => ()
}
Js.Nullable.null
}

let resendEmail = () => {
Expand Down Expand Up @@ -234,14 +237,13 @@ let make = (~setAuthStatus: HyperSwitchAuthTypes.authStatus => unit, ~authType,
onSubmit={handleSubmit}
className={`flex flex-col justify-evenly gap-5 h-full w-full !overflow-visible text-grey-600`}>
{switch authType {
| LoginWithPassword => <EmailPasswordForm setAuthType isMagicLinkEnabled />
| LoginWithPassword => <EmailPasswordForm setAuthType forgetPassword />
| LoginWithEmail
| ForgetPassword
| ForgetPassword =>
forgetPassword ? <EmailForm /> : React.null
| ResendVerifyEmail
| SignUP =>
isMagicLinkEnabled
? <EmailForm />
: <EmailPasswordForm setAuthType isMagicLinkEnabled />
isMagicLinkEnabled ? <EmailForm /> : <EmailPasswordForm setAuthType forgetPassword />
| ResetPassword => <ResetPasswordForm />
| MagicLinkEmailSent | ForgetPasswordEmailSent | ResendVerifyEmailSent =>
<ResendBtn callBackFun={resendEmail} />
Expand Down
4 changes: 2 additions & 2 deletions src/screens/login/HSwitchLoginFlow/HyperSwitchAuthForm.res
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ let fieldWrapperClass = "w-full flex flex-col"
let labelClass = "!text-black !font-medium"
module EmailPasswordForm = {
@react.component
let make = (~setAuthType, ~isMagicLinkEnabled) => {
let make = (~setAuthType, ~forgetPassword) => {
<div className="flex flex-col gap-3">
<FormRenderer.FieldRenderer field=emailField labelClass fieldWrapperClass />
<div className="flex flex-col gap-3">
<FormRenderer.FieldRenderer field=passwordField labelClass fieldWrapperClass />
<UIUtils.RenderIf condition={isMagicLinkEnabled}>
<UIUtils.RenderIf condition={forgetPassword}>
<label
className={`not-italic text-[12px] font-semibold font-ibm-plex text-blue-800 cursor-pointer cursor-pointer`}
onClick={_ => setAuthType(_ => HyperSwitchAuthTypes.ForgetPassword)}>
Expand Down
Loading