Skip to content

Commit

Permalink
Merge pull request #34889 from allroundexperts/feat-34625
Browse files Browse the repository at this point in the history
feat: allow policy admins to edit the report fields of a non-settled report
  • Loading branch information
thienlnam authored Jan 25, 2024
2 parents c6463dc + da41efb commit 726c281
Showing 1 changed file with 21 additions and 6 deletions.
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);

0 comments on commit 726c281

Please sign in to comment.