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

chore: invite users enhancement #1964

Merged
merged 4 commits into from
Jan 2, 2025
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
45 changes: 42 additions & 3 deletions src/screens/UserManagement/UserRevamp/UserManagementHelper.res
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ module MerchantSelection = {
let internalSwitch = OMPSwitchHooks.useInternalSwitch()
let merchList = Recoil.useRecoilValueFromAtom(HyperswitchAtom.merchantListAtom)
let {userInfo: {userEntity}} = React.useContext(UserInfoProvider.defaultContext)
let (showSwitchingMerchant, setShowSwitchingMerchant) = React.useState(_ => false)

let disableSelect = switch userEntity {
| #Merchant | #Profile => true
Expand All @@ -68,8 +69,11 @@ module MerchantSelection = {
try {
let selectedMerchantValue = event->Identity.formReactEventToString
if selectedMerchantValue->stringToVariantForAllSelection->Option.isNone {
setShowSwitchingMerchant(_ => true)
let _ = await internalSwitch(~expectedMerchantId=Some(selectedMerchantValue))
setShowSwitchingMerchant(_ => false)
}

input.onChange(event)
} catch {
| _ => showToast(~message="Something went wrong. Please try again", ~toastType=ToastError)
Expand Down Expand Up @@ -102,7 +106,15 @@ module MerchantSelection = {
~placeholder="Select a merchant",
),
)
<FormRenderer.FieldRenderer field labelClass="font-semibold" />

<>
<FormRenderer.FieldRenderer field labelClass="font-semibold" />
<LoaderModal
showModal={showSwitchingMerchant}
setShowModal={setShowSwitchingMerchant}
text="Switching merchant..."
/>
</>
}
}

Expand All @@ -117,6 +129,23 @@ module ProfileSelection = {
let formState: ReactFinalForm.formState = ReactFinalForm.useFormState(
ReactFinalForm.useFormSubscription(["values"])->Nullable.make,
)
let (showSwitchingProfile, setShowSwitchingProfile) = React.useState(_ => false)

React.useEffect(() => {
switch userEntity {
| #Tenant
| #Organization
| #Merchant =>
form.change(
"profile_value",
(#All_Profiles: UserManagementTypes.allSelectionType :> string)
->String.toLowerCase
->JSON.Encode.string,
)
| #Profile => ()
}
None
}, [])

let disableSelect = switch userEntity {
| #Profile => true
Expand Down Expand Up @@ -147,8 +176,11 @@ module ProfileSelection = {
let selectedProfileValue = event->Identity.formReactEventToString

if selectedProfileValue->stringToVariantForAllSelection->Option.isNone {
setShowSwitchingProfile(_ => true)
let _ = await internalSwitch(~expectedProfileId=Some(selectedProfileValue))
setShowSwitchingProfile(_ => false)
}

input.onChange(event)
} catch {
| _ => showToast(~message="Something went wrong. Please try again", ~toastType=ToastError)
Expand Down Expand Up @@ -182,7 +214,14 @@ module ProfileSelection = {
),
)

<FormRenderer.FieldRenderer field labelClass="font-semibold" />
<>
<FormRenderer.FieldRenderer field labelClass="font-semibold" />
<LoaderModal
showModal={showSwitchingProfile}
setShowModal={setShowSwitchingProfile}
text="Switching profile..."
/>
</>
}
}

Expand Down Expand Up @@ -275,7 +314,7 @@ module UserOmpView = {
let options = views->generateDropdownOptionsUserOMPViews(getNameForId)

let displayName = switch selectedEntity {
| #Default => "My Team"
| #Default => "All"
| _ => selectedEntity->getNameForId
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ let getUserManagementViewValues = (~checkUserEntity) => {
entity: #Profile,
}
let default = {
label: "My Team",
label: "All",
entity: #Default,
}

Expand Down
Loading