App icon indicating copy to clipboard operation
App copied to clipboard

[$175] [CFI] Add workspace join-request pre-approval toggle to Overview > Share

Open trjExpensify opened this issue 5 days ago • 12 comments

Problem

Classic lets admins pre-approve workspace join requests from validated users at their company’s domain. New Expensify lacks this setting, forcing admins to switch to Classic to view or change it.

Proposed solution

Add a toggle below Copy URL on Workspace > Overview > Share, matching the attached mockup: “Pre-approve join requests from [domain]”

Acceptance criteria

  • Display the existing setting without changing its value by default.
  • Allow workspace admins to enable or disable it.
  • Update the same underlying setting used by Classic, preserving its eligibility rules and behavior.
  • Verify changes persist and are reflected in both experiences.

References

Slack discussion

Evidence

Proposed join-request pre-approval toggle on Overview Share page

Proposed join-request pre-approval toggle on Overview Share page

Current New Expensify Overview Share page

Current New Expensify Overview Share page

Existing Classic join-request pre-approval setting

Existing Classic join-request pre-approval setting
Upwork Automation - Do Not Edit
Issue OwnerCurrent Issue Owner: @dukenv0307

trjExpensify avatar Nov 27 '26 15:11 trjExpensify

@MelvinBot write a proposal for this.

trjExpensify avatar Nov 27 '26 15:11 trjExpensify

Proposal

What is the root cause of that problem?

New Expensify’s Share page does not expose the existing workspace join-request pre-approval setting. It already restricts access to workspace admins, but lacks the control and corresponding setting-update integration.

Supporting code

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

Prerequisite: Confirm Classic’s exact setting, update API, domain source, and eligibility rules before implementation. I could not verify these because GitHub read requests for the Classic/backend repositories returned HTTP 404. Whether New Expensify already receives the required admin-facing data also remains unconfirmed.

Once that contract is verified:

  1. Add “Pre-approve join requests from [domain]” below Copy URL, matching the mockup, with localized copy and an accessible label.
  2. Display the existing saved value and apply Classic’s eligibility rules exactly. Do not infer the domain from the current admin’s email.
  3. Read authoritative state through Onyx. Opening the page must not write a default value; distinguish unloaded data from an explicitly disabled setting.
  4. On an explicit toggle, update the same setting used by Classic, with optimistic feedback, queued offline updates, and rollback plus dismissible error feedback on failure.
  5. Ensure reloads and subsequent server updates show the persisted value.
Existing implementation patterns

Reuse these patterns—not the unrelated feature’s eligibility rules.

Validation: Cover initially enabled/disabled states without writes, eligible/ineligible workspaces, admin access, loading, offline updates, and failure rollback. Verify persistence after reload and changes in both directions between Classic and New Expensify. These are proposed tests, not completed verification.

What alternative solutions did you explore? (Optional)

A separate New Expensify preference would risk diverging from Classic. Reusing the existing setting preserves one source of truth.


