Fix: Multi User Invite (#208)

- Use updated API structure
- Use single API to invite multiple users instead of looping.

Co-authored-by: Tejaaswini <tejaaswini.narendra@codemonk.in>
This commit is contained in:
Trisha Anand 2020-08-11 09:24:36 +05:30 committed by GitHub
parent d2442eb815
commit 9d78b020bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 20 additions and 23 deletions

View File

@ -100,7 +100,6 @@ class UserApi extends Api {
}
static inviteUser(request: InviteUserRequest): AxiosPromise<ApiResponse> {
request.status = "INVITED";
return Api.post(UserApi.inviteUserURL, request);
}

View File

@ -56,7 +56,7 @@ export const inviteUsersToOrgSubmitHandler = (
export const inviteUsersToOrg = (values: any, dispatch: any): Promise<any> => {
const data = {
roleName: values.role,
emails: values.users ? values.users.split(",") : [],
usernames: values.users ? values.users.split(",") : [],
orgId: values.orgId,
};
return new Promise((resolve, reject) => {

View File

@ -72,6 +72,13 @@ const orgReducer = createReducer(initialState, {
isFetchAllUsers: false,
},
}),
[ReduxActionTypes.INVITE_USERS_TO_ORG_SUCCESS]: (
state: OrgReduxState,
action: ReduxAction<OrgUser[]>,
) => ({
...state,
orgUsers: [...state.orgUsers, ...action.payload],
}),
[ReduxActionTypes.FETCH_ALL_ROLES_SUCCESS]: (
state: OrgReduxState,
action: ReduxAction<Org[]>,

View File

@ -210,34 +210,25 @@ export function* inviteUser(
export function* inviteUsers(
action: ReduxActionWithPromise<{
data: { emails: string[]; orgId: string; roleName: string };
data: { usernames: string[]; orgId: string; roleName: string };
}>,
) {
const { data, resolve, reject } = action.payload;
try {
const sagasToCall: any[] = [];
data.emails.forEach((email: string) => {
sagasToCall.push(
call(
inviteUser,
{ email, orgId: data.orgId, roleName: data.roleName },
reject,
),
);
const response: ApiResponse = yield callAPI(UserApi.inviteUser, {
usernames: data.usernames,
orgId: data.orgId,
roleName: data.roleName,
});
yield all(sagasToCall);
const isValidResponse = yield validateResponse(response);
if (!isValidResponse) {
let errorMessage = `${data.usernames}: `;
errorMessage += getResponseErrorMessage(response);
yield call(reject, { _error: errorMessage });
}
yield put({
type: ReduxActionTypes.INVITE_USERS_TO_ORG_SUCCESS,
payload: {
inviteCount: sagasToCall.length,
},
});
yield put({
type: ReduxActionTypes.FETCH_ALL_USERS_INIT,
payload: {
orgId: data.orgId,
},
payload: response.data,
});
yield call(resolve);
yield put(reset(INVITE_USERS_TO_ORG_FORM));