From 136d067982b1a929ed6e9b3b84aaac1eb3e7aca6 Mon Sep 17 00:00:00 2001 From: Riddhi Agrawal Date: Tue, 12 Dec 2023 12:00:46 +0530 Subject: [PATCH] fix: url changes for feedback and prodintent --- src/components/HSwitchFeedBackModal.res | 34 ++++++------- src/screens/HyperSwitch/APIUtils/APIUtils.res | 17 +------ .../HyperSwitch/APIUtils/APIUtilsTypes.res | 2 - src/screens/HyperSwitch/HSwitchUtils.res | 7 +-- .../Home/ProdIntent/ProdIntentForm.res | 17 +++++-- .../Home/ProdIntent/ProdVerifyModal.res | 5 +- .../HyperSwitch/Home/QuickStart/GoLive.res | 24 ++++++--- .../IntegrateYourApp/IntegrationDocsPage.res | 5 +- .../HyperSwitch/Routing/ActiveRouting.res | 16 ++++-- .../IntegrationDocs.res | 49 +++++++++---------- 10 files changed, 87 insertions(+), 89 deletions(-) diff --git a/src/components/HSwitchFeedBackModal.res b/src/components/HSwitchFeedBackModal.res index 3f0d34443..bab2a2d52 100644 --- a/src/components/HSwitchFeedBackModal.res +++ b/src/components/HSwitchFeedBackModal.res @@ -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 { diff --git a/src/screens/HyperSwitch/APIUtils/APIUtils.res b/src/screens/HyperSwitch/APIUtils/APIUtils.res index 8b2b0a8d7..5794864ab 100644 --- a/src/screens/HyperSwitch/APIUtils/APIUtils.res +++ b/src/screens/HyperSwitch/APIUtils/APIUtils.res @@ -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 => @@ -180,7 +167,7 @@ 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` @@ -188,7 +175,7 @@ let getURL = ( | #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}` diff --git a/src/screens/HyperSwitch/APIUtils/APIUtilsTypes.res b/src/screens/HyperSwitch/APIUtils/APIUtilsTypes.res index 199c32ee6..3994dbf07 100644 --- a/src/screens/HyperSwitch/APIUtils/APIUtilsTypes.res +++ b/src/screens/HyperSwitch/APIUtils/APIUtilsTypes.res @@ -14,8 +14,6 @@ type entityName = | ORDERS | DEFAULT_FALLBACK | CHANGE_PASSWORD - | PROD_VERIFY - | FEEDBACK | ANALYTICS_SYSTEM_METRICS | PAYMENT_LOGS | SDK_EVENT_LOGS diff --git a/src/screens/HyperSwitch/HSwitchUtils.res b/src/screens/HyperSwitch/HSwitchUtils.res index 0f1fc990b..5a67af218 100644 --- a/src/screens/HyperSwitch/HSwitchUtils.res +++ b/src/screens/HyperSwitch/HSwitchUtils.res @@ -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 => diff --git a/src/screens/HyperSwitch/Home/ProdIntent/ProdIntentForm.res b/src/screens/HyperSwitch/Home/ProdIntent/ProdIntentForm.res index b64d72e77..baff45a82 100644 --- a/src/screens/HyperSwitch/Home/ProdIntent/ProdIntentForm.res +++ b/src/screens/HyperSwitch/Home/ProdIntent/ProdIntentForm.res @@ -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 { | _ => () } diff --git a/src/screens/HyperSwitch/Home/ProdIntent/ProdVerifyModal.res b/src/screens/HyperSwitch/Home/ProdIntent/ProdVerifyModal.res index 67e579e02..cab3d0388 100644 --- a/src/screens/HyperSwitch/Home/ProdIntent/ProdVerifyModal.res +++ b/src/screens/HyperSwitch/Home/ProdIntent/ProdVerifyModal.res @@ -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, diff --git a/src/screens/HyperSwitch/Home/QuickStart/GoLive.res b/src/screens/HyperSwitch/Home/QuickStart/GoLive.res index 43b791432..3aa55004e 100644 --- a/src/screens/HyperSwitch/Home/QuickStart/GoLive.res +++ b/src/screens/HyperSwitch/Home/QuickStart/GoLive.res @@ -63,17 +63,25 @@ 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 { | _ => () } @@ -81,9 +89,11 @@ let make = (~goLive) => { 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 { diff --git a/src/screens/HyperSwitch/Home/QuickStart/IntegrateYourApp/IntegrationDocsPage.res b/src/screens/HyperSwitch/Home/QuickStart/IntegrateYourApp/IntegrationDocsPage.res index 99711f4d3..95037f37b 100644 --- a/src/screens/HyperSwitch/Home/QuickStart/IntegrateYourApp/IntegrationDocsPage.res +++ b/src/screens/HyperSwitch/Home/QuickStart/IntegrateYourApp/IntegrationDocsPage.res @@ -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), @@ -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, diff --git a/src/screens/HyperSwitch/Routing/ActiveRouting.res b/src/screens/HyperSwitch/Routing/ActiveRouting.res index 4df1fb67c..d07e2996d 100644 --- a/src/screens/HyperSwitch/Routing/ActiveRouting.res +++ b/src/screens/HyperSwitch/Routing/ActiveRouting.res @@ -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!", diff --git a/src/screens/HyperSwitch/SelfServe/HSwitchSandboxOnboarding/IntegrationDocs.res b/src/screens/HyperSwitch/SelfServe/HSwitchSandboxOnboarding/IntegrationDocs.res index 537cefbf0..9c89b1f9e 100644 --- a/src/screens/HyperSwitch/SelfServe/HSwitchSandboxOnboarding/IntegrationDocs.res +++ b/src/screens/HyperSwitch/SelfServe/HSwitchSandboxOnboarding/IntegrationDocs.res @@ -3,29 +3,29 @@ 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!", @@ -33,12 +33,11 @@ module RequestPage = { (), ) setIsSubmitButtonEnabled(_ => false) - }) - ->catch(_ => { - resolve() - }) - ->ignore + } catch { + | _ => () + } } + React.useEffect1(() => { setIsSubmitButtonEnabled(_ => true) None @@ -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 = () => {