Next Steps for Contributor+ team: Confirm the Classic contract before accepting implementation.
To accept: After confirmation, @MelvinBot implement [this](https://github.com/Expensify/App/issues/108219) to create a draft PR.
To refine: @MelvinBot <your feedback>
To reject: Explain why you are rejecting Melvin’s proposal.


view run

MelvinBot avatar Nov 27 '26 15:11 MelvinBot

Proposal

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

New Expensify's Workspace > Overview > Share page doesn't expose the "pre-approve join requests from validated users at your company's domain" setting that Expensify Classic already has. Admins who want this must switch to Classic to view or change it.

What is the root cause of that problem?

The Share page (src/pages/workspace/WorkspaceOverviewSharePage.tsx) only renders the workspace's QR code and a "Copy URL" action — it has no UI for the domain pre-approval setting, and the Policy Onyx type (src/types/onyx/Policy.ts) has no field for it at all. The setting already exists and is already enforced server-side (it's what Classic's Domain Admin page reads/writes), but New Expensify has simply never been taught about it — this is a missing feature, not a regression.

This is structurally identical to other simple admin-only boolean policy toggles already shipped in this codebase, e.g. preventSelfApproval ("Prevent self-approvals") — a single boolean on Policy, updated via a dedicated API.write command, with no beta gating.

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

Add the setting following the exact same shape as the existing preventSelfApproval pattern:

1. src/types/onyx/Policy.ts — add the field:

         preventPayoutNonReimbursableReports?: boolean;

+        /** Whether workspace join requests from validated users at the admin's email domain are automatically approved, without manual admin review. Mirrors the equivalent domain pre-approval setting in Expensify Classic. */
+        isJoinRequestAutoApproved?: boolean;
+
         autoReportingOffset?: AutoReportingOffset;

2. src/libs/API/parameters/SetPolicyJoinRequestAutoApproval.ts (new file):

type SetPolicyJoinRequestAutoApprovalParams = {
    policyID: string;
    isJoinRequestAutoApproved: boolean;
};

export default SetPolicyJoinRequestAutoApprovalParams;

3. src/libs/API/types.ts and src/libs/API/parameters/index.ts — register the new write command and param export, next to SET_POLICY_PREVENT_SELF_APPROVAL:

     SET_POLICY_PREVENT_SELF_APPROVAL: 'SetPolicyPreventSelfApproval',
+    SET_POLICY_JOIN_REQUEST_AUTO_APPROVAL: 'SetPolicyJoinRequestAutoApproval',
     [WRITE_COMMANDS.SET_POLICY_PREVENT_SELF_APPROVAL]: Parameters.SetPolicyPreventSelfApprovalParams;
+    [WRITE_COMMANDS.SET_POLICY_JOIN_REQUEST_AUTO_APPROVAL]: Parameters.SetPolicyJoinRequestAutoApprovalParams;

4. src/libs/actions/Policy/Policy.ts — new action function, copied structurally from setPolicyPreventSelfApproval (optimistic update, success clears pendingFields, failure rolls back and sets errorFields):

function setPolicyJoinRequestAutoApproval(policyID: string, isJoinRequestAutoApproved: boolean, currentIsJoinRequestAutoApproved: boolean | undefined) {
    if (isJoinRequestAutoApproved === currentIsJoinRequestAutoApproved) {
        return;
    }

    const optimisticData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.POLICY>> = [
        {
            onyxMethod: Onyx.METHOD.MERGE,
            key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
            value: {
                isJoinRequestAutoApproved,
                pendingFields: {isJoinRequestAutoApproved: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE},
            },
        },
    ];

    const successData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.POLICY>> = [
        {
            onyxMethod: Onyx.METHOD.MERGE,
            key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
            value: {pendingFields: {isJoinRequestAutoApproved: null}, errorFields: null},
        },
    ];

    const failureData: Array<OnyxUpdate<typeof ONYXKEYS.COLLECTION.POLICY>> = [
        {
            onyxMethod: Onyx.METHOD.MERGE,
            key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
            value: {
                isJoinRequestAutoApproved: currentIsJoinRequestAutoApproved ?? null,
                pendingFields: {isJoinRequestAutoApproved: null},
                errorFields: {isJoinRequestAutoApproved: ErrorUtils.getMicroSecondOnyxErrorWithTranslationKey('common.genericErrorMessage')},
            },
        },
    ];

    const parameters: SetPolicyJoinRequestAutoApprovalParams = {policyID, isJoinRequestAutoApproved};

    API.write(WRITE_COMMANDS.SET_POLICY_JOIN_REQUEST_AUTO_APPROVAL, parameters, {optimisticData, successData, failureData});
}

5. src/languages/en.ts — new translation (locale files other than en.ts are generated, per contributingGuides/HOW_TO_AUDIT_TRANSLATIONS.md, and are not hand-edited):

             shareNote: { ... },
+            joinRequestAutoApproval: {
+                title: (domain: string) => `Pre-approve join requests from ${domain}`,
+            },

6. src/pages/workspace/WorkspaceOverviewSharePage.tsx — render the toggle below "Copy URL", using the shared ToggleSettingOptionRow component (the same row component used by every other single-boolean workspace setting in the app, e.g. in ExpenseReportRulesSection.tsx):

                             )}
                         </View>
+                        {canPreApproveJoinRequestsFromDomain && (
+                            <View style={[styles.mt3, styles.ph4]}>
+                                <ToggleSettingOptionRow
+                                    title={translate('workspace.common.joinRequestAutoApproval.title', adminEmailDomain)}
+                                    switchAccessibilityLabel={translate('workspace.common.joinRequestAutoApproval.title', adminEmailDomain)}
+                                    switchSentryLabel={CONST.SENTRY_LABEL.WORKSPACE.OVERVIEW.SHARE_JOIN_REQUEST_AUTO_APPROVAL_SWITCH}
+                                    isActive={!!policy?.isJoinRequestAutoApproved}
+                                    pendingAction={policy?.pendingFields?.isJoinRequestAutoApproved ?? policy?.pendingAction}
+                                    onToggle={(isEnabled) => {
+                                        if (!policyID) {
+                                            return;
+                                        }
+                                        setPolicyJoinRequestAutoApproval(policyID, isEnabled, policy?.isJoinRequestAutoApproved);
+                                    }}
+                                />
+                            </View>
+                        )}

adminEmailDomain is derived with the existing getEmailDomain() helper (@libs/LoginUtils), and the toggle is only shown when !isDomainPublic(adminEmailDomain) — mirroring Classic's own eligibility rule that this setting only applies to a real company domain, never a public provider like gmail.com.

