Skip to content

Commit

Permalink
fix: url changes for feedback and prodintent
Browse files Browse the repository at this point in the history
  • Loading branch information
Riddhiagrawal001 committed Dec 12, 2023
1 parent d129062 commit 136d067
Show file tree
Hide file tree
Showing 10 changed files with 87 additions and 89 deletions.
34 changes: 14 additions & 20 deletions src/components/HSwitchFeedBackModal.res
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,38 @@ let make = (
~modalType: HSwitchFeedBackModalUtils.modalType=FeedBackModal,
) => {
open HSwitchFeedBackModalUtils
open APIUtils
let hyperswitchMixPanel = HSMixPanel.useSendEvent()
let url = RescriptReactRouter.useUrl()
let fetchApi = APIUtils.useUpdateMethod()
let showToast = ToastState.useShowToast()
let updateDetails = useUpdateMethod()

let onSubmit = (values, _) => {
let body = values->HSwitchUtils.getBodyForFeedBack(~modalType, ())

let onSubmit = async (values, _) => {
let mixPanelAction = switch modalType {
| FeedBackModal => "givefeedback"
| RequestConnectorModal => "request_connector"
}

["global", url.path->LogicUtils.getListHead]->Js.Array2.forEach(ele =>
hyperswitchMixPanel(~pageName=ele, ~contextName=feedbackVia, ~actionName=mixPanelAction, ())
)

open Promise

fetchApi(
APIUtils.getURL(~entityName=FEEDBACK, ~methodType=Post, ()),
body->Js.Json.object_,
Fetch.Post,
)
->thenResolve(_ => {
try {
let url = getURL(~entityName=USERS, ~userType=#USER_DATA, ~methodType=Post, ())
let body =
[
("Feedback", values->HSwitchUtils.getBodyForFeedBack(~modalType, ())->Js.Json.object_),
]->LogicUtils.getJsonFromArrayOfJson
let _res = await updateDetails(url, body, Post)
let successMessage = switch modalType {
| FeedBackModal => "Thanks for feedback"
| RequestConnectorModal => "Request submitted succesfully"
}
showToast(~toastType=ToastSuccess, ~message=successMessage, ~autoClose=false, ())
})
->catch(_ => {
resolve()
})
->ignore

} catch {
| _ => ()
}
setShowModal(_ => false)
Js.Nullable.null->resolve
Js.Nullable.null
}

let showLabel = switch modalType {
Expand Down
17 changes: 2 additions & 15 deletions src/screens/HyperSwitch/APIUtils/APIUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -150,19 +150,6 @@ let getURL = (
| PAYMENT_REPORT => `${HSwitchGlobalVars.hyperSwitchApiPrefix}/analytics/v1/report/payments`
| REFUND_REPORT => `${HSwitchGlobalVars.hyperSwitchApiPrefix}/analytics/v1/report/refunds`
| DISPUTE_REPORT => `${HSwitchGlobalVars.hyperSwitchApiPrefix}/analytics/v1/report/dispute`
| PROD_VERIFY =>
switch methodType {
| Put
| Post
| Get =>
`${HSwitchGlobalVars.hyperSwitchApiPrefix}/prodintent`
| _ => ""
}
| FEEDBACK =>
switch methodType {
| Post => `${HSwitchGlobalVars.hyperSwitchApiPrefix}/feedback`
| _ => ""
}
| PAYMENT_LOGS =>
switch methodType {
| Get =>
Expand All @@ -180,15 +167,15 @@ let getURL = (
switch userType {
| #NONE => ""
| #CONNECT_ACCOUNT => `${userUrl}/connect_account`
| #VERIFY_MAGIC_LINK => `${userUrl}/signin/verify`
| #VERIFY_MAGIC_LINK => `${userUrl}/verify_email`
| #SIGNUP => `${userUrl}/signup`

| #SIGNIN => `${userUrl}/signin`

| #VERIFY_EMAIL => `${userUrl}/${(userType :> string)->Js.String2.toLowerCase}`

| #USER_DATA => `${userUrl}/data`
| #MERCHANT_DATA => `${userUrl}/data/merchant`
| #MERCHANT_DATA => `${userUrl}/data`
| #INVITE
| #RESEND_INVITE =>
`${userUrl}/user/${(userType :> string)->Js.String2.toLowerCase}`
Expand Down
2 changes: 0 additions & 2 deletions src/screens/HyperSwitch/APIUtils/APIUtilsTypes.res
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ type entityName =
| ORDERS
| DEFAULT_FALLBACK
| CHANGE_PASSWORD
| PROD_VERIFY
| FEEDBACK
| ANALYTICS_SYSTEM_METRICS
| PAYMENT_LOGS
| SDK_EVENT_LOGS
Expand Down
7 changes: 1 addition & 6 deletions src/screens/HyperSwitch/HSwitchUtils.res
Original file line number Diff line number Diff line change
Expand Up @@ -181,13 +181,8 @@ let getBodyForFeedBack = (values, ~modalType=HSwitchFeedBackModalUtils.FeedBackM
let email = getFromMerchantDetails("email")
let valueDict = values->getDictFromJsonObject
let rating = valueDict->getInt("rating", 1)
let timestamp =
Js.Date.now()
->Js.Date.fromFloat
->Js.Date.toISOString
->TimeZoneHook.formattedISOString("YYYY-MM-DD hh:mm:ss")

let bodyFields = [("created_at", timestamp->Js.Json.string), ("email", email->Js.Json.string)]
let bodyFields = [("email", email->Js.Json.string)]

switch modalType {
| FeedBackModal =>
Expand Down
17 changes: 12 additions & 5 deletions src/screens/HyperSwitch/Home/ProdIntent/ProdIntentForm.res
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,24 @@ let make = (~isFromMilestoneCard=false) => {
let getProdVerifyDetails = async () => {
open LogicUtils
try {
let url = getURL(~entityName=PROD_VERIFY, ~methodType=Fetch.Get, ())
let url = `${getURL(
~entityName=USERS,
~userType=#USER_DATA,
~methodType=Get,
(),
)}?keys=ProdIntent`
let res = await fetchDetails(url)
let valueDict = res->getDictFromJsonObject->getDictfromDict("response")
let hideHeader = valueDict->getBool(IsCompleted->getStringFromVariant, false)
let firstValueFromArray = res->getArrayFromJson([])->getValueFromArray(0, Js.Json.null)
let valueForProdIntent =
firstValueFromArray->getDictFromJsonObject->getDictfromDict("ProdIntent")
let hideHeader = valueForProdIntent->getBool(IsCompleted->getStringFromVariant, false)
setIsProdIntentCompleted(_ => hideHeader)
if !hideHeader {
valueDict->Js.Dict.set(POCemail->getStringFromVariant, email->Js.Json.string)
valueForProdIntent->Js.Dict.set(POCemail->getStringFromVariant, email->Js.Json.string)
} else if !integrationDetails.account_activation.is_done {
markAsDone()->ignore
}
setInitialValues(_ => valueDict)
setInitialValues(_ => valueForProdIntent)
} catch {
| _ => ()
}
Expand Down
5 changes: 3 additions & 2 deletions src/screens/HyperSwitch/Home/ProdIntent/ProdVerifyModal.res
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ let make = (~showModal, ~setShowModal, ~initialValues=Js.Dict.empty(), ~getProdV

let updateProdDetails = async values => {
try {
let url = getURL(~entityName=PROD_VERIFY, ~methodType=Fetch.Post, ())
let body = values->getBody->Js.Json.object_
let url = getURL(~entityName=USERS, ~userType=#USER_DATA, ~methodType=Post, ())
let bodyValues = values->getBody->Js.Json.object_
let body = [("ProdIntent", bodyValues)]->LogicUtils.getJsonFromArrayOfJson
let _ = await updateDetails(url, body, Post)
showToast(
~toastType=ToastSuccess,
Expand Down
24 changes: 17 additions & 7 deletions src/screens/HyperSwitch/Home/QuickStart/GoLive.res
Original file line number Diff line number Diff line change
Expand Up @@ -63,27 +63,37 @@ let make = (~goLive) => {
let getProdVerifyDetails = async () => {
open LogicUtils
try {
let url = getURL(~entityName=PROD_VERIFY, ~methodType=Fetch.Get, ())
let url = `${getURL(
~entityName=USERS,
~userType=#USER_DATA,
~methodType=Get,
(),
)}?keys=ProdIntent`
let res = await fetchDetails(url)
let valueDict = res->getDictFromJsonObject->getDictfromDict("response")
let hideHeader = valueDict->getBool(IsCompleted->getStringFromVariant, false)

let firstValueFromArray = res->getArrayFromJson([])->getValueFromArray(0, Js.Json.null)
let valueForProdIntent =
firstValueFromArray->getDictFromJsonObject->getDictfromDict("ProdIntent")
let hideHeader = valueForProdIntent->getBool(IsCompleted->getStringFromVariant, false)
setIsProdIntentCompleted(_ => hideHeader)
if !hideHeader {
valueDict->Js.Dict.set(POCemail->getStringFromVariant, email->Js.Json.string)
valueForProdIntent->Js.Dict.set(POCemail->getStringFromVariant, email->Js.Json.string)
} else if !integrationDetails.account_activation.is_done {
markAsDone()->ignore
}
setInitialValues(_ => valueDict)
setInitialValues(_ => valueForProdIntent)
} catch {
| _ => ()
}
}

let updateProdDetails = async values => {
try {
let url = getURL(~entityName=PROD_VERIFY, ~methodType=Fetch.Post, ())
let body = values->getBody->Js.Json.object_
let url = getURL(~entityName=USERS, ~userType=#USER_DATA, ~methodType=Post, ())
let bodyValues = values->getBody->Js.Json.object_
let body = [("ProdIntent", bodyValues)]->LogicUtils.getJsonFromArrayOfJson
let _ = await updateDetails(url, body, Post)

getProdVerifyDetails()->ignore
markAsDone()->ignore
} catch {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ module RequestPage = {

let handleSubmitRequest = async () => {
try {
let url = getURL(~entityName=FEEDBACK, ~methodType=Post, ())
let body =
let url = getURL(~entityName=USERS, ~userType=#USER_DATA, ~methodType=Post, ())
let requestedBody =
[
("rating", 5.0->Js.Json.number),
("category", "Platform Request"->Js.Json.string),
Expand All @@ -23,6 +23,7 @@ module RequestPage = {
->HSwitchUtils.getBodyForFeedBack()
->Js.Json.object_

let body = [("Feedback", requestedBody)]->LogicUtils.getJsonFromArrayOfJson
let _ = await updateDetails(url, body, Post)
showToast(
~toastType=ToastSuccess,
Expand Down
16 changes: 11 additions & 5 deletions src/screens/HyperSwitch/Routing/ActiveRouting.res
Original file line number Diff line number Diff line change
Expand Up @@ -34,18 +34,24 @@ module ActionButtons = {

let handleSubmitRequest = async _ => {
try {
let requestBody =
let requestedBody =
[
("rating", 5.0->Js.Json.number),
("category", "Routing request"->Js.Json.string),
("feedbacks", `Request for Cost based Routing`->Js.Json.string),
]
->Js.Dict.fromArray
->LogicUtils.getJsonFromArrayOfJson
->HSwitchUtils.getBodyForFeedBack()
->Js.Json.object_

let body = requestBody->HSwitchUtils.getBodyForFeedBack()
let feedbackUrl = APIUtils.getURL(~entityName=FEEDBACK, ~methodType=Post, ())
let _ = await updateDetails(feedbackUrl, body->Js.Json.object_, Post)
let feedbackUrl = APIUtils.getURL(
~entityName=USERS,
~userType=#USER_DATA,
~methodType=Post,
(),
)
let body = [("Feedback", requestedBody)]->LogicUtils.getJsonFromArrayOfJson
let _ = await updateDetails(feedbackUrl, body, Post)
showToast(
~toastType=ToastSuccess,
~message="Request submitted successfully!",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,41 @@ module RequestPage = {
let make = (~requestedPlatform, ~currentRoute) => {
open UserOnboardingTypes
open UserOnboardingUtils
open APIUtils

let requestedValue =
requestedPlatform->Belt.Option.getWithDefault("")->LogicUtils.capitalizeString
let (isSubmitButtonEnabled, setIsSubmitButtonEnabled) = React.useState(_ => true)
let fetchApi = APIUtils.useUpdateMethod()
let showToast = ToastState.useShowToast()
let handleSubmitRequest = () => {
open Promise
let requestBody =
[
("rating", 5.0->Js.Json.number),
("category", "Platform Request"->Js.Json.string),
("feedbacks", `Request for ${requestedValue}`->Js.Json.string),
]
->Js.Dict.fromArray
->Js.Json.object_
let updateDetails = useUpdateMethod()

let body = requestBody->HSwitchUtils.getBodyForFeedBack()
fetchApi(
APIUtils.getURL(~entityName=FEEDBACK, ~methodType=Post, ()),
body->Js.Json.object_,
Fetch.Post,
)
->thenResolve(_ => {
let handleSubmitRequest = async () => {
try {
let url = getURL(~entityName=USERS, ~userType=#USER_DATA, ~methodType=Post, ())
let requestedBody =
[
("rating", 5.0->Js.Json.number),
("category", "Platform Request"->Js.Json.string),
("feedbacks", `Request for ${requestedValue}`->Js.Json.string),
]
->LogicUtils.getJsonFromArrayOfJson
->HSwitchUtils.getBodyForFeedBack()
->Js.Json.object_

let body = [("Feedback", requestedBody)]->LogicUtils.getJsonFromArrayOfJson
let _res = await updateDetails(url, body, Post)
showToast(
~toastType=ToastSuccess,
~message="Request submitted successfully!",
~autoClose=false,
(),
)
setIsSubmitButtonEnabled(_ => false)
})
->catch(_ => {
resolve()
})
->ignore
} catch {
| _ => ()
}
}

React.useEffect1(() => {
setIsSubmitButtonEnabled(_ => true)
None
Expand All @@ -53,9 +52,9 @@ module RequestPage = {
Window._open("https://hyperswitch.io/docs/migrateFromStripe/migrateFromStripeAndroid")
| #ReactNative =>
Window._open("https://hyperswitch.io/docs/migrateFromStripe/migrateFromStripeRN")
| _ => handleSubmitRequest()
| _ => handleSubmitRequest()->ignore
}
| _ => handleSubmitRequest()
| _ => handleSubmitRequest()->ignore
}
}
let buttonText = () => {
Expand Down

0 comments on commit 136d067

Please sign in to comment.