Skip to content

Commit

Permalink
chore: refactoring invite users
Browse files Browse the repository at this point in the history
  • Loading branch information
Pritish Budhiraja committed Jan 17, 2024
1 parent 684419d commit 73abc6a
Showing 1 changed file with 25 additions and 36 deletions.
61 changes: 25 additions & 36 deletions src/screens/HyperSwitch/UserManagement/InviteUsers.res
Original file line number Diff line number Diff line change
Expand Up @@ -88,15 +88,10 @@ let make = () => {
->Js.Json.object_
})

let inviteUserReq = (body, emailPasswordsArray) => {
// try {
let inviteUserReq = body => {
let url = getURL(~entityName=USERS, ~userType=#INVITE, ~methodType=Post, ())
let response = updateDetails(url, body, Post)

response
// } catch {
// | _ => Js.Json.null
// }
}

let inviteListOfUsers = async values => {
Expand All @@ -105,40 +100,34 @@ let make = () => {
}
let valDict = values->getDictFromJsonObject
let role = valDict->getStrArray("roleType")->LogicUtils.getValueFromArray(0, "")
let emailList = valDict->getStrArray("emailList")
let emailPasswordsArray = []

let arrayOfPromises =
valDict
->getStrArray("emailList")
->Array.map(ele => {
let body =
[
("email", ele->String.toLowerCase->Js.Json.string),
("name", ele->getNameFromEmail->Js.Json.string),
("role_id", role->Js.Json.string),
]->LogicUtils.getJsonFromArrayOfJson
inviteUserReq(body, emailPasswordsArray)
})
let arrayOfPromises = emailList->Array.map(ele => {
let body =
[
("email", ele->String.toLowerCase->Js.Json.string),
("name", ele->getNameFromEmail->Js.Json.string),
("role_id", role->Js.Json.string),
]->LogicUtils.getJsonFromArrayOfJson
inviteUserReq(body)
})

let response = await PromiseUtils.allSettledPolyfill(arrayOfPromises)
Js.log(response)
if !magicLink {
response->Array.forEachWithIndex((ele, index) => {
if ele !== Js.Json.null {
let passwordFromResponse = ele->getDictFromJsonObject->getString("password", "")
emailPasswordsArray->Array.push(
[
("email", emailList[index]->Option.getWithDefault("")->Js.Json.string),
("password", passwordFromResponse->Js.Json.string),
]->LogicUtils.getJsonFromArrayOfJson,
)
}
})
}

// Js.log2(res, "res")/
// if !magicLink {
// let passwordFromResponse = response->getDictFromJsonObject->getString("password", "")
// emailPasswordsArray->Array.push(
// [
// (
// "email",
// body
// ->LogicUtils.getDictFromJsonObject
// ->LogicUtils.getString("email", "")
// ->Js.Json.string,
// ),
// ("password", passwordFromResponse->Js.Json.string),
// ]->LogicUtils.getJsonFromArrayOfJson,
// )
// }
showToast(
~message=magicLink
? `Invite(s) sent successfully via Email`
Expand All @@ -147,7 +136,7 @@ let make = () => {
(),
)

if !magicLink {
if !magicLink && emailPasswordsArray->Array.length > 0 {
DownloadUtils.download(
~fileName=`invited-users.txt`,
~content=emailPasswordsArray->Js.Json.array->Js.Json.stringifyWithSpace(3),
Expand Down

0 comments on commit 73abc6a

Please sign in to comment.