Skip to content
Merged
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
27 changes: 21 additions & 6 deletions src/components/ReportActionItem/MoneyReportView.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import React, {useMemo} from 'react';
import type {StyleProp, TextStyle} from 'react-native';
import {View} from 'react-native';
import {withOnyx} from 'react-native-onyx';
import type {OnyxCollection} from 'react-native-onyx';
import Icon from '@components/Icon';
import * as Expensicons from '@components/Icon/Expensicons';
import MenuItemWithTopDescription from '@components/MenuItemWithTopDescription';
Expand All @@ -18,10 +20,11 @@ import Navigation from '@libs/Navigation/Navigation';
import * as ReportUtils from '@libs/ReportUtils';
import AnimatedEmptyStateBackground from '@pages/home/report/AnimatedEmptyStateBackground';
import variables from '@styles/variables';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {PolicyReportField, Report} from '@src/types/onyx';
import type {Policy, PolicyReportField, Report} from '@src/types/onyx';

type MoneyReportViewProps = {
type MoneyReportViewComponentProps = {
/** The report currently being looked at */
report: Report;

Expand All @@ -32,7 +35,14 @@ type MoneyReportViewProps = {
shouldShowHorizontalRule: boolean;
};

function MoneyReportView({report, policyReportFields, shouldShowHorizontalRule}: MoneyReportViewProps) {
type MoneyReportViewOnyxProps = {
/** Policies that the user is part of */
policies: OnyxCollection<Policy>;
};

type MoneyReportViewProps = MoneyReportViewComponentProps & MoneyReportViewOnyxProps;

function MoneyReportView({report, policyReportFields, shouldShowHorizontalRule, policies}: MoneyReportViewProps) {
const theme = useTheme();
const styles = useThemeStyles();
const StyleUtils = useStyleUtils();
Expand All @@ -59,14 +69,15 @@ function MoneyReportView({report, policyReportFields, shouldShowHorizontalRule}:
() => policyReportFields.sort(({orderWeight: firstOrderWeight}, {orderWeight: secondOrderWeight}) => firstOrderWeight - secondOrderWeight),
[policyReportFields],
);

const isAdmin = ReportUtils.isPolicyAdmin(report.policyID ?? '', policies);
return (
<View style={[StyleUtils.getReportWelcomeContainerStyle(isSmallScreenWidth, true)]}>
<AnimatedEmptyStateBackground />
<View style={[StyleUtils.getReportWelcomeTopMarginStyle(isSmallScreenWidth, true)]}>
{canUseReportFields &&
sortedPolicyReportFields.map((reportField) => {
const title = ReportUtils.getReportFieldTitle(report, reportField);
const isDisabled = !isAdmin || isSettled || ReportUtils.isReportFieldOfTypeTitle(reportField);
return (
<OfflineWithFeedback
pendingAction={report.pendingFields?.[reportField.fieldID]}
Expand All @@ -77,7 +88,7 @@ function MoneyReportView({report, policyReportFields, shouldShowHorizontalRule}:
title={title}
onPress={() => Navigation.navigate(ROUTES.EDIT_REPORT_FIELD_REQUEST.getRoute(report.reportID, report.policyID ?? '', reportField.fieldID))}
shouldShowRightIcon
disabled={ReportUtils.isReportFieldOfTypeTitle(reportField)}
disabled={isDisabled}
wrapperStyle={[styles.pv2, styles.taskDescriptionMenuItem]}
shouldGreyOutWhenDisabled={false}
numberOfLinesTitle={0}
Expand Down Expand Up @@ -167,4 +178,8 @@ function MoneyReportView({report, policyReportFields, shouldShowHorizontalRule}:

MoneyReportView.displayName = 'MoneyReportView';

export default MoneyReportView;
export default withOnyx<MoneyReportViewProps, MoneyReportViewOnyxProps>({
policies: {
key: ONYXKEYS.COLLECTION.POLICY,
},
})(MoneyReportView);