Skip to content

[Due for payment 2025-06-02] [$250] Expensify Card - After deactivating card, Expensify Card link in system message remains linked #61472

Closed

Description

@nlemma

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: 9.1.40-1
Reproducible in staging?: Yes
Reproducible in production?: Yes
If this was caught during regression testing, add the test name, ID and link from TestRail: https://expensify.testrail.io/index.php?/tests/view/6051897
Email or phone of affected tester (no customers): applausetester+khcategory19@applause.expensifail.com
Issue reported by: Applause Internal Team
Device used: Windows 11 / Chrome
App Component: Workspace Settings

Action Performed:

Precondition:

  • User has assigned themselves a virtual Expensify Card.
  1. Go to staging.new.expensify.com
  2. Go to workspace chat.
  3. Click Expensify Card link in the system message.
  4. Click Deactivate card.
  5. Click Deactivate.
  6. Click Expensify Card link in the system message again.

Expected Result:

After deactivating Expensify card, Expensify Card link in the system message should be unlinked.

Actual Result:

After deactivating Expensify card, Expensify Card link in the system message remains linked, which leads to not here page.

Workaround:

Unknown

Platforms:

  • Android: App
  • Android: mWeb Chrome
  • iOS: App
  • iOS: mWeb Safari
  • iOS: mWeb Chrome
  • Windows: Chrome
  • MacOS: Chrome / Safari
  • MacOS: Desktop

Screenshots/Videos

Bug6822987_1746525016784.bandicam_2025-05-06_17-43-38-962.mp4

View all open jobs on GitHub

Upwork Automation - Do Not Edit
  • Upwork Job URL: https://www.upwork.com/jobs/~021919734679965911302
  • Upwork Job ID: 1919734679965911302
  • Last Price Increase: 2025-05-06
  • Automatic offers:
    • daledah | Contributor | 107201438
Issue OwnerCurrent Issue Owner: @mallenexpensify

