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

Replaces usage of reimburserEmail with achAccount.reimburser #39017

Merged
merged 18 commits into from
Apr 3, 2024
Merged
Show file tree
Hide file tree
Changes from 12 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
4 changes: 2 additions & 2 deletions src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1287,8 +1287,8 @@ function isPayer(session: OnyxEntry<Session>, iouReport: OnyxEntry<Report>) {
const isManager = iouReport?.managerID === session?.accountID;
if (isPaidGroupPolicy(iouReport)) {
if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES) {
const isReimburser = session?.email === policy?.reimburserEmail;
return (!policy?.reimburserEmail || isReimburser) && (isApproved || isManager);
const isReimburser = session?.email === policy?.achAccount?.reimburser;
return (!policy?.achAccount?.reimburser || isReimburser) && (isApproved || isManager);
}
if (policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL) {
return isAdmin && (isApproved || isManager);
Expand Down
28 changes: 12 additions & 16 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -664,18 +664,17 @@ function setWorkspaceApprovalMode(policyID: string, approver: string, approvalMo
API.write(WRITE_COMMANDS.SET_WORKSPACE_APPROVAL_MODE, params, {optimisticData, failureData, successData});
}

function setWorkspacePayer(policyID: string, reimburserEmail: string, reimburserAccountID: number) {
function setWorkspacePayer(policyID: string, reimburserEmail: string) {
const policy = ReportUtils.getPolicy(policyID);

const optimisticData: OnyxUpdate[] = [
{
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
reimburserEmail,
reimburserAccountID,
errorFields: {reimburserEmail: null},
pendingFields: {reimburserEmail: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE},
achAccount: {reimburser: reimburserEmail},
errorFields: {reimburser: null},
pendingFields: {reimburser: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE},
},
},
];
Expand All @@ -685,8 +684,8 @@ function setWorkspacePayer(policyID: string, reimburserEmail: string, reimburser
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
errorFields: {reimburserEmail: null},
pendingFields: {reimburserEmail: null},
errorFields: {reimburser: null},
pendingFields: {reimburser: null},
},
},
];
Expand All @@ -696,10 +695,9 @@ function setWorkspacePayer(policyID: string, reimburserEmail: string, reimburser
onyxMethod: Onyx.METHOD.MERGE,
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
reimburserEmail: policy.reimburserEmail ?? null,
reimburserAccountID: policy.reimburserAccountID ?? null,
errorFields: {reimburserEmail: ErrorUtils.getMicroSecondOnyxError('workflowsPayerPage.genericErrorMessage')},
pendingFields: {reimburserEmail: null},
achAccount: policy.achAccount ?? null,
rlinoz marked this conversation as resolved.
Show resolved Hide resolved
errorFields: {reimburser: ErrorUtils.getMicroSecondOnyxError('workflowsPayerPage.genericErrorMessage')},
pendingFields: {reimburser: null},
},
},
];
Expand All @@ -713,7 +711,7 @@ function clearPolicyErrorField(policyID: string, fieldName: string) {
Onyx.merge(`${ONYXKEYS.COLLECTION.POLICY}${policyID}`, {errorFields: {[fieldName]: null}});
}

