Skip to content

Commit

Permalink
Merge pull request Expensify#42981 from software-mansion-labs/@kosmyd…
Browse files Browse the repository at this point in the history
…el/settlement-button-loader

feat: add loading state to the SettlementButton
  • Loading branch information
Beamanator authored Jun 14, 2024
2 parents 43cd0f7 + 59a60f2 commit 2e85794
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/components/MoneyReportHeader.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {View} from 'react-native';
import type {OnyxEntry} from 'react-native-onyx';
import {useOnyx} from 'react-native-onyx';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
import useWindowDimensions from '@hooks/useWindowDimensions';
Expand Down Expand Up @@ -64,6 +65,7 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
const theme = useTheme();
const [isDeleteRequestModalVisible, setIsDeleteRequestModalVisible] = useState(false);
const {translate} = useLocalize();
const {isOffline} = useNetwork();
const {windowWidth} = useWindowDimensions();
const {reimbursableSpend} = ReportUtils.getMoneyRequestSpendBreakdown(moneyRequestReport);
const isSettled = ReportUtils.isSettled(moneyRequestReport.reportID);
Expand Down Expand Up @@ -234,7 +236,8 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
shouldDisableApproveButton={shouldDisableApproveButton}
style={[styles.pv2]}
formattedAmount={!ReportUtils.hasOnlyHeldExpenses(moneyRequestReport.reportID) ? displayedAmount : ''}
isDisabled={!canAllowSettlement}
isDisabled={isOffline && !canAllowSettlement}
isLoading={!isOffline && !canAllowSettlement}
/>
</View>
)}
Expand Down Expand Up @@ -305,7 +308,8 @@ function MoneyReportHeader({policy, report: moneyRequestReport, transactionThrea
shouldShowApproveButton={shouldShowApproveButton}
formattedAmount={!ReportUtils.hasOnlyHeldExpenses(moneyRequestReport.reportID) ? displayedAmount : ''}
shouldDisableApproveButton={shouldDisableApproveButton}
isDisabled={!canAllowSettlement}
isDisabled={isOffline && !canAllowSettlement}
isLoading={!isOffline && !canAllowSettlement}
/>
</View>
)}
Expand Down
5 changes: 4 additions & 1 deletion src/components/ReportActionItem/ReportPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import SettlementButton from '@components/SettlementButton';
import {showContextMenuForReport} from '@components/ShowContextMenuContext';
import Text from '@components/Text';
import useLocalize from '@hooks/useLocalize';
import useNetwork from '@hooks/useNetwork';
import usePermissions from '@hooks/usePermissions';
import useTheme from '@hooks/useTheme';
import useThemeStyles from '@hooks/useThemeStyles';
Expand Down Expand Up @@ -109,6 +110,7 @@ function ReportPreview({
const styles = useThemeStyles();
const {translate} = useLocalize();
const {canUseViolations} = usePermissions();
const {isOffline} = useNetwork();

const {hasMissingSmartscanFields, areAllRequestsBeingSmartScanned, hasOnlyTransactionsWithPendingRoutes, hasNonReimbursableTransactions} = useMemo(
() => ({
Expand Down Expand Up @@ -421,7 +423,8 @@ function ReportPreview({
horizontal: CONST.MODAL.ANCHOR_ORIGIN_HORIZONTAL.RIGHT,
vertical: CONST.MODAL.ANCHOR_ORIGIN_VERTICAL.BOTTOM,
}}
isDisabled={!canAllowSettlement}
isDisabled={isOffline && !canAllowSettlement}
isLoading={!isOffline && !canAllowSettlement}
/>
)}
{shouldShowSubmitButton && (
Expand Down
3 changes: 2 additions & 1 deletion src/libs/ReportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6519,8 +6519,9 @@ function hasUpdatedTotal(report: OnyxInputOrEntry<Report>, policy: OnyxInputOrEn
const hasPendingTransaction = transactions.some((transaction) => !!transaction.pendingAction);
const hasTransactionWithDifferentCurrency = transactions.some((transaction) => transaction.currency !== report.currency);
const hasDifferentWorkspaceCurrency = report.pendingFields?.createChat && isExpenseReport(report) && report.currency !== policy?.outputCurrency;
const hasOptimisticHeldExpense = hasHeldExpenses(report.reportID) && report?.unheldTotal === undefined;

return !(hasPendingTransaction && (hasTransactionWithDifferentCurrency || hasDifferentWorkspaceCurrency)) && !(hasHeldExpenses(report.reportID) && report?.unheldTotal === undefined);
return !(hasPendingTransaction && (hasTransactionWithDifferentCurrency || hasDifferentWorkspaceCurrency)) && !hasOptimisticHeldExpense;
}

/**
Expand Down

0 comments on commit 2e85794

Please sign in to comment.