Activity

  1. added
    BugSomething is broken. Auto assigns a BugZero manager.
    on May 6, 2025
  2. melvin-bot commented on May 6, 2025

    @melvin-bot

    Triggered auto assignment to @laurenreidexpensify (Bug), see https://stackoverflow.com/c/expensify/questions/14418 for more details. Please add this bug to a GH project, as outlined in the SO.

  3. changed the title [-]Expensify Card - After deactivating card, Expensify Card link in system message remains linked[/-] [+][$250] Expensify Card - After deactivating card, Expensify Card link in system message remains linked[/+] on May 6, 2025
  4. melvin-bot commented on May 6, 2025

    @melvin-bot
  5. added
    Help WantedApply this label when an issue is open to proposals by contributors
    on May 6, 2025
  6. melvin-bot commented on May 6, 2025

    @melvin-bot

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

  7. daledah commented on May 6, 2025

    @daledah
    Contributor

    🚨 Edited by proposal-police: This proposal was edited at 2025-05-06 15:29:28 UTC.

    Proposal

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

    After deactivating Expensify card, Expensify Card link in the system message remains linked, which leads to not here page.

    What is the root cause of that problem?

    We display issue card message without relying on card changes:

    function IssueCardMessage({action, policyID}: IssueCardMessageProps) {

    While when deactivating card, only card data is modified

    function deactivateCard(workspaceAccountID: number, card?: Card) {

    So the message is not updated after deactivate card

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

    We can force render card message when card data change

    First, get card data up in ReportActionItem component

    const [allWorkspaceCards] = useOnyx(ONYXKEYS.COLLECTION.WORKSPACE_CARDS_LIST, {canBeMissing: true});
    const card = getExpensifyCardFromReportAction({reportAction: action, policyID: report?.policyID, cards: allWorkspaceCards});

    While doing this we modify getExpensifyCardFromReportAction like below

    function getExpensifyCardFromReportAction({reportAction, policyID}: {reportAction?: ReportAction; policyID?: string}): Card | undefined {

    function getExpensifyCardFromReportAction({
        reportAction,
        policyID,
        cards = allWorkspaceCards,
    }: {
        reportAction?: ReportAction;
        policyID?: string;
        cards?: OnyxCollection<WorkspaceCardsList>;
    }): Card | undefined {

    const allExpensifyCards = allWorkspaceCards?.[`cards_${workspaceAccountID}_${CONST.EXPENSIFY_CARD.BANK}`] ?? {};

    const allExpensifyCards = cards?.[`cards_${workspaceAccountID}_${CONST.EXPENSIFY_CARD.BANK}`] ?? {};

    The purpose is to force recalculation of card after deactivating card.

    Then, pass card from ReportActionItem down to IssueCardMessage

    Screen.Recording.2025-05-06.at.21.57.50.mp4

    What specific scenarios should we cover in automated tests to prevent reintroducing this issue in the future?

    We can render IssueCardMessage, perform Onyx update similar to deactivate card action and make sure IssueCardMessage is rerendered properly

    What alternative solutions did you explore? (Optional)

    We can update deactivateCard to modify reportAction data to force rerender IssueCardMessage without the need of passing card from above.

    First, we need to create 2 util functions:

    // ReportActionUtils.ts
    function getReportActionFromExpensifyCard(cardID: number) {
        return Object.values(allReportActions ?? {})
            .map((reportActions) => Object.values(reportActions ?? {}))
            .flat()
            .find((reportAction) => {
                const cardIssuedActionOriginalMessage = isActionOfType(
                    reportAction,
                    CONST.REPORT.ACTIONS.TYPE.CARD_ISSUED,
                    CONST.REPORT.ACTIONS.TYPE.CARD_ISSUED_VIRTUAL,
                    CONST.REPORT.ACTIONS.TYPE.CARD_ASSIGNED,
                    CONST.REPORT.ACTIONS.TYPE.CARD_MISSING_ADDRESS,
                )
                    ? getOriginalMessage(reportAction)
                    : undefined;
    
                if (cardIssuedActionOriginalMessage?.cardID !== cardID) {
                    return false;
                }
    
                return true;
            });
    }

    This function is used to get the reportAction related to cardID

    And another one

    // ReportUtils.ts
    function findReportIDForAction(action?: ReportAction): string | undefined {
        if (!allReportActions || !action?.reportActionID) {
            return undefined;
        }
    
        for (const reportActionsKey in allReportActions) {
            if (Object.prototype.hasOwnProperty.call(allReportActions, reportActionsKey)) {
                const reportActions = allReportActions[reportActionsKey];
                if (reportActions && reportActions[action.reportActionID]) {
                    // Extract reportID from the key (e.g., "reportActions_12345" -> "12345")
                    return reportActionsKey.replace(`${ONYXKEYS.COLLECTION.REPORT_ACTIONS}`, '');
                }
            }
        }
    
        return undefined;
    }

    This is used to get reportID of found reportAction, since I don't see reportID exists in any CARDISSUEDVIRTUAL report actions.

    Then we update deactivateCard

    const reportAction = getReportActionFromExpensifyCard(cardID);
    const reportID = findReportIDForAction(reportAction) ?? reportAction?.reportID;

    Add optimistic and failure data

        if (reportAction?.reportActionID && reportID) {
            optimisticData.push({
                onyxMethod: Onyx.METHOD.MERGE,
                key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
                value: {
                    [reportAction.reportActionID]: {
                        ...reportAction,
                        originalMessage: {
                            cardID: null,
                        },
                    },
                },
            });
            failureData.push({
                onyxMethod: Onyx.METHOD.MERGE,
                key: `${ONYXKEYS.COLLECTION.REPORT_ACTIONS}${reportID}`,
                value: {
                    [reportAction.reportActionID]: reportAction,
                },
            });
        }

    If we decide to go with this solution, we might need to update BE as well to maintain consistency between BE and FE.

    Reminder: Please use plain English, be brief and avoid jargon. Feel free to use images, charts or pseudo-code if necessary. Do not post large multi-line diffs or write walls of text. Do not create PRs unless you have been hired for this job.

  8. ZhenjaHorbach commented on May 6, 2025

    @ZhenjaHorbach
    Contributor

    @daledah
    Thanks for your proposal
    I like your two solutions
    But the alternative looks a bit cleaner as for me
    Since we don't need to pass specific params to the common component

    🎀 👀 🎀 C+ reviewed

  9. melvin-bot commented on May 6, 2025

    @melvin-bot

    Triggered auto assignment to @rlinoz, see https://stackoverflow.com/c/expensify/questions/7972 for more details.

  10. 26 remaining items

  11. ZhenjaHorbach commented on Jun 4, 2025

    @ZhenjaHorbach
    Contributor

    BugZero Checklist:

    • [Contributor] Classify the bug:
    Bug classification

    Source of bug:

    • 1a. Result of the original design (eg. a case wasn't considered)
    • 1b. Mistake during implementation
    • 1c. Backend bug
    • 1z. Other:

    Where bug was reported:

    • 2a. Reported on production (eg. bug slipped through the normal regression and PR testing process on staging)
    • 2b. Reported on staging (eg. found during regression or PR testing)
    • 2d. Reported on a PR
    • 2z. Other:

    Who reported the bug:

    • 3a. Expensify user
    • 3b. Expensify employee
    • 3c. Contributor
    • 3d. QA
    • 3z. Other:
    • [Contributor] 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: https://github.com/Expensify/App/pull/47986/files#r2127391984

    • [Contributor] If the regression was CRITICAL (e.g. interrupts a core flow) A discussion in #expensify-open-source 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: NA

    • [Contributor] If it was decided to create a regression test for the bug, please propose the regression test steps using the template below to ensure the same bug will not reach production again.

    Regression Test Proposal

    • Precondition: User has assigned themselves a virtual Expensify Card.
    1. Open App.
    2. Go to workspace chat.
    3. Click Expensify Card link in the system message.
    4. Click Deactivate card.
    5. Click Deactivate.
    6. Verify that: After RHP is closed, Expensify Card link in the system message is unlinked.
  12. melvin-bot commented on Jun 6, 2025

    @melvin-bot

    @mallenexpensify Uh oh! This issue is overdue by 2 days. Don't forget to update your issues!

  13. mallenexpensify commented on Jun 6, 2025

    @mallenexpensify
    Contributor

    Contributor: @daledah paid $ via Upwork
    Contributor+: @ZhenjaHorbach due $250 via NewDot

    Test case

    Thx!

  14. ZhenjaHorbach commented on Jun 19, 2025

    @ZhenjaHorbach
    Contributor

    Requested in ND

  15. garrettmknight commented on Jun 26, 2025

    @garrettmknight
    Contributor

    $250 approved for @ZhenjaHorbach

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.ExternalAdded to denote the issue can be worked on by a contributorReviewingHas a PR in reviewWeeklyKSv2

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions