Skip to content

[HOLD for payment 2024-03-19] [$500] Members – Member invited in offline is not grayed out on Announce room members list #34671

Closed

Description

@lanitochka17

If you haven’t already, check out our contributing guidelines for onboarding and email contributors@expensify.com to request to join our Slack channel!


Version Number: 1.4.26-1
Reproducible in staging?: Y
Reproducible in production?: Y
If this was caught during regression testing, add the test name, ID and link from TestRail:
Email or phone of affected tester (no customers):
Logs: https://stackoverflow.com/c/expensify/questions/4856
Expensify/Expensify Issue URL:
Issue reported by: Applause - Internal Team
Slack conversation:

Action Performed:

  1. Navigate to the Workspace editor
  2. Navigate to the Manage members page.
  3. Disable the internet connection
  4. Click on invite and enter a user address
  5. Select the member and click on invite
  6. Verify the member is added to the list and it's grayed out
  7. Navigate to #announce room> Members

Expected Result:

Added member in offline should be grayed out in Announce room members list

Actual Result:

Member invited in offline mode is not grayed out on Announce room members list

Workaround:

Unknown

Platforms:

Which of our officially supported platforms is this issue occurring on?

  • Android: Native
  • Android: mWeb Chrome
  • iOS: Native
  • iOS: mWeb Safari
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Add any screenshot/video evidence

Bug6345685_1705519343551.Recording__1834.1.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~0115b0aaa09aebec57
  • Upwork Job ID: 1747726949510807552
  • Last Price Increase: 2024-01-24
  • Automatic offers:
    • getusha | Reviewer | 28137400
    • DylanDylann | Contributor | 28137402

