Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions src/CONST/SENTRY_LABEL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1477,6 +1477,7 @@ const SENTRY_LABEL = {
PAY: 'HomePage-ForYouItem-Pay',
EXPORT: 'HomePage-ForYouItem-Export',
REVIEW_DOMAIN_ADMIN_REQUESTS: 'HomePage-ForYouItem-ReviewDomainAdminRequests',
APPROVE_ACCOUNT_MERGE_REQUESTS: 'HomePage-ForYouItem-ApproveAccountMergeRequests',
},
FOR_YOU_ITEM_BUTTON: {
REVIEW_EXPENSES: 'HomePage-ForYouItemButton-ReviewExpenses',
Expand All @@ -1485,6 +1486,7 @@ const SENTRY_LABEL = {
PAY: 'HomePage-ForYouItemButton-Pay',
EXPORT: 'HomePage-ForYouItemButton-Export',
REVIEW_DOMAIN_ADMIN_REQUESTS: 'HomePage-ForYouItemButton-ReviewDomainAdminRequests',
APPROVE_ACCOUNT_MERGE_REQUESTS: 'HomePage-ForYouItemButton-ApproveAccountMergeRequests',
},
TIME_SENSITIVE_ITEM: {
ACTIVATE_CARD: 'HomePage-TimeSensitiveItem-ActivateCard',
Expand Down
5 changes: 4 additions & 1 deletion src/ONYXKEYS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1073,8 +1073,10 @@ const ONYXKEYS = {
POLICY_MERGE_HR_INITIAL_SYNC_MODAL_SHOWN: 'policyMergeHRInitialSyncModalShown_',
POLICY_MERGE_ATS_INITIAL_SYNC_MODAL_SHOWN: 'policyMergeATSInitialSyncModalShown_',

/** Pending domain-controlled account merge requests, keyed by requestID. Requesters see only their own entry; admins see what they are authorized to review. */
/** The current user's own pending domain-controlled account merge request, keyed by requestID. */
DOMAIN_ACCOUNT_MERGE_REQUEST: 'domainAccountMergeRequest_',
/** Pending domain-controlled account merge requests the current user is authorized to review, keyed by the target domain's accountID. */
DOMAIN_ACCOUNT_MERGE_REQUESTS_TO_REVIEW: 'domainAccountMergeRequestsToReview_',
RULE: 'rules_',
WORKSPACE_INVITE_MEMBERS_DRAFT: 'workspaceInviteMembersDraft_',
WORKSPACE_INVITE_MESSAGE_DRAFT: 'workspaceInviteMessageDraft_',
Expand Down Expand Up @@ -1845,6 +1847,7 @@ type OnyxCollectionValuesMapping = {
[ONYXKEYS.COLLECTION.POLICY_MERGE_HR_INITIAL_SYNC_MODAL_SHOWN]: boolean;
[ONYXKEYS.COLLECTION.POLICY_MERGE_ATS_INITIAL_SYNC_MODAL_SHOWN]: boolean;
[ONYXKEYS.COLLECTION.DOMAIN_ACCOUNT_MERGE_REQUEST]: OnyxTypes.DomainAccountMergeRequest;
[ONYXKEYS.COLLECTION.DOMAIN_ACCOUNT_MERGE_REQUESTS_TO_REVIEW]: OnyxTypes.DomainAccountMergeRequestsToReview;
[ONYXKEYS.COLLECTION.SNAPSHOT]: OnyxTypes.SearchResults;
[ONYXKEYS.COLLECTION.INSIGHTS]: OnyxTypes.InsightsDashboard;
[ONYXKEYS.COLLECTION.INSIGHTS_TAG_LEVELS]: OnyxTypes.InsightsResponseTagLevels;
Expand Down
4 changes: 4 additions & 0 deletions src/languages/de.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,10 @@ const translations: TranslationDeepObject<typeof en> = {
one: 'Prüfen Sie 1 Domain-Admin-Anfrage',
other: `Prüfen Sie ${count} Domain-Admin-Anfragen`,
}),
approveAccountMergeRequests: ({count}: {count: number}) => ({
one: '1 Kontozusammenführungsanfrage genehmigen',
other: `${count} Kontozusammenführungsanfragen genehmigen`,
}),
reportSubmitted: 'Bericht eingereicht',
reportApproved: 'Bericht genehmigt',
reportPaid: 'Bericht bezahlt',
Expand Down
4 changes: 4 additions & 0 deletions src/languages/el.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1187,6 +1187,10 @@ const translations: TranslationDeepObject<typeof en> = {
one: 'Ελέγξτε 1 αίτημα διαχειριστή τομέα',
other: `Ελέγξτε ${count} αιτήματα διαχειριστή τομέα`,
}),
approveAccountMergeRequests: ({count}: {count: number}) => ({
one: 'Έγκριση 1 αιτήματος συγχώνευσης λογαριασμού',
other: `Εγκρίνετε ${count} αιτήματα συγχώνευσης λογαριασμών`,
}),
submit: ({count}: {count: number}) => ({
one: 'Υποβολή 1 αναφοράς',
other: `Υποβολή ${count} αναφορών`,
Expand Down
4 changes: 4 additions & 0 deletions src/languages/en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1307,6 +1307,10 @@ const translations = {
one: 'Review 1 domain admin request',
other: `Review ${count} domain admin requests`,
}),
approveAccountMergeRequests: ({count}: {count: number}) => ({
one: 'Approve 1 account merge request',
other: `Approve ${count} account merge requests`,
}),
begin: 'Begin',
reportSubmitted: 'Report submitted',
reportApproved: 'Report approved',
Expand Down
4 changes: 4 additions & 0 deletions src/languages/es.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1186,6 +1186,10 @@ const translations: TranslationDeepObject<typeof en> = {
one: 'Revisa 1 solicitud de administrador de dominio',
other: `Revisa ${count} solicitudes de administrador de dominio`,
}),
approveAccountMergeRequests: ({count}: {count: number}) => ({
one: 'Aprobar 1 solicitud de fusión de cuenta',
other: `Aprobar ${count} solicitudes de fusión de cuentas`,
}),
reportSubmitted: 'Informe enviado',
reportApproved: 'Informe aprobado',
reportPaid: 'Informe pagado',
Expand Down
4 changes: 4 additions & 0 deletions src/languages/fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1178,6 +1178,10 @@ const translations: TranslationDeepObject<typeof en> = {
one: `Examiner ${count} demande d'administrateur de domaine`,
other: `Examiner ${count} demandes d'administrateur de domaine`,
}),
approveAccountMergeRequests: ({count}: {count: number}) => ({
one: 'Approuver 1 demande de fusion de compte',
other: `Approuver ${count} demandes de fusion de comptes`,
}),
reportSubmitted: 'Note de frais soumise',
reportApproved: 'Note de frais approuvée',
reportPaid: 'Note de frais payée',
Expand Down
4 changes: 4 additions & 0 deletions src/languages/it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1177,6 +1177,10 @@ const translations: TranslationDeepObject<typeof en> = {
one: 'Esamina 1 richiesta di amministratore del dominio',
other: `Esamina ${count} richieste di amministratore del dominio`,
}),
approveAccountMergeRequests: ({count}: {count: number}) => ({
one: 'Approva 1 richiesta di unione account',
other: `Approva ${count} richieste di unione dell’account`,
}),
reportSubmitted: 'Report inviato',
reportApproved: 'Report approvato',
reportPaid: 'Report pagato',
Expand Down
4 changes: 4 additions & 0 deletions src/languages/ja.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1162,6 +1162,10 @@ const translations: TranslationDeepObject<typeof en> = {
one: `${count} 件のドメイン管理者リクエストを確認`,
other: `${count} 件のドメイン管理者リクエストを確認`,
}),
approveAccountMergeRequests: ({count}: {count: number}) => ({
one: '1件のアカウント統合リクエストを承認',
other: `${count} 件のアカウント統合リクエストを承認します`,
}),
reportSubmitted: 'レポートを送信しました',
reportApproved: 'レポートを承認しました',
reportPaid: 'レポートは支払済みです',
Expand Down
4 changes: 4 additions & 0 deletions src/languages/nl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1173,6 +1173,10 @@ const translations: TranslationDeepObject<typeof en> = {
one: 'Beoordeel 1 domeinbeheerdersverzoek',
other: `Beoordeel ${count} domeinbeheerdersverzoeken`,
}),
approveAccountMergeRequests: ({count}: {count: number}) => ({
one: '1 verzoek tot samenvoegen van accounts goedkeuren',
other: `Keur ${count} verzoeken tot samenvoegen van accounts goed`,
}),
reportSubmitted: 'Declaratie ingediend',
reportApproved: 'Rapport goedgekeurd',
reportPaid: 'Rapport betaald',
Expand Down
4 changes: 4 additions & 0 deletions src/languages/pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,10 @@ const translations: TranslationDeepObject<typeof en> = {
many: `Przejrzyj ${count} próśb administratora domeny`,
other: `Przejrzyj ${count} prośby administratora domeny`,
}),
approveAccountMergeRequests: ({count}: {count: number}) => ({
one: 'Zatwierdź 1 prośbę o scalenie kont',
other: `Zatwierdź ${count} prośby o połączenie konta`,
}),
reportSubmitted: 'Raport wysłany',
reportApproved: 'Raport zatwierdzony',
reportPaid: 'Raport opłacony',
Expand Down
4 changes: 4 additions & 0 deletions src/languages/pt-BR.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1176,6 +1176,10 @@ const translations: TranslationDeepObject<typeof en> = {
one: `Revisar ${count} solicitação de administrador de domínio`,
other: `Revisar ${count} solicitações de administrador de domínio`,
}),
approveAccountMergeRequests: ({count}: {count: number}) => ({
one: 'Aprovar 1 solicitação de mesclagem de conta',
other: `Aprovar ${count} solicitações de mesclagem de conta`,
}),
reportSubmitted: 'Relatório enviado',
reportApproved: 'Relatório aprovado',
reportPaid: 'Relatório pago',
Expand Down
4 changes: 4 additions & 0 deletions src/languages/zh-hans.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1141,6 +1141,10 @@ const translations: TranslationDeepObject<typeof en> = {
one: `审核 ${count} 个域管理员请求`,
other: `审核 ${count} 个域管理员请求`,
}),
approveAccountMergeRequests: ({count}: {count: number}) => ({
one: '批准 1 个账户合并请求',
other: `批准 ${count} 个账户合并请求`,
}),
reportSubmitted: '报表已提交',
reportApproved: '报销单已批准',
reportPaid: '报销单已支付',
Expand Down
1 change: 1 addition & 0 deletions src/libs/ExportOnyxState/masking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,7 @@ const onyxKeysToMaskFragileData = new Set<string>([
ONYXKEYS.COLLECTION.DEPRECATED_POLICY_MEMBER_LIST,
ONYXKEYS.COLLECTION.DOMAIN,
ONYXKEYS.COLLECTION.DOMAIN_ACCOUNT_MERGE_REQUEST,
ONYXKEYS.COLLECTION.DOMAIN_ACCOUNT_MERGE_REQUESTS_TO_REVIEW,
ONYXKEYS.COLLECTION.DOMAIN_ERRORS,
ONYXKEYS.COLLECTION.DOMAIN_PENDING_ACTIONS,
ONYXKEYS.COLLECTION.EXPORT_DOWNLOAD,
Expand Down
11 changes: 11 additions & 0 deletions src/pages/home/ForYouSection/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import React, {useEffect} from 'react';
import ConciergePromptBox from './ConciergePromptBox';
import ForYouBody from './ForYouBody';
import shouldHideForYouSection from './shouldHideForYouSection';
import useApproveAccountMergeRequests from './useApproveAccountMergeRequests';
import useClearHomeTodoReviewOnFocus from './useClearHomeTodoReviewOnFocus';
import useReviewDomainAdminRequests from './useReviewDomainAdminRequests';
import useReviewFlaggedExpenses from './useReviewFlaggedExpenses';
Expand All @@ -51,6 +52,7 @@ function ForYouSection({isInitialLoad, isConciergeMenuVisible, setIsConciergeMen
const [hasSeenForYouTodo = false] = useOnyx(ONYXKEYS.NVP_HAS_SEEN_FOR_YOU_TODO);
const {count: flaggedExpensesCount, reviewExpenses} = useReviewFlaggedExpenses();
const {count: domainAdminRequestsCount, reviewDomainAdminRequests} = useReviewDomainAdminRequests();
const {count: accountMergeRequestsCount, approveAccountMergeRequests} = useApproveAccountMergeRequests();
const timeSensitiveItems = useTimeSensitiveItems();
useClearHomeTodoReviewOnFocus();

Expand Down Expand Up @@ -129,6 +131,15 @@ function ForYouSection({isInitialLoad, isConciergeMenuVisible, setIsConciergeMen
translationKey: 'homePage.forYouSection.reviewDomainAdminRequests' as const,
handler: reviewDomainAdminRequests,
},
{
key: 'approveAccountMergeRequests',
sentryLabel: CONST.SENTRY_LABEL.HOME_PAGE.FOR_YOU_ITEM.APPROVE_ACCOUNT_MERGE_REQUESTS,
buttonSentryLabel: CONST.SENTRY_LABEL.HOME_PAGE.FOR_YOU_ITEM_BUTTON.APPROVE_ACCOUNT_MERGE_REQUESTS,
count: accountMergeRequestsCount,
icon: icons.UserShield,
translationKey: 'homePage.forYouSection.approveAccountMergeRequests' as const,
handler: approveAccountMergeRequests,
},
].filter((item) => item.count > 0);

const hasAnyTodos = todoItems.length > 0;
Expand Down
44 changes: 44 additions & 0 deletions src/pages/home/ForYouSection/useApproveAccountMergeRequests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import useOnyx from '@hooks/useOnyx';
import usePermissions from '@hooks/usePermissions';
import useResponsiveLayout from '@hooks/useResponsiveLayout';

import navigateToDomainRouteWithSidebarSync from '@libs/Navigation/helpers/navigateToDomainRouteWithSidebarSync';
import Navigation from '@libs/Navigation/Navigation';

import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import {getPendingAccountMergeApprovals} from '@src/selectors/Domain';

type ApproveAccountMergeRequests = {
/** Number of pending account merge requests the current user can approve, used to decide whether to render the approval row */
count: number;

/** accountIDs of the domains that have at least one approvable request, used to count distinct marked domain rows */
domainAccountIDs: number[];

/** Opens the domain members page for the one domain with pending requests, or the domains list when there are several. */
approveAccountMergeRequests: () => void;
};

/** Handles the "Approve X account merge request(s)" row on the "For you" section of the home page. */
function useApproveAccountMergeRequests(): ApproveAccountMergeRequests {
const {shouldUseNarrowLayout} = useResponsiveLayout();
const {isBetaEnabled} = usePermissions();
const [reviewableMergeRequestsByDomain] = useOnyx(ONYXKEYS.COLLECTION.DOMAIN_ACCOUNT_MERGE_REQUESTS_TO_REVIEW);

const {count, domainAccountIDs} = isBetaEnabled(CONST.BETAS.MERGE_DOMAIN_ACCOUNTS) ? getPendingAccountMergeApprovals(reviewableMergeRequestsByDomain) : {count: 0, domainAccountIDs: []};

const approveAccountMergeRequests = () => {
const domainAccountID = domainAccountIDs.at(0);
if (domainAccountIDs.length === 1 && domainAccountID !== undefined) {
navigateToDomainRouteWithSidebarSync(ROUTES.DOMAIN_MEMBERS.getRoute(domainAccountID), domainAccountID, shouldUseNarrowLayout);
Comment thread
dukenv0307 marked this conversation as resolved.
Resolved
return;
}
Navigation.navigate(ROUTES.DOMAINS_LIST.getRoute());
};

return {count, domainAccountIDs, approveAccountMergeRequests};
}

export default useApproveAccountMergeRequests;
47 changes: 46 additions & 1 deletion src/selectors/Domain.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {CardFeeds, Domain, DomainAccountMergeRequest, DomainErrors, DomainPendingActions, DomainSecurityGroup, DomainSettings, SamlMetadata} from '@src/types/onyx';
import type {
CardFeeds,
Domain,
DomainAccountMergeRequest,
DomainAccountMergeRequestsToReview,
DomainErrors,
DomainPendingActions,
DomainSecurityGroup,
DomainSettings,
SamlMetadata,
} from '@src/types/onyx';
import type {SecurityGroupKey, UserSecurityGroupData} from '@src/types/onyx/Domain';
import type {DomainSecurityGroupErrors} from '@src/types/onyx/DomainErrors';
import type {DomainSecurityGroupPendingActions} from '@src/types/onyx/DomainPendingActions';
Expand Down Expand Up @@ -300,6 +310,40 @@ function getPendingDomainAdminRequests(
return count > 0 ? {count, domainAccountIDs} : EMPTY_PENDING_DOMAIN_ADMIN_REQUESTS;
}

type PendingAccountMergeApprovals = {
/** Total pending account merge requests the current user can approve across every domain they administer */
count: number;
/** accountIDs of the domains that contributed at least one pending request, for navigation and GBR indicators */
domainAccountIDs: number[];
};

const EMPTY_PENDING_ACCOUNT_MERGE_APPROVALS: PendingAccountMergeApprovals = {count: 0, domainAccountIDs: []};

/** Counts the merge requests the current user can review (approve or deny) from the collection the backend hydrates, and collects their distinct target domains. */
function getPendingAccountMergeApprovals(reviewableMergeRequestsByDomain: OnyxCollection<DomainAccountMergeRequestsToReview>): PendingAccountMergeApprovals {
if (!reviewableMergeRequestsByDomain) {
return EMPTY_PENDING_ACCOUNT_MERGE_APPROVALS;
}

let count = 0;
const domainAccountIDs = new Set<number>();
for (const [key, domainRequests] of Object.entries(reviewableMergeRequestsByDomain)) {
if (!domainRequests) {
continue;
}

const domainCount = Object.values(domainRequests).filter((request) => !!request).length;
if (domainCount === 0) {
continue;
}

count += domainCount;
domainAccountIDs.add(Number(key.replace(ONYXKEYS.COLLECTION.DOMAIN_ACCOUNT_MERGE_REQUESTS_TO_REVIEW, '')));
}

return count > 0 ? {count, domainAccountIDs: [...domainAccountIDs]} : EMPTY_PENDING_ACCOUNT_MERGE_APPROVALS;
}

/** Creates a selector that extracts the pending action for a security group's setting */
function domainSecurityGroupSettingPendingActionSelector(settingName: keyof DomainSecurityGroupPendingActions, groupID?: string) {
return (domainPendingActions: OnyxEntry<DomainPendingActions>) => {
Expand Down Expand Up @@ -352,6 +396,7 @@ export {
pendingAdminRequesterAccountIDsSelector,
adminshipRequesterPendingActionSelector,
getPendingDomainAdminRequests,
getPendingAccountMergeApprovals,
selectGroupByID,
domainSecurityGroupSettingPendingActionSelector,
domainSecurityGroupSettingErrorsSelector,
Expand Down
6 changes: 6 additions & 0 deletions src/types/onyx/DomainAccountMergeRequestsToReview.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import type DomainAccountMergeRequest from './DomainAccountMergeRequest';

/** The merge requests the current user is authorized to review on one domain, keyed by requestID. */
type DomainAccountMergeRequestsToReview = Record<string, DomainAccountMergeRequest>;

export default DomainAccountMergeRequestsToReview;
2 changes: 2 additions & 0 deletions src/types/onyx/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import type DismissedReferralBanners from './DismissedReferralBanners';
import type Domain from './Domain';
import type {DomainSecurityGroup, SamlMetadata, UserSecurityGroupData} from './Domain';
import type DomainAccountMergeRequest from './DomainAccountMergeRequest';
import type DomainAccountMergeRequestsToReview from './DomainAccountMergeRequestsToReview';
import type DomainErrors from './DomainErrors';
import type DomainHighlightItems from './DomainHighlightItems';
import type DomainPendingActions from './DomainPendingActions';
Expand Down Expand Up @@ -325,6 +326,7 @@ export type {
DismissedReferralBanners,
Domain,
DomainAccountMergeRequest,
DomainAccountMergeRequestsToReview,
Download,
ExportDownload,
BulkAction,
Expand Down
Loading
Loading