Skip to content

Commit

Permalink
Merge pull request #32788 from dukenv0307/fix/32712
Browse files Browse the repository at this point in the history
Create personal detail optimistic data when inviting member to the room
  • Loading branch information
roryabraham authored Dec 12, 2023
2 parents 742de75 + 2c034f8 commit a3354d7
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/libs/actions/Report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Log from '@libs/Log';
import Navigation from '@libs/Navigation/Navigation';
import LocalNotification from '@libs/Notification/LocalNotification';
import {ReportCommentParams} from '@libs/Notification/LocalNotification/types';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';
import * as Pusher from '@libs/Pusher/pusher';
import * as ReportActionsUtils from '@libs/ReportActionsUtils';
Expand Down Expand Up @@ -2126,11 +2127,19 @@ function inviteToRoom(reportID: string, inviteeEmailsToAccountIDs: Record<string

const inviteeEmails = Object.keys(inviteeEmailsToAccountIDs);
const inviteeAccountIDs = Object.values(inviteeEmailsToAccountIDs);

const participantAccountIDsAfterInvitation = [...new Set([...(report?.participantAccountIDs ?? []), ...inviteeAccountIDs])].filter(
(accountID): accountID is number => typeof accountID === 'number',
);

type PersonalDetailsOnyxData = {
optimisticData: OnyxUpdate[];
successData: OnyxUpdate[];
failureData: OnyxUpdate[];
};

const logins = inviteeEmails.map((memberLogin) => OptionsListUtils.addSMSDomainIfPhoneNumber(memberLogin));
const newPersonalDetailsOnyxData = PersonalDetailsUtils.getNewPersonalDetailsOnyxData(logins, inviteeAccountIDs) as PersonalDetailsOnyxData;

const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -2139,8 +2148,11 @@ function inviteToRoom(reportID: string, inviteeEmailsToAccountIDs: Record<string
participantAccountIDs: participantAccountIDsAfterInvitation,
},
},
...newPersonalDetailsOnyxData.optimisticData,
];

const successData: OnyxUpdate[] = newPersonalDetailsOnyxData.successData;

const failureData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
Expand All @@ -2149,6 +2161,7 @@ function inviteToRoom(reportID: string, inviteeEmailsToAccountIDs: Record<string
participantAccountIDs: report.participantAccountIDs,
},
},
...newPersonalDetailsOnyxData.failureData,
];

type InviteToRoomParameters = {
Expand All @@ -2161,7 +2174,7 @@ function inviteToRoom(reportID: string, inviteeEmailsToAccountIDs: Record<string
inviteeEmails,
};

API.write('InviteToRoom', parameters, {optimisticData, failureData});
API.write('InviteToRoom', parameters, {optimisticData, successData, failureData});
}

/** Removes people from a room */
Expand Down

0 comments on commit a3354d7

Please sign in to comment.