Activity

  1. added
    ExternalAdded to denote the issue can be worked on by a contributor
    BugSomething is broken. Auto assigns a BugZero manager.
    on Jan 17, 2024
  2. changed the title [-]Members – Member invited in offline is not grayed out on Announce room members list[/-] [+][$500] Members – Member invited in offline is not grayed out on Announce room members list[/+] on Jan 17, 2024
  3. melvin-bot commented on Jan 17, 2024

    @melvin-bot
  4. melvin-bot commented on Jan 17, 2024

    @melvin-bot

    Triggered auto assignment to @alexpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details.

  5. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on Jan 17, 2024
  6. melvin-bot commented on Jan 17, 2024

    @melvin-bot

    Triggered auto assignment to Contributor-plus team member for initial proposal review - @getusha (External)

  7. Krishna2323 commented on Jan 17, 2024

    @Krishna2323
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    Members – Member invited in offline is not grayed out on Announce room members list

    What is the root cause of that problem?

    We are not adding pendingAction:, in participants data inside ReportParticipantsPage.

    What changes do you think we should make in order to solve the problem?

    We need to use withPolicyAndFullscreenLoading or withPolicy or we can directly subscribe to onyx for getting policyMembers and get the pendingAction boolean of a account id and then pass it to pendingAction: , here:

    function ReportParticipantsPage(props) {
    const styles = useThemeStyles();
    const participants = _.map(getAllParticipants(props.report, props.personalDetails, props.translate), (participant) => ({
    ...participant,
    isDisabled: ReportUtils.isOptimisticPersonalDetail(participant.accountID),
    }));

    We can also add a check for finding if the report is a policy or not.

    We will subscribe to policyMembers using:

            policyMembers: {
                key: (props) => `${ONYXKEYS.COLLECTION.POLICY_MEMBERS}${props.report.policyID}`,
            },
    

    Then we will get the object from policyMembers for each account using participants.accountId:
    const pendingAction = _.get(props.policyMembers, accountId).pendingAction

    Also, when creating a workspace, we don't set pending action for admin, so we need to add a pending action for admin and clear it in the successData.

    App/src/libs/actions/Policy.ts

    Lines 1189 to 1198 in 4b7b8f2

    {
    onyxMethod: Onyx.METHOD.SET,
    key: `${ONYXKEYS.COLLECTION.POLICY_MEMBERS_DRAFTS}${policyID}`,
    value: {
    [sessionAccountID]: {
    role: CONST.POLICY.ROLE.ADMIN,
    errors: {},
    },
    },
    },

    App/src/libs/actions/Policy.ts

    Lines 1249 to 1258 in 4b7b8f2

    {
    onyxMethod: Onyx.METHOD.SET,
    key: `${ONYXKEYS.COLLECTION.POLICY_MEMBERS}${policyID}`,
    value: {
    [sessionAccountID]: {
    role: CONST.POLICY.ROLE.ADMIN,
    errors: {},
    },
    },
    },

    const successData: OnyxUpdate[] = [

    Object to clear pendingAction in successData:

                    {
                        onyxMethod: Onyx.METHOD.MERGE,
                        key: `${ONYXKEYS.COLLECTION.POLICY_MEMBERS}${policyID}`,
                        value: {
                            [sessionAccountID]: {
                                pendingAction: null,
                            },
                        },
                    },

    For room invitation:

    We need to also update onyx for POLICY_MEMBERS when inviting/removing room members, we have the implementation for inviting/removing workspace members, we need to just do the same and the we can get policyMembers data for room policies also. In the code snippet below we can see we update onyx for POLICY_MEMBERS while inviting users to workspace.

    Details

    function addMembersToWorkspace(invitedEmailsToAccountIDs: Record<string, number>, welcomeNote: string, policyID: string) {
    const membersListKey = `${ONYXKEYS.COLLECTION.POLICY_MEMBERS}${policyID}` as const;
    const logins = Object.keys(invitedEmailsToAccountIDs).map((memberLogin) => OptionsListUtils.addSMSDomainIfPhoneNumber(memberLogin));
    const accountIDs = Object.values(invitedEmailsToAccountIDs);
    const newPersonalDetailsOnyxData = PersonalDetailsUtils.getNewPersonalDetailsOnyxData(logins, accountIDs);
    const announceRoomMembers = buildAnnounceRoomMembersOnyxData(policyID, accountIDs);
    // create onyx data for policy expense chats for each new member
    const membersChats = createPolicyExpenseChats(policyID, invitedEmailsToAccountIDs);
    const optimisticMembersState: OnyxCollection<PolicyMember> = {};
    const failureMembersState: OnyxCollection<PolicyMember> = {};
    accountIDs.forEach((accountID) => {
    optimisticMembersState[accountID] = {pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD};
    failureMembersState[accountID] = {
    errors: ErrorUtils.getMicroSecondOnyxError('workspace.people.error.genericAdd'),
    };
    });
    const optimisticData: OnyxUpdate[] = [
    {
    onyxMethod: Onyx.METHOD.MERGE,
    key: membersListKey,
    // Convert to object with each key containing {pendingAction: ‘add’}
    value: optimisticMembersState,
    },
    ...newPersonalDetailsOnyxData.optimisticData,
    ...membersChats.onyxOptimisticData,
    ...announceRoomMembers.onyxOptimisticData,
    ];
    const successData: OnyxUpdate[] = [
    {
    onyxMethod: Onyx.METHOD.MERGE,
    key: membersListKey,
    // Convert to object with each key clearing pendingAction, when it is an existing account.
    // Remove the object, when it is a newly created account.
    value: accountIDs.reduce((accountIDsWithClearedPendingAction, accountID) => {
    let value = null;
    const accountAlreadyExists = !isEmptyObject(allPersonalDetails?.[accountID]);
    if (accountAlreadyExists) {
    value = {pendingAction: null, errors: null};
    }
    return {...accountIDsWithClearedPendingAction, [accountID]: value};
    }, {}),
    },
    ...newPersonalDetailsOnyxData.finallyData,
    ...membersChats.onyxSuccessData,
    ];
    const failureData: OnyxUpdate[] = [
    {
    onyxMethod: Onyx.METHOD.MERGE,
    key: membersListKey,
    // Convert to object with each key containing the error. We don’t
    // need to remove the members since that is handled by onClose of OfflineWithFeedback.
    value: failureMembersState,
    },
    ...newPersonalDetailsOnyxData.finallyData,
    ...membersChats.onyxFailureData,
    ...announceRoomMembers.onyxFailureData,
    ];
    type AddMembersToWorkspaceParams = {
    employees: string;
    welcomeNote: string;
    policyID: string;
    reportCreationData?: string;
    };
    const params: AddMembersToWorkspaceParams = {
    employees: JSON.stringify(logins.map((login) => ({email: login}))),
    welcomeNote: new ExpensiMark().replace(welcomeNote),
    policyID,
    };
    if (!isEmptyObject(membersChats.reportCreationData)) {
    params.reportCreationData = JSON.stringify(membersChats.reportCreationData);
    }
    API.write('AddMembersToWorkspace', params, {optimisticData, successData, failureData});
    }

    We also need to add utilities like below:

    App/src/libs/actions/Policy.ts

    Lines 1052 to 1069 in 6cfdd6f

    function clearAddMemberError(policyID: string, accountID: number) {
    Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY_MEMBERS}${policyID}`, {
    [accountID]: null,
    });
    Onyx.merge(`${ONYXKEYS.PERSONAL_DETAILS_LIST}`, {
    [accountID]: null,
    });
    }
    /**
    * Removes an error after trying to delete a workspace
    */
    function clearDeleteWorkspaceError(policyID: string) {
    Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {
    pendingAction: null,
    errors: null,
    });
    }

    We might need to add some more changes to sync with workspace invite/remove flow but that can be discussed during the PR.

    Result

    room_members_not_grayed_out.mp4
  8. abzokhattab commented on Jan 17, 2024

    @abzokhattab
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    Members – Member invited in offline is not grayed out on Announce room members list

    What is the root cause of that problem?

    if a participant is created in offline mode then there should a pendingAction
    however the getAllParticipants does not return the pendingAction object of each participant ,unlike the workspace members page

    What changes do you think we should make in order to solve the problem?

    so in case the report is a policy report we need to check the pending action of each participant
    this can done by:

    First load the policy members using withOynx:

        policyMembers: {
                key: (props) => `${ONYXKEYS.COLLECTION.POLICY_MEMBERS}${props.report.policyID || '0'}`,
            },

    Then inside the ReportParticipantsPage function, we need to add a new attribute policyMembers:

    Then we need to add the pending action to the returned object of each participant

    const pendingAction = lodashGet(policyMembers, accountID,{}).pendingAction
         return {
                    alternateText: userLogin,
                    displayName,
    +              pendingAction,
                    accountID: userPersonalDetail.accountID,
                    icons: [
                        {
                            id: accountID,
                            source: UserUtils.getAvatar(userPersonalDetail.avatar, accountID),
                            name: userLogin,
                            type: CONST.ICON_TYPE_AVATAR,
                        },
                    ],
                    keyForList: `${index}-${userLogin}`,
                    login: userLogin,
                    text: displayName,
                    tooltipText: userLogin,
                    participantsList: [{accountID, displayName}],
                };

    Result

    image

    also, I refactored the isDeleted logic and added to the getAllParticipants function so that we don't have to loop over the participants list twice.

    you can check all the changes in the following test branch:
    Test Branch

  9. DylanDylann commented on Jan 18, 2024

    @DylanDylann
    Contributor

    Proposal

    Please re-state the problem that we are trying to solve in this issue.

    Member invited in offline mode is not grayed out on Announce room members list

    What is the root cause of that problem?

    In ReportParticipantsPage, we are using visibleChatMemberAccountIDs to display participants.

    When adding new members to workspace, we will add accountID of new members to visibleChatMemberAccountIDs of announce report but we don't add any sign to identify which accountIDs is pending

    ...announceRoomMembers.onyxOptimisticData,

    visibleChatMemberAccountIDs: participantAccountIDs,

    What changes do you think we should make in order to solve the problem?

    We can introduce a new field called pendingVisibleChatMemberAccountIDs when adding new member to the workspace

    visibleChatMemberAccountIDs: participantAccountIDs,

    we will add

    const pendingAccountIDs = accountIDs.map((accountID) => {
                accountID;
                pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD;
            }),   
    const pendingVisibleChatMemberAccountIDs = [...announceReport.pendingVisibleChatMemberAccountIDs, ...pendingAccountIDs]
    announceRoomMembers.onyxOptimisticData.push({
                onyxMethod: Onyx.METHOD.MERGE,
                key: `${ONYXKEYS.COLLECTION.REPORT}${announceReport?.reportID}`,
                value: {
                    participantAccountIDs,
                    visibleChatMemberAccountIDs: participantAccountIDs,
                    pendingVisibleChatMemberAccountIDs
                },
            });
    

    and in successData and failureData we will reset

    pendingVisibleChatMemberAccountIDs: announceReport?.pendingVisibleChatMemberAccountIDs
    
    

    We also update the same thing when removing member from workspace

    And then in ReportParticipantsPage, we will add pendingAction field based on pendingVisibleChatMemberAccountIDs

     const pendingVisibleChatMember = _.find(report.pendingVisibleChatMemberAccountIDs, (member) => member.accountID === accountID)
    
                return {
                    .....
                    pendingAction: pendingVisibleChatMember.pendingAction,
    

    What alternative solutions did you explore? (Optional)

    In another implementation of the above idea, we can update the data structure of visibleChatMemberAccountIDs field, currently visibleChatMemberAccountIDs is a list of accountIDs. We can update this field to include pendingAction like this

    visibleChatMemberAccountIDs = [
      {
        accountID: "1729749",
        pendingAction: "ADD"
      }
    ]
    

    With this approach, we have a global solution to handle bugs that relate to pendingAction of member in reports

  10. alexpensify commented on Jan 19, 2024

    @alexpensify
    Contributor

    @getusha - can we get your feedback here? Thanks!

  11. Krishna2323 commented on Jan 20, 2024

    @Krishna2323
    Contributor

    To avoid confusions before @getusha starts the review I want to mention that I already have many edits, the last edit which was made before the other proposals came was the 9th edit, and it already mentioned about getting data about members pendingAction using policyMembers, that edit came before @abzokhattab's proposal. I recently faced a issue where all the participants wasted too much time in selecting the right proposal due to edits. I'm trying improve my proposal and from now on I will post proposal updated after every edit.

  12. 58 remaining items

  13. alexpensify commented on Feb 20, 2024

    @alexpensify
    Contributor

    This PR looks like it's still moving forward!

  14. alexpensify commented on Feb 27, 2024

    @alexpensify
    Contributor

    Weekly Update: The PR is still under review

  15. alexpensify commented on Mar 5, 2024

    @alexpensify
    Contributor

    Weekly Update: The recent PR comments were addressed yesterday.

  16. added
    Awaiting PaymentAuto-added when associated PR is deployed to production
    and removed on Mar 12, 2024
  17. changed the title [-][$500] Members – Member invited in offline is not grayed out on Announce room members list[/-] [+][HOLD for payment 2024-03-19] [$500] Members – Member invited in offline is not grayed out on Announce room members list[/+] on Mar 12, 2024
  18. melvin-bot commented on Mar 12, 2024

    @melvin-bot

    Reviewing label has been removed, please complete the "BugZero Checklist".

  19. melvin-bot commented on Mar 12, 2024

    @melvin-bot

    The solution for this issue has been 🚀 deployed to production 🚀 in version 1.4.50-5 and is now subject to a 7-day regression period 📆. Here is the list of pull requests that resolve this issue:

    If no regressions arise, payment will be issued on 2024-03-19. 🎊

    For reference, here are some details about the assignees on this issue:

  20. melvin-bot commented on Mar 12, 2024

    @melvin-bot

    BugZero Checklist: The PR fixing this issue has been merged! The following checklist (instructions) will need to be completed before the issue can be closed:

    • [@getusha / @DylanDylann] The PR that introduced the bug has been identified. Link to the PR:
    • [@getusha / @DylanDylann] The offending PR has been commented on, pointing out the bug it caused and why, so the author and reviewers can learn from the mistake. Link to comment:
    • [@getusha / @DylanDylann] A discussion in #expensify-bugs has been started about whether any other steps should be taken (e.g. updating the PR review checklist) in order to catch this type of bug sooner. Link to discussion:
    • [@getusha / @DylanDylann] Determine if we should create a regression test for this bug.
    • [@getusha / @DylanDylann] If we decide to create a regression test for the bug, please propose the regression test steps to ensure the same bug will not reach production again.
    • [@alexpensify] Link the GH issue for creating/updating the regression test once above steps have been agreed upon:
  21. alexpensify commented on Mar 19, 2024

    @alexpensify
    Contributor

    Here is the payment summary:

    • External issue reporter - N/A
    • Contributor that fixed the issue @DylanDylann $500
    • Contributor+ that helped on the issue and/or PR - @getusha $500

    Upwork Job: https://www.upwork.com/jobs/~0115b0aaa09aebec57

    Extra Notes regarding payment: Everyone has been paid via Upwork.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

Awaiting PaymentAuto-added when associated PR is deployed to productionBugSomething is broken. Auto assigns a BugZero manager.DailyKSv2ExternalAdded to denote the issue can be worked on by a contributor

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions