Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
luacmartins committed Feb 28, 2024
1 parent 208efe2 commit cf27c93
Showing 1 changed file with 27 additions and 37 deletions.
64 changes: 27 additions & 37 deletions src/pages/workspace/categories/WorkspaceCategoriesPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,42 +112,6 @@ function WorkspaceCategoriesPage({policyCategories, route}: WorkspaceCategoriesP
</View>
);

const getComponentToRender = () => {
if (policyCategories === undefined) {
return (
<ActivityIndicator
size={CONST.ACTIVITY_INDICATOR_SIZE.LARGE}
style={[styles.flex1]}
color={theme.textSupporting}
/>
);
}

if (categoryList.length === 0) {
return (
<WorkspaceEmptyStateSection
title={translate('workspace.categories.emptyCategories.title')}
icon={Illustrations.EmptyStateExpenses}
subtitle={translate('workspace.categories.emptyCategories.subtitle')}
/>
);
}

return (
<SelectionList
canSelectMultiple
sections={[{data: categoryList, indexOffset: 0, isDisabled: false}]}
onCheckboxPress={toggleCategory}
onSelectRow={navigateToCategorySettings}
onSelectAll={toggleAllCategories}
showScrollIndicator
ListItem={TableListItem}
customListHeader={getCustomListHeader()}
listHeaderWrapperStyle={[styles.ph9, styles.pv3, styles.pb5]}
/>
);
};

return (
<AdminPolicyAccessOrNotFoundWrapper policyID={route.params.policyID}>
<PaidPolicyAccessOrNotFoundWrapper policyID={route.params.policyID}>
Expand All @@ -168,7 +132,33 @@ function WorkspaceCategoriesPage({policyCategories, route}: WorkspaceCategoriesP
<View style={[styles.ph5, styles.pb5]}>
<Text style={[styles.textNormal, styles.colorMuted]}>{translate('workspace.categories.subtitle')}</Text>
</View>
{getComponentToRender()}
{policyCategories === undefined && (
<ActivityIndicator
size={CONST.ACTIVITY_INDICATOR_SIZE.LARGE}
style={[styles.flex1]}
color={theme.textSupporting}
/>
)}
{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}]}
onCheckboxPress={toggleCategory}
onSelectRow={navigateToCategorySettings}
onSelectAll={toggleAllCategories}
showScrollIndicator
ListItem={TableListItem}
customListHeader={getCustomListHeader()}
listHeaderWrapperStyle={[styles.ph9, styles.pv3, styles.pb5]}
/>
)}
</ScreenWrapper>
</PaidPolicyAccessOrNotFoundWrapper>
</AdminPolicyAccessOrNotFoundWrapper>
Expand Down

0 comments on commit cf27c93

Please sign in to comment.