From 940f69de80fafa0b4b48d6b89a511410d9c5a2a6 Mon Sep 17 00:00:00 2001 From: Pritish Budhiraja <1805317@kiit.ac.in> Date: Wed, 14 Feb 2024 18:01:32 +0530 Subject: [PATCH 01/12] feat: Delete user added --- .env | 2 +- src/screens/HyperSwitch/APIUtils/APIUtils.res | 1 + .../HyperSwitch/APIUtils/APIUtilsTypes.res | 1 + .../UserManagement/ShowUserData.res | 91 +++++++++++++++++-- .../UserManagement/UserRoleEntity.res | 2 - 5 files changed, 85 insertions(+), 12 deletions(-) diff --git a/.env b/.env index ad42dae28..8acc5a320 100644 --- a/.env +++ b/.env @@ -1,3 +1,3 @@ -apiBaseUrl=https://sandbox.hyperswitch.io +apiBaseUrl=https://integ-api.hyperswitch.io sdkBaseUrl=https://beta.hyperswitch.io/v1/HyperLoader.js mixpanelToken= \ No newline at end of file diff --git a/src/screens/HyperSwitch/APIUtils/APIUtils.res b/src/screens/HyperSwitch/APIUtils/APIUtils.res index 1c602ba4c..753eaae4c 100644 --- a/src/screens/HyperSwitch/APIUtils/APIUtils.res +++ b/src/screens/HyperSwitch/APIUtils/APIUtils.res @@ -171,6 +171,7 @@ let getURL = ( | _ => `${userUrl}/${(userType :> string)->String.toLowerCase}` } | #GET_PERMISSIONS => `${userUrl}/role` + | #USER_DELETE => `${userUrl}/user/delete` | #SIGNINV2 => `${userUrl}/v2/signin` | #VERIFY_EMAILV2 => `${userUrl}/v2/verify_email` | #ACCEPT_INVITE => `${userUrl}/user/invite/accept` diff --git a/src/screens/HyperSwitch/APIUtils/APIUtilsTypes.res b/src/screens/HyperSwitch/APIUtils/APIUtilsTypes.res index 2433e5306..3358b155b 100644 --- a/src/screens/HyperSwitch/APIUtils/APIUtilsTypes.res +++ b/src/screens/HyperSwitch/APIUtils/APIUtilsTypes.res @@ -59,6 +59,7 @@ type userType = [ | #MERCHANT_DATA | #USER_DATA | #INVITE + | #USER_DELETE | #INVITE_MULTIPLE | #RESEND_INVITE | #CREATE_MERCHANT diff --git a/src/screens/HyperSwitch/UserManagement/ShowUserData.res b/src/screens/HyperSwitch/UserManagement/ShowUserData.res index 410580c18..33f822975 100644 --- a/src/screens/HyperSwitch/UserManagement/ShowUserData.res +++ b/src/screens/HyperSwitch/UserManagement/ShowUserData.res @@ -4,6 +4,76 @@ external typeConversion: array> => arr UserRoleEntity.userTableTypes, > = "%identity" +module UserUtilsPopover = { + @react.component + let make = (~infoValue: UserRoleEntity.userTableTypes) => { + open HeadlessUI + open APIUtils + + let updateDetails = useUpdateMethod() + let showToast = ToastState.useShowToast() + + let deleteUser = async () => { + try { + let url = getURL(~entityName=USERS, ~methodType=Post, ~userType={#USER_DELETE}, ()) + let body = + [("email", infoValue.email->JSON.Encode.string)]->LogicUtils.getJsonFromArrayOfJson + let _ = await updateDetails(url, body, Delete, ()) + showToast(~message=`User has been successfully deleted.`, ~toastType=ToastSuccess, ()) + RescriptReactRouter.replace("/users") + } catch { + | _ => () + } + } + + + {popoverProps => <> + + {buttonProps => } + + + + {panelProps => { +
+ { + panelProps["close"]() + }} + /> + + { + deleteUser()->ignore + }} + /> + +
+ }} +
+
+ } +
+ } +} + module UserHeading = { @react.component let make = (~infoValue: UserRoleEntity.userTableTypes) => { @@ -42,15 +112,18 @@ module UserHeading = { | _ => infoValue.status->String.toUpperCase->React.string }} - -