diff --git a/src/screens/HyperSwitch/UserManagement/InviteUsers.res b/src/screens/HyperSwitch/UserManagement/InviteUsers.res index 5391dae3f..107e5c11f 100644 --- a/src/screens/HyperSwitch/UserManagement/InviteUsers.res +++ b/src/screens/HyperSwitch/UserManagement/InviteUsers.res @@ -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 => { @@ -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` @@ -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),