From 9fbc0f7d69b28bee05abe36a9aa94c0309ec4842 Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Fri, 12 Apr 2024 20:23:33 +0530 Subject: [PATCH 1/4] Deprecated Policy Role in favor of employeeList --- src/components/MoneyRequestHeader.tsx | 3 ++- src/libs/PolicyUtils.ts | 18 ++++++++++++++- src/libs/ReportUtils.ts | 23 +++++++++---------- src/libs/actions/IOU.ts | 2 +- src/libs/actions/Policy.ts | 11 +++++---- .../FloatingActionButtonAndPopover.tsx | 4 ++-- src/pages/workspace/WorkspacesListPage.tsx | 5 ++-- src/types/onyx/Policy.ts | 5 +--- src/types/onyx/PolicyMember.ts | 4 +++- tests/actions/PolicyTest.ts | 1 - 10 files changed, 46 insertions(+), 30 deletions(-) diff --git a/src/components/MoneyRequestHeader.tsx b/src/components/MoneyRequestHeader.tsx index f451f5f15581..4ac348e5a4af 100644 --- a/src/components/MoneyRequestHeader.tsx +++ b/src/components/MoneyRequestHeader.tsx @@ -7,6 +7,7 @@ import useThemeStyles from '@hooks/useThemeStyles'; import useWindowDimensions from '@hooks/useWindowDimensions'; import * as HeaderUtils from '@libs/HeaderUtils'; import Navigation from '@libs/Navigation/Navigation'; +import * as PolicyUtils from '@libs/PolicyUtils'; import * as ReportActionsUtils from '@libs/ReportActionsUtils'; import * as ReportUtils from '@libs/ReportUtils'; import * as TransactionUtils from '@libs/TransactionUtils'; @@ -65,7 +66,7 @@ function MoneyRequestHeader({session, parentReport, report, parentReportAction, // Only the requestor can take delete the request, admins can only edit it. const isActionOwner = typeof parentReportAction?.actorAccountID === 'number' && typeof session?.accountID === 'number' && parentReportAction.actorAccountID === session?.accountID; - const isPolicyAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN; + const isPolicyAdmin = PolicyUtils.isPolicyAdmin(policy); const isApprover = ReportUtils.isMoneyRequestReport(moneyRequestReport) && (session?.accountID ?? null) === moneyRequestReport?.managerID; const deleteTransaction = useCallback(() => { diff --git a/src/libs/PolicyUtils.ts b/src/libs/PolicyUtils.ts index 1b9423c70ee7..dff4999da34e 100644 --- a/src/libs/PolicyUtils.ts +++ b/src/libs/PolicyUtils.ts @@ -1,6 +1,8 @@ import Str from 'expensify-common/lib/str'; import type {OnyxCollection, OnyxEntry} from 'react-native-onyx'; +import Onyx from 'react-native-onyx'; import type {ValueOf} from 'type-fest'; +import type {PolicySelector} from '@pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover'; import CONST from '@src/CONST'; import ONYXKEYS from '@src/ONYXKEYS'; import ROUTES from '@src/ROUTES'; @@ -14,6 +16,14 @@ import type {RootStackParamList, State} from './Navigation/types'; type MemberEmailsToAccountIDs = Record; +let sessionEmail = ''; +Onyx.connect({ + key: ONYXKEYS.SESSION, + callback: (val) => { + sessionEmail = val?.email ?? ''; + }, +}); + /** * Filter out the active policies, which will exclude policies with pending deletion * These are policies that we can use to create reports with in NewDot. @@ -118,10 +128,15 @@ function isExpensifyTeam(email: string | undefined): boolean { return emailDomain === CONST.EXPENSIFY_PARTNER_NAME || emailDomain === CONST.EMAIL.GUIDES_DOMAIN; } +function getPolicyRole(policy: OnyxEntry | OnyxEntry | EmptyObject): ValueOf | undefined { + const role = policy?.employeeList?.[sessionEmail]?.role; + return role; +} + /** * Checks if the current user is an admin of the policy. */ -const isPolicyAdmin = (policy: OnyxEntry | EmptyObject): boolean => policy?.role === CONST.POLICY.ROLE.ADMIN; +const isPolicyAdmin = (policy: OnyxEntry | EmptyObject): boolean => getPolicyRole(policy) === CONST.POLICY.ROLE.ADMIN; /** * Checks if the policy is a free group policy. @@ -351,6 +366,7 @@ export { getTaxByID, hasPolicyCategoriesError, getPolicyIDFromNavigationState, + getPolicyRole, }; export type {MemberEmailsToAccountIDs}; diff --git a/src/libs/ReportUtils.ts b/src/libs/ReportUtils.ts index 6197a29cd4a6..0d5c1fc9bf93 100644 --- a/src/libs/ReportUtils.ts +++ b/src/libs/ReportUtils.ts @@ -1190,7 +1190,7 @@ function isAllowedToComment(report: OnyxEntry): boolean { // If we've made it here, commenting on this report is restricted. // If the user is an admin, allow them to post. const policy = allPolicies[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]; - return policy?.role === CONST.POLICY.ROLE.ADMIN; + return PolicyUtils.isPolicyAdmin(policy); } /** @@ -1201,18 +1201,17 @@ function isPolicyExpenseChatAdmin(report: OnyxEntry, policies: OnyxColle return false; } - const policyRole = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]?.role; + const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`] ?? null; - return policyRole === CONST.POLICY.ROLE.ADMIN; + return PolicyUtils.isPolicyAdmin(policy); } /** * Checks if the current user is the admin of the policy. */ function isPolicyAdmin(policyID: string, policies: OnyxCollection): boolean { - const policyRole = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`]?.role; - - return policyRole === CONST.POLICY.ROLE.ADMIN; + const policy = policies?.[`${ONYXKEYS.COLLECTION.POLICY}${policyID}`] ?? null; + return PolicyUtils.isPolicyAdmin(policy); } /** @@ -1355,7 +1354,7 @@ function isPayer(session: OnyxEntry, iouReport: OnyxEntry) { const isApproved = isReportApproved(iouReport); const policy = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${iouReport?.policyID}`] ?? null; const policyType = policy?.type; - const isAdmin = policyType !== CONST.POLICY.TYPE.PERSONAL && policy?.role === CONST.POLICY.ROLE.ADMIN; + const isAdmin = policyType !== CONST.POLICY.TYPE.PERSONAL && PolicyUtils.isPolicyAdmin(policy); const isManager = iouReport?.managerID === session?.accountID; if (isPaidGroupPolicy(iouReport)) { if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES) { @@ -1455,7 +1454,7 @@ function canDeleteReportAction(reportAction: OnyxEntry, reportID: return false; } - const isAdmin = policy?.role === CONST.POLICY.ROLE.ADMIN && !isEmptyObject(report) && !isDM(report); + const isAdmin = PolicyUtils.isPolicyAdmin(policy) && !isEmptyObject(report) && !isDM(report); return isActionOwner || isAdmin; } @@ -2164,10 +2163,10 @@ function getPolicyExpenseChatName(report: OnyxEntry, policy: OnyxEntry

= CONST.POLICY.ROLE.USER; const policyItem = allPolicies?.[`${ONYXKEYS.COLLECTION.POLICY}${report?.policyID}`]; if (policyItem) { - policyExpenseChatRole = policyItem.role || 'user'; + policyExpenseChatRole = PolicyUtils.getPolicyRole(policyItem) ?? CONST.POLICY.ROLE.USER; } // If this user is not admin and this policy expense chat has been archived because of account merging, this must be an old workspace chat @@ -2405,7 +2404,7 @@ function canEditMoneyRequest(reportAction: OnyxEntry): boolean { } const policy = getPolicy(moneyRequestReport?.policyID ?? ''); - const isAdmin = policy.role === CONST.POLICY.ROLE.ADMIN; + const isAdmin = PolicyUtils.isPolicyAdmin(policy); const isManager = currentUserAccountID === moneyRequestReport?.managerID; // Admin & managers can always edit coding fields such as tag, category, billable, etc. As long as the report has a state higher than OPEN. @@ -2455,7 +2454,7 @@ function canEditFieldOfMoneyRequest(reportAction: OnyxEntry, field if (TransactionUtils.isDistanceRequest(transaction)) { const policy = getPolicy(moneyRequestReport?.reportID ?? ''); - const isAdmin = isExpenseReport(moneyRequestReport) && policy.role === CONST.POLICY.ROLE.ADMIN; + const isAdmin = isExpenseReport(moneyRequestReport) && PolicyUtils.isPolicyAdmin(policy); const isManager = isExpenseReport(moneyRequestReport) && currentUserAccountID === moneyRequestReport?.managerID; return isAdmin || isManager; diff --git a/src/libs/actions/IOU.ts b/src/libs/actions/IOU.ts index 470be9a4f345..6d4dfd4db6f9 100644 --- a/src/libs/actions/IOU.ts +++ b/src/libs/actions/IOU.ts @@ -4997,7 +4997,7 @@ function submitReport(expenseReport: OnyxTypes.Report) { const policy = getPolicy(expenseReport.policyID); const isCurrentUserManager = currentUserPersonalDetails.accountID === expenseReport.managerID; const isSubmitAndClosePolicy = PolicyUtils.isSubmitAndClose(policy); - const adminAccountID = policy.role === CONST.POLICY.ROLE.ADMIN ? currentUserPersonalDetails.accountID : undefined; + const adminAccountID = PolicyUtils.isPolicyAdmin(policy) ? currentUserPersonalDetails.accountID : undefined; const optimisticSubmittedReportAction = ReportUtils.buildOptimisticSubmittedReportAction(expenseReport?.total ?? 0, expenseReport.currency ?? '', expenseReport.reportID, adminAccountID); const optimisticNextStep = NextStepUtils.buildNextStep(expenseReport, isSubmitAndClosePolicy ? CONST.REPORT.STATUS_NUM.CLOSED : CONST.REPORT.STATUS_NUM.SUBMITTED); diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index d6ab203e85a4..a9104c129be4 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -293,8 +293,11 @@ function hasActiveChatEnabledPolicies(policies: Array> const adminChatEnabledPolicies = Object.values(policies ?? {}).filter( (policy) => policy && - ((policy.type === CONST.POLICY.TYPE.FREE && policy.role === CONST.POLICY.ROLE.ADMIN) || - (!includeOnlyFreePolicies && policy.type !== CONST.POLICY.TYPE.PERSONAL && policy.role === CONST.POLICY.ROLE.ADMIN && policy.isPolicyExpenseChatEnabled)), + ((policy.type === CONST.POLICY.TYPE.FREE && PolicyUtils.getPolicyRole(policy) === CONST.POLICY.ROLE.ADMIN) || + (!includeOnlyFreePolicies && + policy.type !== CONST.POLICY.TYPE.PERSONAL && + PolicyUtils.getPolicyRole(policy) === CONST.POLICY.ROLE.ADMIN && + policy.isPolicyExpenseChatEnabled)), ); if (adminChatEnabledPolicies.length === 0) { @@ -438,7 +441,7 @@ function deleteWorkspace(policyID: string, policyName: string) { * Is the user an admin of a free policy (aka workspace)? */ function isAdminOfFreePolicy(policies?: PoliciesRecord): boolean { - return Object.values(policies ?? {}).some((policy) => policy && policy.type === CONST.POLICY.TYPE.FREE && policy.role === CONST.POLICY.ROLE.ADMIN); + return Object.values(policies ?? {}).some((policy) => policy && PolicyUtils.isFreeGroupPolicy(policy) && PolicyUtils.isPolicyAdmin(policy)); } /** @@ -1946,7 +1949,6 @@ function createDraftInitialWorkspace(policyOwnerEmail = '', policyName = '', pol id: policyID, type: CONST.POLICY.TYPE.TEAM, name: workspaceName, - role: CONST.POLICY.ROLE.ADMIN, owner: sessionEmail, ownerAccountID: sessionAccountID, isPolicyExpenseChatEnabled: true, @@ -2011,7 +2013,6 @@ function createWorkspace(policyOwnerEmail = '', makeMeAdmin = false, policyName id: policyID, type: CONST.POLICY.TYPE.TEAM, name: workspaceName, - role: CONST.POLICY.ROLE.ADMIN, owner: sessionEmail, ownerAccountID: sessionAccountID, isPolicyExpenseChatEnabled: true, diff --git a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx index 591099ae5ec7..d2e37f838831 100644 --- a/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx +++ b/src/pages/home/sidebar/SidebarScreen/FloatingActionButtonAndPopover.tsx @@ -28,7 +28,7 @@ import type * as OnyxTypes from '@src/types/onyx'; import type {QuickActionName} from '@src/types/onyx/QuickAction'; import {isEmptyObject} from '@src/types/utils/EmptyObject'; -type PolicySelector = Pick; +type PolicySelector = Pick; type FloatingActionButtonAndPopoverOnyxProps = { /** The list of policies the user has access to. */ @@ -62,7 +62,7 @@ type FloatingActionButtonAndPopoverRef = { const policySelector = (policy: OnyxEntry): PolicySelector => (policy && { type: policy.type, - role: policy.role, + employeeList: policy.employeeList, isPolicyExpenseChatEnabled: policy.isPolicyExpenseChatEnabled, pendingAction: policy.pendingAction, avatar: policy.avatar, diff --git a/src/pages/workspace/WorkspacesListPage.tsx b/src/pages/workspace/WorkspacesListPage.tsx index 3a24f22996c0..e2e1f4c76e79 100755 --- a/src/pages/workspace/WorkspacesListPage.tsx +++ b/src/pages/workspace/WorkspacesListPage.tsx @@ -46,7 +46,7 @@ import WorkspacesListRow from './WorkspacesListRow'; type WorkspaceItem = Required> & Pick & Pick & - Pick & { + Pick & { icon: AvatarSource; action: () => void; dismissError: () => void; @@ -55,6 +55,7 @@ type WorkspaceItem = Required> & adminRoom?: string | null; announceRoom?: string | null; isJoinRequestPending?: boolean; + role?: ValueOf; }; // eslint-disable-next-line react/no-unused-prop-types @@ -340,7 +341,7 @@ function WorkspacesListPage({policies, allPolicyMembers, reimbursementAccount, r adminRoom: policyRooms?.[policy.id]?.adminRoom ?? policy.chatReportIDAdmins?.toString(), announceRoom: policyRooms?.[policy.id]?.announceRoom ?? policy.chatReportIDAnnounce?.toString(), ownerAccountID: policy.ownerAccountID, - role: policy.role, + role: PolicyUtils.getPolicyRole(policy), type: policy.type, }; }) diff --git a/src/types/onyx/Policy.ts b/src/types/onyx/Policy.ts index a21e98f4bfec..8f0ede2da7c8 100644 --- a/src/types/onyx/Policy.ts +++ b/src/types/onyx/Policy.ts @@ -273,9 +273,6 @@ type Policy = OnyxCommon.OnyxValueWithOfflineFeedback< /** The name of the policy */ name: string; - /** The current user's role in the policy */ - role: ValueOf; - /** The policy type */ type: ValueOf; @@ -331,7 +328,7 @@ type Policy = OnyxCommon.OnyxValueWithOfflineFeedback< submitsTo?: number; /** The employee list of the policy */ - employeeList?: OnyxTypes.PolicyMembers | []; + employeeList?: OnyxTypes.PolicyMembers; /** The reimbursement choice for policy */ reimbursementChoice?: ValueOf; diff --git a/src/types/onyx/PolicyMember.ts b/src/types/onyx/PolicyMember.ts index 366a7ef7d530..bb41a66affe0 100644 --- a/src/types/onyx/PolicyMember.ts +++ b/src/types/onyx/PolicyMember.ts @@ -1,8 +1,10 @@ +import type {ValueOf} from 'type-fest'; +import type CONST from '@src/CONST'; import type * as OnyxCommon from './OnyxCommon'; type PolicyMember = OnyxCommon.OnyxValueWithOfflineFeedback<{ /** Role of the user in the policy */ - role?: string; + role?: ValueOf; /** Email of the user */ email?: string; diff --git a/tests/actions/PolicyTest.ts b/tests/actions/PolicyTest.ts index 18a6337a9b93..96e4ba3b5ab5 100644 --- a/tests/actions/PolicyTest.ts +++ b/tests/actions/PolicyTest.ts @@ -55,7 +55,6 @@ describe('actions/Policy', () => { expect(policy?.id).toBe(policyID); expect(policy?.name).toBe(WORKSPACE_NAME); expect(policy?.type).toBe(CONST.POLICY.TYPE.TEAM); - expect(policy?.role).toBe(CONST.POLICY.ROLE.ADMIN); expect(policy?.owner).toBe(ESH_EMAIL); expect(policy?.isPolicyExpenseChatEnabled).toBe(true); expect(policy?.pendingAction).toBe(CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD); From 3a47aece74dab8e8100c435e0dcedc7c447dea3b Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Fri, 12 Apr 2024 21:26:47 +0530 Subject: [PATCH 2/4] Fixed tests --- src/libs/actions/TeachersUnite.ts | 1 - tests/actions/IOUTest.ts | 13 ++++++++++--- tests/unit/NextStepUtilsTest.ts | 6 +++++- tests/unit/ReportUtilsTest.ts | 18 +++++++++++++++--- tests/utils/LHNTestUtils.tsx | 7 +++++-- 5 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/libs/actions/TeachersUnite.ts b/src/libs/actions/TeachersUnite.ts index 1f8b32724bd4..903109d50fba 100644 --- a/src/libs/actions/TeachersUnite.ts +++ b/src/libs/actions/TeachersUnite.ts @@ -93,7 +93,6 @@ function addSchoolPrincipal(firstName: string, partnerUserID: string, lastName: isPolicyExpenseChatEnabled: true, type: CONST.POLICY.TYPE.CORPORATE, name: policyName, - role: CONST.POLICY.ROLE.USER, owner: sessionEmail, outputCurrency: allPersonalDetails?.[sessionAccountID]?.localCurrencyCode ?? CONST.CURRENCY.USD, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.ADD, diff --git a/tests/actions/IOUTest.ts b/tests/actions/IOUTest.ts index c8c74d4198ab..686d3b07921b 100644 --- a/tests/actions/IOUTest.ts +++ b/tests/actions/IOUTest.ts @@ -1678,10 +1678,14 @@ describe('actions/IOU', () => { {amount: 20000, comment: 'Double the amount!'}, { id: '123', - role: 'user', type: 'free', name: '', owner: '', + employeeList: { + [RORY_EMAIL]: { + role: 'user', + }, + }, outputCurrency: '', isPolicyExpenseChatEnabled: false, }, @@ -1833,11 +1837,15 @@ describe('actions/IOU', () => { {amount: 20000, comment: 'Double the amount!'}, { id: '123', - role: 'user', type: 'free', name: '', owner: '', outputCurrency: '', + employeeList: { + [RORY_EMAIL]: { + role: 'user', + }, + }, isPolicyExpenseChatEnabled: false, }, {}, @@ -2568,7 +2576,6 @@ describe('actions/IOU', () => { {amount: 20000, comment: 'Double the amount!'}, { id: '123', - role: 'user', type: 'free', name: '', owner: '', diff --git a/tests/unit/NextStepUtilsTest.ts b/tests/unit/NextStepUtilsTest.ts index 072a06748da9..659bf8681d50 100644 --- a/tests/unit/NextStepUtilsTest.ts +++ b/tests/unit/NextStepUtilsTest.ts @@ -28,8 +28,12 @@ describe('libs/NextStepUtils', () => { }, // Required props name: 'Policy', - role: 'admin', type: 'team', + employeeList: { + [currentUserEmail]: { + role: 'admin', + }, + }, outputCurrency: CONST.CURRENCY.USD, isPolicyExpenseChatEnabled: true, }; diff --git a/tests/unit/ReportUtilsTest.ts b/tests/unit/ReportUtilsTest.ts index b3c4f8bdb001..4ac4b290045a 100644 --- a/tests/unit/ReportUtilsTest.ts +++ b/tests/unit/ReportUtilsTest.ts @@ -51,9 +51,13 @@ const participantsPersonalDetails: PersonalDetailsList = { const policy: Policy = { id: '1', name: 'Vikings Policy', - role: 'user', type: 'free', owner: '', + employeeList: { + [currentUserEmail]: { + role: 'user', + }, + }, outputCurrency: '', isPolicyExpenseChatEnabled: false, }; @@ -435,8 +439,12 @@ describe('ReportUtils', () => { id: '3f54cca8', type: CONST.POLICY.TYPE.TEAM, name: '', - role: 'user', owner: '', + employeeList: { + [currentUserEmail]: { + role: 'user', + }, + }, outputCurrency: '', isPolicyExpenseChatEnabled: false, }; @@ -617,8 +625,12 @@ describe('ReportUtils', () => { autoReporting: true, autoReportingFrequency: CONST.POLICY.AUTO_REPORTING_FREQUENCIES.INSTANT, name: '', - role: 'user', owner: '', + employeeList: { + [currentUserEmail]: { + role: 'user', + }, + }, outputCurrency: '', isPolicyExpenseChatEnabled: false, }; diff --git a/tests/utils/LHNTestUtils.tsx b/tests/utils/LHNTestUtils.tsx index 0630fddb81b7..50c67daf5de3 100644 --- a/tests/utils/LHNTestUtils.tsx +++ b/tests/utils/LHNTestUtils.tsx @@ -243,12 +243,15 @@ function getFakePolicy(id = '1', name = 'Workspace-Test-001'): Policy { id, name, isFromFullPolicy: false, - role: 'admin', type: 'free', owner: 'myuser@gmail.com', outputCurrency: 'BRL', avatar: '', - employeeList: [], + employeeList: { + 'myuser@gmail.com': { + role: 'admin', + }, + }, isPolicyExpenseChatEnabled: true, lastModified: '1697323926777105', autoReporting: true, From 5d936555b97801ae6b246488649964a1ec241ee5 Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Fri, 12 Apr 2024 21:41:38 +0530 Subject: [PATCH 3/4] Fixed tests attempt 2 --- tests/unit/OptionsListUtilsTest.ts | 6 +++++- tests/utils/collections/policies.ts | 1 - tests/utils/collections/policyMembers.ts | 5 +++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/unit/OptionsListUtilsTest.ts b/tests/unit/OptionsListUtilsTest.ts index af5782b1ca32..385ac01a4ab0 100644 --- a/tests/unit/OptionsListUtilsTest.ts +++ b/tests/unit/OptionsListUtilsTest.ts @@ -325,10 +325,14 @@ describe('OptionsListUtils', () => { const POLICY: Policy = { id: policyID, name: 'Hero Policy', - role: 'user', type: 'free', owner: '', outputCurrency: '', + employeeList: { + 'tonystark@expensify.com': { + role: 'user', + }, + }, isPolicyExpenseChatEnabled: false, }; diff --git a/tests/utils/collections/policies.ts b/tests/utils/collections/policies.ts index 8dd04f4750a9..5f2b4eb4ef80 100644 --- a/tests/utils/collections/policies.ts +++ b/tests/utils/collections/policies.ts @@ -17,7 +17,6 @@ export default function createRandomPolicy(index: number): Policy { preventSelfApproval: randBoolean(), submitsTo: index, outputCurrency: randCurrencyCode(), - role: rand(Object.values(CONST.POLICY.ROLE)), owner: randEmail(), ownerAccountID: index, avatar: randAvatar(), diff --git a/tests/utils/collections/policyMembers.ts b/tests/utils/collections/policyMembers.ts index 076c8ddb2d3d..e3e83886250c 100644 --- a/tests/utils/collections/policyMembers.ts +++ b/tests/utils/collections/policyMembers.ts @@ -1,9 +1,10 @@ -import {randWord} from '@ngneat/falso'; +import {rand} from '@ngneat/falso'; +import CONST from '@src/CONST'; import type {PolicyMember} from '@src/types/onyx'; export default function createRandomPolicyMember(): PolicyMember { return { - role: randWord(), + role: rand(Object.values(CONST.POLICY.ROLE)), errors: {}, }; } From 37cf80751af09f3c7cf3bb9ec9297ed4619f9373 Mon Sep 17 00:00:00 2001 From: Shubham Agrawal Date: Wed, 17 Apr 2024 08:12:30 +0530 Subject: [PATCH 4/4] Fix type --- src/libs/actions/Policy.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/actions/Policy.ts b/src/libs/actions/Policy.ts index 6413a9f77794..ce5b58eb9790 100644 --- a/src/libs/actions/Policy.ts +++ b/src/libs/actions/Policy.ts @@ -1081,7 +1081,7 @@ function updateWorkspaceMembersRole(policyID: string, accountIDs: number[], newR key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { employeeList: { - ...memberRoles.reduce((member: Record, current) => { + ...memberRoles.reduce((member: Record; pendingAction: PendingAction}>, current) => { // eslint-disable-next-line no-param-reassign member[current.email] = {role: current?.role, pendingAction: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE}; return member; @@ -1098,7 +1098,7 @@ function updateWorkspaceMembersRole(policyID: string, accountIDs: number[], newR key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`, value: { employeeList: { - ...memberRoles.reduce((member: Record, current) => { + ...memberRoles.reduce((member: Record; pendingAction: PendingAction}>, current) => { // eslint-disable-next-line no-param-reassign member[current.email] = {role: current?.role, pendingAction: null}; return member;