function setWorkspaceReimbursement(policyID: string, reimbursementChoice: ValueOf<typeof CONST.POLICY.REIMBURSEMENT_CHOICES>, reimburserAccountID: number, reimburserEmail: string) {
function setWorkspaceReimbursement(policyID: string, reimbursementChoice: ValueOf<typeof CONST.POLICY.REIMBURSEMENT_CHOICES>, reimburserEmail: string) {
const policy = ReportUtils.getPolicy(policyID);

const optimisticData: OnyxUpdate[] = [
Expand All @@ -722,8 +720,7 @@ function setWorkspaceReimbursement(policyID: string, reimbursementChoice: ValueO
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
reimbursementChoice,
reimburserAccountID,
reimburserEmail,
achAccount: {reimburser: reimburserEmail},
errorFields: {reimbursementChoice: null},
pendingFields: {reimbursementChoice: CONST.RED_BRICK_ROAD_PENDING_ACTION.UPDATE},
},
Expand All @@ -747,8 +744,7 @@ function setWorkspaceReimbursement(policyID: string, reimbursementChoice: ValueO
key: `${ONYXKEYS.COLLECTION.POLICY}${policyID}`,
value: {
reimbursementChoice: policy.reimbursementChoice ?? null,
reimburserAccountID: policy.reimburserAccountID ?? null,
reimburserEmail: policy.reimburserEmail ?? null,
achAccount: policy.achAccount ?? null,
rlinoz marked this conversation as resolved.
Show resolved Hide resolved
errorFields: {reimbursementChoice: ErrorUtils.getMicroSecondOnyxError('common.genericErrorMessage')},
pendingFields: {reimbursementChoice: null},
},
Expand Down
2 changes: 1 addition & 1 deletion src/pages/workspace/WorkspaceInitialPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ function WorkspaceInitialPage({policyDraft, policy: policyProp, policyMembers, r
icon: Expensicons.Workflows,
action: singleExecution(waitForNavigate(() => Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS.getRoute(policyID)))),
routeName: SCREENS.WORKSPACE.WORKFLOWS,
brickRoadIndicator: !isEmptyObject(policy?.errorFields?.reimburserEmail ?? {}) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined,
brickRoadIndicator: !isEmptyObject(policy?.errorFields?.reimburser ?? {}) ? CONST.BRICK_ROAD_INDICATOR_STATUS.ERROR : undefined,
});
}

Expand Down
30 changes: 10 additions & 20 deletions src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
import type {Beta, Session} from '@src/types/onyx';
import type {Beta} from '@src/types/onyx';
import ToggleSettingOptionRow from './ToggleSettingsOptionRow';
import type {ToggleSettingOptionRowProps} from './ToggleSettingsOptionRow';
import {getAutoReportingFrequencyDisplayNames} from './WorkspaceAutoReportingFrequencyPage';
Expand All @@ -38,12 +38,10 @@ import type {AutoReportingFrequencyKey} from './WorkspaceAutoReportingFrequencyP
type WorkspaceWorkflowsPageOnyxProps = {
/** Beta features list */
betas: OnyxEntry<Beta[]>;
/** Policy details */
session: OnyxEntry<Session>;
};
type WorkspaceWorkflowsPageProps = WithPolicyProps & WorkspaceWorkflowsPageOnyxProps & StackScreenProps<WorkspacesCentralPaneNavigatorParamList, typeof SCREENS.WORKSPACE.WORKFLOWS>;

function WorkspaceWorkflowsPage({policy, betas, route, session}: WorkspaceWorkflowsPageProps) {
function WorkspaceWorkflowsPage({policy, betas, route}: WorkspaceWorkflowsPageProps) {
const {translate, preferredLocale} = useLocalize();
const styles = useThemeStyles();
const {isSmallScreenWidth} = useWindowDimensions();
Expand All @@ -54,11 +52,10 @@ function WorkspaceWorkflowsPage({policy, betas, route, session}: WorkspaceWorkfl
const canUseDelayedSubmission = Permissions.canUseWorkflowsDelayedSubmission(betas);
const [isCurrencyModalOpen, setIsCurrencyModalOpen] = useState(false);

const displayNameForAuthorizedPayer = useMemo(() => {
const personalDetails = PersonalDetailsUtils.getPersonalDetailsByIDs([policy?.reimburserAccountID ?? 0], session?.accountID ?? 0);
const displayNameFromReimburserEmail = PersonalDetailsUtils.getPersonalDetailByEmail(policy?.reimburserEmail ?? '')?.displayName ?? policy?.reimburserEmail;
return displayNameFromReimburserEmail ?? personalDetails?.[0]?.displayName;
}, [policy?.reimburserAccountID, policy?.reimburserEmail, session?.accountID]);
const displayNameForAuthorizedPayer = useMemo(
() => PersonalDetailsUtils.getPersonalDetailByEmail(policy?.achAccount?.reimburser ?? '')?.displayName ?? policy?.achAccount?.reimburser,
[policy?.achAccount?.reimburser],
);

const onPressAutoReportingFrequency = useCallback(() => Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_AUTOREPORTING_FREQUENCY.getRoute(policy?.id ?? '')), [policy?.id]);

Expand Down Expand Up @@ -90,7 +87,7 @@ function WorkspaceWorkflowsPage({policy, betas, route, session}: WorkspaceWorkfl
if (accountNumber && bankDisplayName !== accountNumber) {
bankDisplayName += ` ${accountNumber.slice(-5)}`;
}
const hasReimburserEmailError = !!policy?.errorFields?.reimburserEmail;
const hasReimburserEmailError = !!policy?.errorFields?.reimburser;
rlinoz marked this conversation as resolved.
Show resolved Hide resolved
const hasApprovalError = !!policy?.errorFields?.approvalMode;
const hasDelayedSubmissionError = !!policy?.errorFields?.autoReporting;

Expand Down Expand Up @@ -172,11 +169,8 @@ function WorkspaceWorkflowsPage({policy, betas, route, session}: WorkspaceWorkfl
newReimbursementChoice = hasVBA ? CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES : CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_MANUAL;
}

const newReimburserAccountID =
// eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
PersonalDetailsUtils.getPersonalDetailByEmail(policy?.reimburserEmail ?? '')?.accountID || policy?.reimburserAccountID || policy?.ownerAccountID;
const newReimburserEmail = PersonalDetailsUtils.getPersonalDetailsByIDs([newReimburserAccountID ?? 0], session?.accountID ?? 0)?.[0]?.login;
Policy.setWorkspaceReimbursement(policy?.id ?? '', newReimbursementChoice, newReimburserAccountID ?? 0, newReimburserEmail ?? '');
const newReimburserEmail = policy?.achAccount?.reimburser ?? policy?.owner;
Policy.setWorkspaceReimbursement(policy?.id ?? '', newReimbursementChoice, newReimburserEmail ?? '');
},
subMenuItems: (
<>
Expand All @@ -203,7 +197,7 @@ function WorkspaceWorkflowsPage({policy, betas, route, session}: WorkspaceWorkfl
/>
{hasVBA && policy?.reimbursementChoice === CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES && (
<OfflineWithFeedback
pendingAction={policy?.pendingFields?.reimburserEmail}
pendingAction={policy?.pendingFields?.reimburser}
errors={ErrorUtils.getLatestErrorField(policy ?? {}, CONST.POLICY.COLLECTION_KEYS.REIMBURSER_EMAIL)}
rlinoz marked this conversation as resolved.
Show resolved Hide resolved
onClose={() => Policy.clearPolicyErrorField(policy?.id ?? '', CONST.POLICY.COLLECTION_KEYS.REIMBURSER_EMAIL)}
errorRowStyles={[styles.ml7]}
Expand Down Expand Up @@ -241,7 +235,6 @@ function WorkspaceWorkflowsPage({policy, betas, route, session}: WorkspaceWorkfl
preferredLocale,
canUseDelayedSubmission,
displayNameForAuthorizedPayer,
session?.accountID,
isOffline,
isPolicyAdmin,
]);
Expand Down Expand Up @@ -319,8 +312,5 @@ export default withPolicy(
betas: {
key: ONYXKEYS.BETAS,
},
session: {
key: ONYXKEYS.SESSION,
},
})(WorkspaceWorkflowsPage),
);
24 changes: 6 additions & 18 deletions src/pages/workspace/workflows/WorkspaceWorkflowsPayerPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function WorkspaceWorkflowsPayerPage({route, policy, policyMembers, personalDeta
/>
);

const isAuthorizedPayer = policy?.reimburserEmail === details?.login ?? policy?.reimburserAccountID === accountID;
const isAuthorizedPayer = policy?.achAccount?.reimburser === details?.login;

const formattedMember = {
keyForList: accountIDKey,
Expand All @@ -106,28 +106,17 @@ function WorkspaceWorkflowsPayerPage({route, policy, policyMembers, personalDeta
},
],
errors: policyMember.errors,
pendingAction: policyMember.pendingAction ?? isAuthorizedPayer ? policy?.pendingFields?.reimburserEmail : null,
pendingAction: policyMember.pendingAction ?? isAuthorizedPayer ? policy?.pendingFields?.reimburser : null,
};

if (policy?.reimburserEmail === details?.login ?? policy?.reimburserAccountID === accountID) {
if (policy?.achAccount?.reimburser === details?.login) {
rlinoz marked this conversation as resolved.
Show resolved Hide resolved
authorizedPayerDetails.push(formattedMember);
} else {
policyAdminDetails.push(formattedMember);
}
});
return [policyAdminDetails, authorizedPayerDetails];
}, [
personalDetails,
policyMembers,
translate,
policy?.reimburserEmail,
isDeletedPolicyMember,
policy?.owner,
styles,
StyleUtils,
policy?.reimburserAccountID,
policy?.pendingFields?.reimburserEmail,
]);
}, [personalDetails, policyMembers, translate, policy?.achAccount?.reimburser, isDeletedPolicyMember, policy?.owner, styles, StyleUtils, policy?.pendingFields?.reimburser]);

const sections: MembersSection[] = useMemo(() => {
const sectionsArray: MembersSection[] = [];
Expand Down Expand Up @@ -171,13 +160,12 @@ function WorkspaceWorkflowsPayerPage({route, policy, policyMembers, personalDeta
const setPolicyAuthorizedPayer = (member: MemberOption) => {
const authorizedPayerEmail = personalDetails?.[member.accountID]?.login ?? '';

if (policy?.reimburserEmail === authorizedPayerEmail || policy?.reimbursementChoice !== CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES) {
if (policy?.achAccount?.reimburser === authorizedPayerEmail || policy?.reimbursementChoice !== CONST.POLICY.REIMBURSEMENT_CHOICES.REIMBURSEMENT_YES) {
Navigation.goBack();
return;
}

const authorizedPayerAccountID = member.accountID;
Policy.setWorkspacePayer(policy?.id ?? '', authorizedPayerEmail, authorizedPayerAccountID);
Policy.setWorkspacePayer(policy?.id ?? '', authorizedPayerEmail);
Navigation.goBack();
};

Expand Down
9 changes: 2 additions & 7 deletions src/types/onyx/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ type ACHAccount = {
routingNumber: string;
addressName: string;
bankName: string;
reimburser: string;
};

type AutoReportingOffset = number | ValueOf<typeof CONST.POLICY.AUTO_REPORTING_OFFSET>;
Expand Down Expand Up @@ -390,12 +391,6 @@ type Policy = OnyxCommon.OnyxValueWithOfflineFeedback<
/** Collection of tax rates attached to a policy */
taxRates?: TaxRatesWithDefault;

/** Email of the reimburser when reimbursement is set direct */
reimburserEmail?: string;

/** AccountID of the reimburser when reimbursement is set direct */
reimburserAccountID?: number;

/** ReportID of the admins room for this workspace */
chatReportIDAdmins?: number;

Expand Down Expand Up @@ -438,7 +433,7 @@ type Policy = OnyxCommon.OnyxValueWithOfflineFeedback<
/** Indicates if the Policy ownership change is failed */
isChangeOwnerFailed?: boolean;
} & Partial<PendingJoinRequestPolicy>,
'generalSettings' | 'addWorkspaceRoom'
'generalSettings' | 'addWorkspaceRoom' | keyof ACHAccount
>;

export default Policy;
Expand Down
Loading