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

Call OpenPolicyCategoriesPage #37457

Merged
merged 11 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 5 additions & 0 deletions src/libs/API/parameters/OpenPolicyCategoriesPageParams.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type OpenPolicyCategoriesPageParams = {
policyID: string;
};

export default OpenPolicyCategoriesPageParams;
1 change: 1 addition & 0 deletions src/libs/API/parameters/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ export type {default as OpenWorkspaceViewParams} from './OpenWorkspaceViewParams
export type {default as OpenWorkspaceReimburseViewParams} from './OpenWorkspaceReimburseViewParams';
export type {default as OpenWorkspaceInvitePageParams} from './OpenWorkspaceInvitePageParams';
export type {default as OpenWorkspaceMembersPageParams} from './OpenWorkspaceMembersPageParams';
export type {default as OpenPolicyCategoriesPageParams} from './OpenPolicyCategoriesPageParams';
export type {default as OpenDraftWorkspaceRequestParams} from './OpenDraftWorkspaceRequestParams';
export type {default as UpdateWorkspaceCustomUnitAndRateParams} from './UpdateWorkspaceCustomUnitAndRateParams';
export type {default as CreateWorkspaceFromIOUPaymentParams} from './CreateWorkspaceFromIOUPaymentParams';
Expand Down
2 changes: 2 additions & 0 deletions src/libs/API/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ const READ_COMMANDS = {
OPEN_WORKSPACE_REIMBURSE_VIEW: 'OpenWorkspaceReimburseView',
OPEN_WORKSPACE: 'OpenWorkspace',
OPEN_WORKSPACE_MEMBERS_PAGE: 'OpenWorkspaceMembersPage',
OPEN_POLICY_CATEGORIES_PAGE: 'OpenPolicyCategoriesPage',
OPEN_WORKSPACE_INVITE_PAGE: 'OpenWorkspaceInvitePage',
OPEN_DRAFT_WORKSPACE_REQUEST: 'OpenDraftWorkspaceRequest',
} as const;
Expand Down Expand Up @@ -364,6 +365,7 @@ type ReadCommandParameters = {
[READ_COMMANDS.OPEN_WORKSPACE_REIMBURSE_VIEW]: Parameters.OpenWorkspaceReimburseViewParams;
[READ_COMMANDS.OPEN_WORKSPACE]: Parameters.OpenWorkspaceParams;
[READ_COMMANDS.OPEN_WORKSPACE_MEMBERS_PAGE]: Parameters.OpenWorkspaceMembersPageParams;
[READ_COMMANDS.OPEN_POLICY_CATEGORIES_PAGE]: Parameters.OpenPolicyCategoriesPageParams;
[READ_COMMANDS.OPEN_WORKSPACE_INVITE_PAGE]: Parameters.OpenWorkspaceInvitePageParams;
[READ_COMMANDS.OPEN_DRAFT_WORKSPACE_REQUEST]: Parameters.OpenDraftWorkspaceRequestParams;
};
Expand Down
15 changes: 15 additions & 0 deletions src/libs/actions/Policy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
DeleteWorkspaceAvatarParams,
DeleteWorkspaceParams,
OpenDraftWorkspaceRequestParams,
OpenPolicyCategoriesPageParams,
OpenWorkspaceInvitePageParams,
OpenWorkspaceMembersPageParams,
OpenWorkspaceParams,
Expand Down Expand Up @@ -1673,6 +1674,19 @@ function openWorkspaceMembersPage(policyID: string, clientMemberEmails: string[]
API.read(READ_COMMANDS.OPEN_WORKSPACE_MEMBERS_PAGE, params);
}

function openPolicyCategoriesPage(policyID: string) {
if (!policyID) {
Log.warn('openPolicyCategoriesPage invalid params', {policyID});
return;
}

const params: OpenPolicyCategoriesPageParams = {
policyID,
};

API.read(READ_COMMANDS.OPEN_POLICY_CATEGORIES_PAGE, params);
}

function openWorkspaceInvitePage(policyID: string, clientMemberEmails: string[]) {
if (!policyID || !clientMemberEmails) {
Log.warn('openWorkspaceInvitePage invalid params', {policyID, clientMemberEmails});
Expand Down Expand Up @@ -2264,6 +2278,7 @@ export {
generatePolicyID,
createWorkspace,
openWorkspaceMembersPage,
openPolicyCategoriesPage,
openWorkspaceInvitePage,
openWorkspace,
removeWorkspace,
Expand Down
33 changes: 24 additions & 9 deletions src/pages/workspace/categories/WorkspaceCategoriesPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type {StackScreenProps} from '@react-navigation/stack';
import React, {useMemo, useState} from 'react';
import {View} from 'react-native';
import React, {useEffect, useMemo, useState} from 'react';
import {ActivityIndicator, View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import type {OnyxEntry} from 'react-native-onyx';
import Button from '@components/Button';
Expand All @@ -21,6 +21,8 @@ import Navigation from '@libs/Navigation/Navigation';
import type {CentralPaneNavigatorParamList} from '@navigation/types';
import AdminPolicyAccessOrNotFoundWrapper from '@pages/workspace/AdminPolicyAccessOrNotFoundWrapper';
import PaidPolicyAccessOrNotFoundWrapper from '@pages/workspace/PaidPolicyAccessOrNotFoundWrapper';
import * as Policy from '@userActions/Policy';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type SCREENS from '@src/SCREENS';
Expand Down Expand Up @@ -48,6 +50,11 @@ function WorkspaceCategoriesPage({policyCategories, route}: WorkspaceCategoriesP
const {translate} = useLocalize();
const [selectedCategories, setSelectedCategories] = useState<Record<string, boolean>>({});

useEffect(() => {
Policy.openPolicyCategoriesPage(route.params.policyID);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

const categoryList = useMemo<PolicyForList[]>(
() =>
Object.values(policyCategories ?? {}).map((value) => ({
Expand Down Expand Up @@ -125,7 +132,21 @@ function WorkspaceCategoriesPage({policyCategories, route}: WorkspaceCategoriesP
<View style={[styles.ph5, styles.pb5]}>
<Text style={[styles.textNormal, styles.colorMuted]}>{translate('workspace.categories.subtitle')}</Text>
</View>
{categoryList.length ? (
{policyCategories === undefined && (
<ActivityIndicator
size={CONST.ACTIVITY_INDICATOR_SIZE.LARGE}
style={[styles.flex1]}
color={theme.textSupporting}
luacmartins marked this conversation as resolved.
Show resolved Hide resolved
/>
)}
{Boolean(policyCategories) && categoryList.length === 0 && (
<WorkspaceEmptyStateSection
title={translate('workspace.categories.emptyCategories.title')}
icon={Illustrations.EmptyStateExpenses}
subtitle={translate('workspace.categories.emptyCategories.subtitle')}
/>
)}
{Boolean(policyCategories) && Boolean(categoryList.length) && (
<SelectionList
canSelectMultiple
sections={[{data: categoryList, indexOffset: 0, isDisabled: false}]}
Expand All @@ -137,12 +158,6 @@ function WorkspaceCategoriesPage({policyCategories, route}: WorkspaceCategoriesP
customListHeader={getCustomListHeader()}
listHeaderWrapperStyle={[styles.ph9, styles.pv3, styles.pb5]}
/>
) : (
<WorkspaceEmptyStateSection
title={translate('workspace.categories.emptyCategories.title')}
icon={Illustrations.EmptyStateExpenses}
subtitle={translate('workspace.categories.emptyCategories.subtitle')}
/>
)}
</ScreenWrapper>
</PaidPolicyAccessOrNotFoundWrapper>
Expand Down
Loading