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

[Simplified Collect][Workflows] Select workspace approver #37391

Merged
merged 108 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
646b689
add spend route
rushatgabhane Feb 27, 2024
08b1ed2
add spend route
rushatgabhane Feb 27, 2024
52d78fa
add approver to stack nav
rushatgabhane Feb 27, 2024
e30eb65
open workflow page on click
rushatgabhane Feb 27, 2024
b45c106
add dummy approver page
rushatgabhane Feb 27, 2024
c335676
fix linking
rushatgabhane Feb 27, 2024
7028951
fix tpo
rushatgabhane Feb 27, 2024
15704d4
rename
rushatgabhane Feb 27, 2024
90beac6
rename: remove spend
rushatgabhane Feb 27, 2024
e254f56
add api type
rushatgabhane Feb 27, 2024
bcd89b7
link write api params
rushatgabhane Feb 27, 2024
c814c51
fix policy id route
rushatgabhane Feb 27, 2024
d4e4de1
rm console
rushatgabhane Feb 27, 2024
84d4d35
use policy members
rushatgabhane Feb 27, 2024
f215f03
add settings to routes as per doc
rushatgabhane Feb 27, 2024
353d350
get personal details for policy members
rushatgabhane Feb 27, 2024
c65636b
get personal details for policy members
rushatgabhane Feb 28, 2024
3f524ba
add check for approver
rushatgabhane Feb 28, 2024
1d325d1
add all section
rushatgabhane Feb 28, 2024
1e4e5cb
add all section
rushatgabhane Feb 28, 2024
4e0d42b
add all section
rushatgabhane Feb 28, 2024
97dd3a2
add all section 0 offset
rushatgabhane Feb 28, 2024
54f846e
add all section 0 offset
rushatgabhane Feb 28, 2024
f5a0592
add all section 0 offset
rushatgabhane Feb 28, 2024
76d03fa
add approver section
rushatgabhane Feb 28, 2024
06399aa
add approver section
rushatgabhane Feb 28, 2024
eeaae97
add approver section
rushatgabhane Feb 28, 2024
8a058da
fix index offset for all
rushatgabhane Feb 28, 2024
4c629b6
make api call on approver select
rushatgabhane Feb 28, 2024
a9fc405
add set approver action
rushatgabhane Feb 28, 2024
73b8245
add set approver action
rushatgabhane Feb 28, 2024
89e42af
add set approver action
rushatgabhane Feb 28, 2024
2f46ead
go back on set approver
rushatgabhane Feb 28, 2024
5a2ed40
rm comment
rushatgabhane Feb 28, 2024
ec63de4
Merge branch 'Expensify:main' into approval-page
rushatgabhane Feb 28, 2024
a88070c
fix lint
rushatgabhane Feb 28, 2024
56ffb47
Merge branch 'approval-page' of github.com:rushatgabhane/exfy into ap…
rushatgabhane Feb 28, 2024
30655d8
rm setworkspace approver command
rushatgabhane Feb 28, 2024
b894a34
rm setworkspace approver command
rushatgabhane Feb 28, 2024
138edad
rm setworkspace approver command
rushatgabhane Feb 28, 2024
af43199
rm setworkspace approver command
rushatgabhane Feb 28, 2024
324c529
use set policy approver mode
rushatgabhane Feb 28, 2024
c0e4981
use set policy approver mode
rushatgabhane Feb 28, 2024
35e5d18
show policy approver
rushatgabhane Feb 28, 2024
a01f23c
show policy approver
rushatgabhane Feb 28, 2024
bd29662
show policy approver
rushatgabhane Feb 28, 2024
d619c70
default to policy owner
rushatgabhane Feb 28, 2024
eb09ea1
memoize policy members
rushatgabhane Feb 28, 2024
9ad56cc
memoize policy members
rushatgabhane Feb 28, 2024
e917162
add filter
rushatgabhane Feb 28, 2024
aca798a
add filter
rushatgabhane Feb 28, 2024
f2e6310
add filter
rushatgabhane Feb 28, 2024
a3cacc2
handle empty approver
rushatgabhane Feb 28, 2024
0a3c7f9
Merge branch 'main' of github.com:rushatgabhane/exfy into approval-page
rushatgabhane Feb 28, 2024
e8b63b3
fix lint
rushatgabhane Feb 28, 2024
722ae40
fix lint
rushatgabhane Feb 28, 2024
f69f94f
fix lint
rushatgabhane Feb 28, 2024
3e66027
fix lint
rushatgabhane Feb 28, 2024
34aa039
add not found page
rushatgabhane Feb 28, 2024
9fc8ee7
add not found page
rushatgabhane Feb 28, 2024
baf34f5
add not found page
rushatgabhane Feb 28, 2024
4cf6d18
add not found page
rushatgabhane Feb 28, 2024
b86d2f0
handle no results
rushatgabhane Feb 28, 2024
b935378
handle no results
rushatgabhane Feb 28, 2024
caec3f6
fix err msg
rushatgabhane Feb 28, 2024
b4728c9
fix err msg
rushatgabhane Feb 28, 2024
6dd7fee
fix lint
rushatgabhane Feb 28, 2024
5852f2e
fix lint
rushatgabhane Feb 28, 2024
538cacf
fix lint
rushatgabhane Feb 28, 2024
eceef70
fix lint
rushatgabhane Feb 28, 2024
c5daa84
fix lint
rushatgabhane Feb 28, 2024
461d38b
fix more lint
rushatgabhane Feb 28, 2024
b965a33
fix deps arr for memo
rushatgabhane Feb 28, 2024
4f02a5a
Merge branch 'Expensify:main' into approval-page
rushatgabhane Feb 29, 2024
3f0f86b
rename sections array
rushatgabhane Feb 29, 2024
784ef76
rename sections array
rushatgabhane Feb 29, 2024
91f5369
fix deps arr
rushatgabhane Feb 29, 2024
8582f29
rm unused
rushatgabhane Feb 29, 2024
75e1946
show approver display name
rushatgabhane Feb 29, 2024
e717fea
show approver display name
rushatgabhane Feb 29, 2024
2201a27
show approver display name
rushatgabhane Feb 29, 2024
da72467
show approver display name
rushatgabhane Feb 29, 2024
b00f2c7
show approver display name
rushatgabhane Feb 29, 2024
fd23672
show approver display name
rushatgabhane Feb 29, 2024
e08f217
fix func
rushatgabhane Feb 29, 2024
4d63fe5
fix merge
rushatgabhane Mar 1, 2024
01b12a5
fix center pane refresh bug
rushatgabhane Mar 1, 2024
675d514
fix center pane refresh bug
rushatgabhane Mar 1, 2024
98f1b1a
fix center pane refresh bug
rushatgabhane Mar 1, 2024
4b2ccaf
rm todo
rushatgabhane Mar 1, 2024
740c93f
cleanup type
rushatgabhane Mar 1, 2024
511a5ff
cleanup using optional chain
rushatgabhane Mar 1, 2024
86e3c77
cleanup
rushatgabhane Mar 1, 2024
73cb58c
fix lint
rushatgabhane Mar 1, 2024
07e69d1
rm unused
rushatgabhane Mar 1, 2024
66e81e6
dry parse phone
rushatgabhane Mar 1, 2024
449e7a6
dry parse phone
rushatgabhane Mar 1, 2024
74591dc
dry parse phone
rushatgabhane Mar 1, 2024
8c74efc
dry parse phone
rushatgabhane Mar 1, 2024
d4b0344
dry parse phone
rushatgabhane Mar 1, 2024
5c6423c
fix lint
rushatgabhane Mar 1, 2024
1c98660
fix deps cycle
rushatgabhane Mar 1, 2024
25a5b0f
memoize deletedpolicy member
rushatgabhane Mar 1, 2024
e2495bf
Merge branch 'main' of github.com:rushatgabhane/exfy into approval-page
rushatgabhane Mar 1, 2024
47738f6
fix lint
rushatgabhane Mar 1, 2024
e60a960
ignore deps rule
rushatgabhane Mar 1, 2024
8b0d417
ignore deps rule
rushatgabhane Mar 1, 2024
45585e8
ignore deps rule
rushatgabhane Mar 1, 2024
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: 4 additions & 0 deletions src/ROUTES.ts
Original file line number Diff line number Diff line change
Expand Up @@ -486,6 +486,10 @@ const ROUTES = {
route: 'workspace/:policyID/workflows',
getRoute: (policyID: string) => `workspace/${policyID}/workflows` as const,
},
WORKSPACE_WORKFLOWS_APPROVER: {
route: 'workspace/:policyID/settings/workflows/approver',
getRoute: (policyId: string) => `workspace/${policyId}/settings/workflows/approver` as const,
},
WORKSPACE_WORKFLOWS_AUTOREPORTING_FREQUENCY: {
route: 'workspace/:policyID/settings/workflows/auto-reporting-frequency',
getRoute: (policyID: string) => `workspace/${policyID}/settings/workflows/auto-reporting-frequency` as const,
Expand Down
1 change: 1 addition & 0 deletions src/SCREENS.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ const SCREENS = {
CATEGORIES: 'Workspace_Categories',
CURRENCY: 'Workspace_Profile_Currency',
WORKFLOWS: 'Workspace_Workflows',
WORKFLOWS_APPROVER: 'Workspace_Workflows_Approver',
WORKFLOWS_AUTO_REPORTING_FREQUENCY: 'Workspace_Workflows_Auto_Reporting_Frequency',
WORKFLOWS_AUTO_REPORTING_MONTHLY_OFFSET: 'Workspace_Workflows_Auto_Reporting_Monthly_Offset',
DESCRIPTION: 'Workspace_Profile_Description',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ const SettingsModalStackNavigator = createModalStackNavigator<SettingsNavigatorP
[SCREENS.WORKSPACE.RATE_AND_UNIT_RATE]: () => require('../../../pages/workspace/reimburse/WorkspaceRateAndUnitPage/RatePage').default as React.ComponentType,
[SCREENS.WORKSPACE.RATE_AND_UNIT_UNIT]: () => require('../../../pages/workspace/reimburse/WorkspaceRateAndUnitPage/UnitPage').default as React.ComponentType,
[SCREENS.WORKSPACE.INVITE]: () => require('../../../pages/workspace/WorkspaceInvitePage').default as React.ComponentType,
[SCREENS.WORKSPACE.WORKFLOWS_APPROVER]: () => require('../../../pages/workspace/workflows/WorkspaceWorkflowsApproverPage').default as React.ComponentType,
[SCREENS.WORKSPACE.INVITE_MESSAGE]: () => require('../../../pages/workspace/WorkspaceInviteMessagePage').default as React.ComponentType,
[SCREENS.WORKSPACE.NAME]: () => require('../../../pages/workspace/WorkspaceNamePage').default as React.ComponentType,
[SCREENS.WORKSPACE.DESCRIPTION]: () => require('../../../pages/workspace/WorkspaceProfileDescriptionPage').default as React.ComponentType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const CENTRAL_PANE_TO_RHP_MAPPING: Partial<Record<CentralPaneName, string[]>> =
[SCREENS.WORKSPACE.PROFILE]: [SCREENS.WORKSPACE.NAME, SCREENS.WORKSPACE.CURRENCY, SCREENS.WORKSPACE.DESCRIPTION, SCREENS.WORKSPACE.SHARE],
[SCREENS.WORKSPACE.REIMBURSE]: [SCREENS.WORKSPACE.RATE_AND_UNIT, SCREENS.WORKSPACE.RATE_AND_UNIT_RATE, SCREENS.WORKSPACE.RATE_AND_UNIT_UNIT],
[SCREENS.WORKSPACE.MEMBERS]: [SCREENS.WORKSPACE.INVITE, SCREENS.WORKSPACE.INVITE_MESSAGE],
[SCREENS.WORKSPACE.WORKFLOWS]: [SCREENS.WORKSPACE.WORKFLOWS_APPROVER],
};

export default CENTRAL_PANE_TO_RHP_MAPPING;
3 changes: 3 additions & 0 deletions src/libs/Navigation/linkingConfig/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,9 @@ const config: LinkingOptions<RootStackParamList>['config'] = {
[SCREENS.WORKSPACE.INVITE]: {
path: ROUTES.WORKSPACE_INVITE.route,
},
[SCREENS.WORKSPACE.WORKFLOWS_APPROVER]: {
path: ROUTES.WORKSPACE_WORKFLOWS_APPROVER.route,
},
[SCREENS.WORKSPACE.INVITE_MESSAGE]: {
path: ROUTES.WORKSPACE_INVITE_MESSAGE.route,
},
Expand Down
3 changes: 3 additions & 0 deletions src/libs/Navigation/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,9 @@ type CentralPaneNavigatorParamList = {
[SCREENS.WORKSPACE.WORKFLOWS]: {
policyID: string;
};
[SCREENS.WORKSPACE.WORKFLOWS_APPROVER]: {
policyID: string;
};
Comment on lines +66 to +68

This comment was marked as duplicate.

Copy link
Member Author

@rushatgabhane rushatgabhane Mar 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could you please link the TS check. i can't find failing check

Copy link
Contributor

@ishpaul777 ishpaul777 Mar 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry that was mistake 🙇‍♂️

[SCREENS.WORKSPACE.WORKFLOWS_AUTO_REPORTING_FREQUENCY]: {
policyID: string;
};
Expand Down
8 changes: 7 additions & 1 deletion src/libs/OptionsListUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -804,6 +804,11 @@ function getEnabledCategoriesCount(options: PolicyCategories): number {
return Object.values(options).filter((option) => option.enabled).length;
}

function getSearchValueForPhoneOrEmail(searchTerm: string) {
const parsedPhoneNumber = PhoneNumber.parsePhoneNumber(LoginUtils.appendCountryCode(Str.removeSMSDomain(searchTerm)));
return parsedPhoneNumber.possible ? parsedPhoneNumber.number?.e164 ?? '' : searchTerm.toLowerCase();
}

/**
* Verifies that there is at least one enabled option
*/
Expand Down Expand Up @@ -1882,7 +1887,7 @@ function formatMemberForList(member: ReportUtils.OptionData): MemberForList {
login: member.login ?? '',
icons: member.icons,
pendingAction: member.pendingAction,
reportID: member.reportID,
reportID: member.reportID ?? '',
};
}

Expand Down Expand Up @@ -2026,6 +2031,7 @@ export {
getMemberInviteOptions,
getHeaderMessage,
getHeaderMessageForNonUserList,
getSearchValueForPhoneOrEmail,
getPersonalDetailsForAccountIDs,
getIOUConfirmationOptionsFromPayeePersonalDetail,
getIOUConfirmationOptionsFromParticipants,
Expand Down
5 changes: 5 additions & 0 deletions src/libs/PersonalDetailsUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ function getPersonalDetailsByIDs(accountIDs: number[], currentUserAccountID: num
return result;
}

function getPersonalDetailByEmail(email: string): PersonalDetails | undefined {
return (Object.values(allPersonalDetails ?? {}) as PersonalDetails[]).find((detail) => detail?.login === email);
}

/**
* Given a list of logins, find the associated personal detail and return related accountIDs.
*
Expand Down Expand Up @@ -263,6 +267,7 @@ export {
isPersonalDetailsEmpty,
getDisplayNameOrDefault,
getPersonalDetailsByIDs,
getPersonalDetailByEmail,
getAccountIDsByLogins,
getLoginsByAccountIDs,
getNewPersonalDetailsOnyxData,
Expand Down
5 changes: 2 additions & 3 deletions src/pages/workspace/WorkspaceInvitePage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {useNavigation} from '@react-navigation/native';
import type {StackNavigationProp, StackScreenProps} from '@react-navigation/stack';
import Str from 'expensify-common/lib/str';
import React, {useEffect, useMemo, useState} from 'react';
import type {SectionListData} from 'react-native';
import {View} from 'react-native';
Expand Down Expand Up @@ -176,8 +175,8 @@ function WorkspaceInvitePage({
filterSelectedOptions = selectedOptions.filter((option) => {
const accountID = option.accountID;
const isOptionInPersonalDetails = Object.values(personalDetails).some((personalDetail) => personalDetail.accountID === accountID);
const parsedPhoneNumber = PhoneNumber.parsePhoneNumber(LoginUtils.appendCountryCode(Str.removeSMSDomain(searchTerm)));
const searchValue = parsedPhoneNumber.possible ? parsedPhoneNumber.number?.e164 ?? '' : searchTerm.toLowerCase();

const searchValue = OptionsListUtils.getSearchValueForPhoneOrEmail(searchTerm);

const isPartOfSearchTerm = !!option.text?.toLowerCase().includes(searchValue) || !!option.login?.toLowerCase().includes(searchValue);
return isPartOfSearchTerm || isOptionInPersonalDetails;
Expand Down
203 changes: 203 additions & 0 deletions src/pages/workspace/workflows/WorkspaceWorkflowsApproverPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
import React, {useCallback, useMemo, useState} from 'react';
import type {SectionListData} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import Badge from '@components/Badge';
import FullPageNotFoundView from '@components/BlockingViews/FullPageNotFoundView';
import HeaderWithBackButton from '@components/HeaderWithBackButton';
import ScreenWrapper from '@components/ScreenWrapper';
import SelectionList from '@components/SelectionList';
import type {ListItem, Section} from '@components/SelectionList/types';
import UserListItem from '@components/SelectionList/UserListItem';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import compose from '@libs/compose';
import {formatPhoneNumber} from '@libs/LocalePhoneNumber';
import Log from '@libs/Log';
import Navigation from '@libs/Navigation/Navigation';
import * as OptionsListUtils from '@libs/OptionsListUtils';
import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';
import * as PolicyUtils from '@libs/PolicyUtils';
import * as UserUtils from '@libs/UserUtils';
import withPolicyAndFullscreenLoading from '@pages/workspace/withPolicyAndFullscreenLoading';
import type {WithPolicyAndFullscreenLoadingProps} from '@pages/workspace/withPolicyAndFullscreenLoading';
import * as Policy from '@userActions/Policy';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import type {PersonalDetailsList, PolicyMember} from '@src/types/onyx';
import {isEmptyObject} from '@src/types/utils/EmptyObject';

type WorkspaceWorkflowsApproverPageOnyxProps = {
/** All of the personal details for everyone */
personalDetails: OnyxEntry<PersonalDetailsList>;
};

type WorkspaceWorkflowsApproverPageProps = WorkspaceWorkflowsApproverPageOnyxProps & WithPolicyAndFullscreenLoadingProps;
type MemberOption = Omit<ListItem, 'accountID'> & {accountID: number};
type MembersSection = SectionListData<MemberOption, Section<MemberOption>>;

function WorkspaceWorkflowsApproverPage({policy, policyMembers, personalDetails, isLoadingReportData = true}: WorkspaceWorkflowsApproverPageProps) {
const {translate} = useLocalize();
const policyName = policy?.name ?? '';
const [searchTerm, setSearchTerm] = useState('');
const {isOffline} = useNetwork();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();

const isDeletedPolicyMember = useCallback(
(policyMember: PolicyMember) => !isOffline && policyMember.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE && isEmptyObject(policyMember.errors),
[isOffline],
);

const [formattedPolicyMembers, formattedApprover] = useMemo(() => {
const policyMemberDetails: MemberOption[] = [];
const approverDetails: MemberOption[] = [];

Object.entries(policyMembers ?? {}).forEach(([accountIDKey, policyMember]) => {
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
const accountID = Number(accountIDKey);
if (isDeletedPolicyMember(policyMember)) {
return;
}

const details = personalDetails?.[accountID];
if (!details) {
Log.hmmm(`[WorkspaceMembersPage] no personal details found for policy member with accountID: ${accountID}`);
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
return;
}

const isOwner = policy?.owner === details.login;
const isAdmin = policyMember.role === CONST.POLICY.ROLE.ADMIN;

let roleBadge = null;
if (isOwner || isAdmin) {
roleBadge = (
<Badge
text={isOwner ? translate('common.owner') : translate('common.admin')}
textStyles={styles.textStrong}
badgeStyles={[styles.justifyContentCenter, StyleUtils.getMinimumWidth(60), styles.badgeBordered]}
/>
);
}

const formattedMember = {
keyForList: accountIDKey,
accountID,
isSelected: policy?.approver === details.login,
isDisabled: policyMember.pendingAction === CONST.RED_BRICK_ROAD_PENDING_ACTION.DELETE || !isEmptyObject(policyMember.errors),
text: formatPhoneNumber(PersonalDetailsUtils.getDisplayNameOrDefault(details)),
alternateText: formatPhoneNumber(details?.login ?? ''),
rightElement: roleBadge,
icons: [
{
source: UserUtils.getAvatar(details.avatar, accountID),
name: formatPhoneNumber(details?.login ?? ''),
type: CONST.ICON_TYPE_AVATAR,
id: accountID,
},
],
errors: policyMember.errors,
pendingAction: policyMember.pendingAction,
};

if (policy?.approver === details.login) {
approverDetails.push(formattedMember);
} else {
policyMemberDetails.push(formattedMember);
}
});
return [policyMemberDetails, approverDetails];
}, [personalDetails, policyMembers, translate, policy?.approver, StyleUtils, isDeletedPolicyMember, policy?.owner, styles]);

const sections: MembersSection[] = useMemo(() => {
const sectionsArray: MembersSection[] = [];

if (searchTerm !== '') {
const filteredOptions = [...formattedApprover, ...formattedPolicyMembers].filter((option) => {
const searchValue = OptionsListUtils.getSearchValueForPhoneOrEmail(searchTerm);
return !!option.text?.toLowerCase().includes(searchValue) || !!option.login?.toLowerCase().includes(searchValue);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

});
return [
{
title: undefined,
data: filteredOptions,
shouldShow: true,
},
];
}

sectionsArray.push({
title: undefined,
data: formattedApprover,
shouldShow: formattedApprover.length > 0,
indexOffset: 0,
});

sectionsArray.push({
title: translate('common.all'),
data: formattedPolicyMembers,
shouldShow: true,
indexOffset: formattedApprover.length,
});

return sectionsArray;
}, [formattedPolicyMembers, formattedApprover, searchTerm, translate]);

const headerMessage = useMemo(
() => (searchTerm && !sections[0].data.length ? translate('common.noResultsFound') : ''),

// eslint-disable-next-line react-hooks/exhaustive-deps
[translate, sections],
);

const setPolicyApprover = (member: MemberOption) => {
if (!policy?.approvalMode || !personalDetails?.[member.accountID]?.login) {
return;
}
const approver: string = personalDetails?.[member.accountID]?.login ?? policy.approver ?? policy.owner;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... Do we want this fallback? IMO, if personalDetails?.[member.accountID] is empty, we should just not let the user submit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On main, when approver toggle is enabled, policy owner is set as the default approver. So I don't think we should change that

Policy.setWorkspaceApprovalMode(policy.id, approver, policy.approvalMode);
Navigation.goBack();
};

return (
<ScreenWrapper
includeSafeAreaPaddingBottom={false}
testID={WorkspaceWorkflowsApproverPage.displayName}
>
<FullPageNotFoundView
shouldShow={(isEmptyObject(policy) && !isLoadingReportData) || !PolicyUtils.isPolicyAdmin(policy) || PolicyUtils.isPendingDeletePolicy(policy)}
subtitleKey={isEmptyObject(policy) ? undefined : 'workspace.common.notAuthorized'}
onBackButtonPress={PolicyUtils.goBackFromInvalidPolicy}
onLinkPress={PolicyUtils.goBackFromInvalidPolicy}
>
<HeaderWithBackButton
title={translate('workflowsPage.approver')}
subtitle={policyName}
onBackButtonPress={Navigation.goBack}
/>
<SelectionList
sections={sections}
textInputLabel={translate('optionsSelector.findMember')}
textInputValue={searchTerm}
onChangeText={setSearchTerm}
headerMessage={headerMessage}
ListItem={UserListItem}
onSelectRow={setPolicyApprover}
showScrollIndicator
/>
</FullPageNotFoundView>
</ScreenWrapper>
);
}

WorkspaceWorkflowsApproverPage.displayName = 'WorkspaceWorkflowsApproverPage';

export default compose(
withOnyx<WorkspaceWorkflowsApproverPageProps, WorkspaceWorkflowsApproverPageOnyxProps>({
personalDetails: {
key: ONYXKEYS.PERSONAL_DETAILS_LIST,
},
}),
withPolicyAndFullscreenLoading,
)(WorkspaceWorkflowsApproverPage);
14 changes: 6 additions & 8 deletions src/pages/workspace/workflows/WorkspaceWorkflowsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ import useStyleUtils from '@hooks/useStyleUtils';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
import Navigation from '@libs/Navigation/Navigation';
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
import * as OptionsListUtils from '@libs/OptionsListUtils';
import Permissions from '@libs/Permissions';
import * as PersonalDetailsUtils from '@libs/PersonalDetailsUtils';
import * as PolicyUtils from '@libs/PolicyUtils';
import * as ReportUtils from '@libs/ReportUtils';
import type {CentralPaneNavigatorParamList} from '@navigation/types';
import type {WithPolicyProps} from '@pages/workspace/withPolicy';
import withPolicy from '@pages/workspace/withPolicy';
Expand Down Expand Up @@ -45,8 +44,8 @@ function WorkspaceWorkflowsPage({policy, betas, route}: WorkspaceWorkflowsPagePr
const {isSmallScreenWidth} = useWindowDimensions();
const {isOffline} = useNetwork();

const ownerPersonalDetails = ReportUtils.getDisplayNamesWithTooltips(OptionsListUtils.getPersonalDetailsForAccountIDs([policy?.ownerAccountID ?? 0], CONST.EMPTY_OBJECT), false);
const policyOwnerDisplayName = ownerPersonalDetails[0]?.displayName;
const policyApproverEmail = policy?.approver;
const policyApproverName = useMemo(() => PersonalDetailsUtils.getPersonalDetailByEmail(policyApproverEmail ?? '')?.displayName ?? policyApproverEmail, [policyApproverEmail]);
const containerStyle = useMemo(() => [styles.ph8, styles.mhn8, styles.ml11, styles.pv3, styles.pr0, styles.pl4, styles.mr0, styles.widthAuto, styles.mt4], [styles]);
const canUseDelayedSubmission = Permissions.canUseWorkflowsDelayedSubmission(betas);

Expand Down Expand Up @@ -96,9 +95,8 @@ function WorkspaceWorkflowsPage({policy, betas, route}: WorkspaceWorkflowsPagePr
title={translate('workflowsPage.approver')}
titleStyle={styles.textLabelSupportingNormal}
descriptionTextStyle={styles.textNormalThemeText}
description={policyOwnerDisplayName ?? ''}
// onPress={() => Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVER.getRoute(route.params.policyID))}
// TODO will be done in https://github.com/Expensify/Expensify/issues/368334
description={policyApproverName ?? ''}
onPress={() => Navigation.navigate(ROUTES.WORKSPACE_WORKFLOWS_APPROVER.getRoute(route.params.policyID))}
shouldShowRightIcon
wrapperStyle={containerStyle}
hoverAndPressStyle={[styles.mr0, styles.br2]}
Expand Down Expand Up @@ -132,11 +130,11 @@ function WorkspaceWorkflowsPage({policy, betas, route}: WorkspaceWorkflowsPagePr
},
],
[
policyApproverName,
policy,
route.params.policyID,
styles,
translate,
policyOwnerDisplayName,
containerStyle,
isOffline,
StyleUtils,
Expand Down
Loading