Tests added (tests/actions/PolicyTest.ts, following the existing setPolicyPreventSelfApproval/setPolicyPreventPayoutNonReimbursableReports test blocks):

  • Enabling the setting writes the optimistic value and pendingFields.UPDATE, then clears pendingFields on success.
  • A failed request rolls the value back and sets errorFields.
  • Calling the action with the value unchanged is a no-op (no API call, no pending state).

ratulbmg avatar Nov 27 '26 16:11 ratulbmg

@MelvinBot I think this might require backend, because we likely need the existing policyNVP automaticJoiningEnabled: true to be exposed to NewDot.

trjExpensify avatar Nov 27 '26 17:11 trjExpensify

Agreed—this should be treated as potentially backend-dependent, not a frontend-only toggle.

NewDot already receives automaticJoiningEnabled for joinable workspaces (JoinablePolicies.ts:15–18) and uses it to choose between joining immediately and requesting approval (BaseOnboardingWorkspaces.tsx:209–222). That does not establish that it is exposed in the admin-facing workspace data used by Share.

The proposal’s prerequisite should therefore be:

  • Have an internal engineer confirm whether the existing policyNVP is included in NewDot’s admin policy responses and synchronized when Classic changes it.
  • Confirm the existing write API, eligible domain, and Classic eligibility rules.
  • If backend exposure is missing, handle that dependency internally before implementing the App toggle.

Adding a TypeScript property alone would not expose server data. We also should not introduce a separate preference or assume a new endpoint exists.

I can confirm the App-side distinction, but not the missing backend serialization itself: access to the relevant backend repositories returned HTTP 404 during the investigation.


view run

MelvinBot avatar Nov 27 '26 17:11 MelvinBot

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

Job added to Upwork: https://www.upwork.com/jobs/~022126376188210261960

Adding External to get a C+ assigned to evaluate this. @Krishna2323 what do you think?

trjExpensify avatar Nov 27 '26 18:11 trjExpensify

Proposal

What is the root cause of that problem?

New Expensify never reads or writes this setting for admins, so they must go to Classic.

  1. The Share page has no control for it. WorkspaceOverviewSharePage.tsx L111-L141 renders only Copy URL and Download.
  2. The admin's policy data has no such field. The Policy type (Policy.ts around L4426-L4429, where the other boolean settings live) has no field for it. The only copy of the setting in the app is automaticJoiningEnabled on JoinablePolicy L17-L18. That data is for people who want to join a workspace (BaseOnboardingWorkspaces.tsx L209-L222). It is not part of the admin's workspace data.
  3. No write command exists. src/libs/API/types.ts has no command to change it.

The backend already knows this setting. When Classic changes it, the backend posts POLICYCHANGELOG_SET_AUTO_JOIN to the admins room. New Expensify already shows that message (CONST/index.ts L2453, en.ts L11194).

Answer to @trjExpensify's question: yes, this needs backend work. Adding a TypeScript field alone gives the page no data.

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

A. Backend contract (internal engineer). We keep the existing setting and its name. We add no new setting.

  1. Return automaticJoiningEnabled (always true or false) in the policy data sent to admins. Include it in OpenPolicyProfilePage, which the Overview page already calls on focus (WorkspaceOverviewPage.tsx L306). Also include it in the normal app policy data.
  2. Add the write command SetPolicyAutomaticJoiningEnabled with params {policyID, enabled}. It writes the same value Classic writes, keeps Classic's rules (validated users, private domain only), and posts the existing POLICYCHANGELOG_SET_AUTO_JOIN message.
  3. When Classic changes the value, push it in the policy update, so New Expensify shows the change without a reload.

