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

Create personal detail optimistic data when inviting member to the room #32788

Merged
merged 3 commits into from
Dec 12, 2023
Merged
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
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
Loading