B. App changes (us).

  1. Onyx type. Add automaticJoiningEnabled?: boolean to Policy, next to isReceiptVisibilityPublic. Add a short comment.
  2. API. Add SET_POLICY_AUTOMATIC_JOINING_ENABLED: 'SetPolicyAutomaticJoiningEnabled' to WRITE_COMMANDS. Add a params file {policyID: string; enabled: boolean}. It is the same shape as SetPolicyPublicReceiptVisibilityEnabledParams.
  3. Action. Add setPolicyAutomaticJoiningEnabled(policyID, enabled, currentEnabled) in libs/actions/Policy/Policy.ts. It is a copy of the pattern in setPolicyReceiptVisibilityPublic L7589-L7634:
    • optimistic: automaticJoiningEnabled: enabled, pendingFields.automaticJoiningEnabled: UPDATE
    • success: pendingFields.automaticJoiningEnabled: null, errorFields: null
    • failure: automaticJoiningEnabled: currentEnabled ?? null, pendingFields.automaticJoiningEnabled: null, errorFields.automaticJoiningEnabled: genericErrorMessage
    • It returns early if enabled === currentEnabled.
    • We add no optimistic admins-room message. Other policy toggles also do not add one; the backend message arrives by push.
  4. Domain rule. Use the workspace owner's email domain, not the signed-in admin's. The help docs say people can join a workspace that "someone on your email domain already owns" (Submit-Workspace.md L71). Example: an outside accountant at firm.com who is an admin must still see "acme.com".
    domain = getEmailDomain(policy.owner)                       // LoginUtils L48
    canShow = domain && !isDomainPublic(domain)                 // LoginUtils L41; no gmail.com etc.
              && policy.automaticJoiningEnabled !== undefined   // value loaded from server
    
    LoginUtils.ts L41-L50. If the backend engineer says Classic uses a different domain, we change only this one line.
  5. UI. In WorkspaceOverviewSharePage, below the Copy URL / Download block (L111-L141), render ToggleSettingOptionRow. It is the same row the workspace settings use (PublicReceiptVisibilityToggle.tsx L62-L79), with the same error handling as RulesRequireFieldsPage.tsx L324-L326:
    • title and switchAccessibilityLabel: translate('workspace.common.preApproveJoinRequests', domain)
    • isActive={!!policy?.automaticJoiningEnabled}
    • onToggle={(enabled) => setPolicyAutomaticJoiningEnabled(policyID, enabled, policy?.automaticJoiningEnabled)}
    • pendingAction={policy?.pendingFields?.automaticJoiningEnabled}
    • errors={policy?.errorFields?.automaticJoiningEnabled}, onCloseError={() => clearPolicyErrorField(policyID, 'automaticJoiningEnabled')}
    • switchSentryLabel: new CONST.SENTRY_LABEL.WORKSPACE.OVERVIEW.SHARE_PRE_APPROVE_JOIN_REQUESTS, next to SHARE_COPY (SENTRY_LABEL.ts L1903-L1904)
    • Spacing matches the mockup (styles.mt3, styles.ph4 like the block above). The page is already admin-only (L73-L76), so no extra role check is needed.
  6. Translations. Add preApproveJoinRequests: (domain: string) => \Pre-approve join requests from ${domain}`underworkspace.commoninen.ts, next to shareNote(L5837). The other languages come fromscripts/generateTranslations.ts`.

Acceptance criteria, one by one:

  • Show the saved value and do not change it: the page only reads policy.automaticJoiningEnabled. Nothing writes when the page opens. The toggle is hidden until the value is loaded, so a missing value never shows as "off".
  • Admins can turn it on or off: via the toggle on the admin-only page.
  • Same setting and rules as Classic: one value on the server, one write command. Classic's rules stay in the backend.
  • Saved and shown in both apps: the toggle saves through the API. Changes made in Classic arrive by push and by OpenPolicyProfilePage.

Offline. API.write queues the request. The toggle flips at once and is greyed out by pendingAction (OfflineWithFeedback is inside ToggleSettingOptionRow). The request is sent on reconnect. On failure, the value goes back and a closable red error shows under the row.

Safe release order. Because the toggle shows only when the server sends the value, the app change can merge before or after the backend change. No beta is needed.

Tests.

  • tests/actions/PolicyTest.ts, like the setPolicyAttendeeTrackingEnabled block (L8452-L8504):
    • optimistic value and pending state, then pending cleared on success
    • failure puts the old value back and sets errorFields
    • same value: no API call
  • New tests/ui/WorkspaceOverviewSharePageTest.tsx:
    • shows "Pre-approve join requests from acme.com" for owner [email protected], with the saved on and off states
    • hidden for a gmail.com owner
    • hidden when automaticJoiningEnabled is undefined
    • a non-owner admin at another domain still sees the owner's domain
    • pressing the switch calls the action once; opening the page calls it zero times

What alternative solutions did you explore? (Optional)

  • New field or new setting for New Expensify only (for example isJoinRequestAutoApproved). Rejected: it splits from Classic and breaks "same underlying setting".
  • Domain from the signed-in admin's email. Rejected: it shows the wrong domain to admins outside the owner's company.
  • Show "off" while the value is missing. Rejected: it shows a wrong state, and one tap could overwrite the real value.

mattlsyyssll avatar Nov 27 '26 20:11 mattlsyyssll

@trjExpensify Agreed, this needs a backend PR first. NewDot currently has no policy field for this setting, no write command to update it, and no domain for the label. automaticJoiningEnabled is only passed to NewDot through JoinablePolicy, which represents the joiner's side.

Once the backend sends the NVP on the policy and adds a command to update it, I can move forward with Melvin's proposal.

Krishna2323 avatar Nov 27 '26 21:11 Krishna2323

@MelvinBot create E/E issue then assign me

dukenv0307 avatar Nov 28 '26 04:11 dukenv0307

Created the E/E issue Expose workspace join-request pre-approval setting to New Expensify admins and assigned it to dukenv0307.


view run

MelvinBot avatar Nov 28 '26 04:11 MelvinBot