diff --git a/src/pages/workspace/reimburse/WorkspaceReimburseSection.js b/src/pages/workspace/reimburse/WorkspaceReimburseSection.js
index a53cc01d51d2..eb8305f23140 100644
--- a/src/pages/workspace/reimburse/WorkspaceReimburseSection.js
+++ b/src/pages/workspace/reimburse/WorkspaceReimburseSection.js
@@ -1,4 +1,4 @@
-import React from 'react';
+import React, {useState, useEffect} from 'react';
import PropTypes from 'prop-types';
import {ActivityIndicator, View} from 'react-native';
import lodashGet from 'lodash/get';
@@ -32,102 +32,91 @@ const propTypes = {
translate: PropTypes.func.isRequired,
};
-class WorkspaceReimburseSection extends React.Component {
- constructor(props) {
- super(props);
- this.state = {
- shouldShowLoadingSpinner: false,
- };
+function WorkspaceReimburseSection(props) {
+ const [shouldShowLoadingSpinner, setShouldShowLoadingSpinner] = useState(false);
+ const achState = lodashGet(props.reimbursementAccount, 'achData.state', '');
+ const hasVBA = achState === BankAccount.STATE.OPEN;
+ const reimburseReceiptsUrl = `reports?policyID=${props.policy.id}&from=all&type=expense&showStates=Archived&isAdvancedFilterMode=true`;
+ const debounceSetShouldShowLoadingSpinner = _.debounce(() => {
+ const isLoading = props.reimbursementAccount.isLoading || false;
+ if (isLoading !== shouldShowLoadingSpinner) {
+ setShouldShowLoadingSpinner(isLoading);
+ }
+ }, CONST.TIMING.SHOW_LOADING_SPINNER_DEBOUNCE_TIME);
+ useEffect(() => {
+ debounceSetShouldShowLoadingSpinner();
+ }, [debounceSetShouldShowLoadingSpinner]);
- this.debounceSetShouldShowLoadingSpinner = _.debounce(this.setShouldShowLoadingSpinner.bind(this), CONST.TIMING.SHOW_LOADING_SPINNER_DEBOUNCE_TIME);
+ if (props.network.isOffline) {
+ return (
+
+
+ {`${props.translate('common.youAppearToBeOffline')} ${props.translate('common.thisFeatureRequiresInternet')}`}
+
+
+ );
}
- componentDidUpdate() {
- this.debounceSetShouldShowLoadingSpinner();
+ // If the reimbursementAccount is loading but not enough time has passed to show a spinner, then render nothing.
+ if (props.reimbursementAccount.isLoading && !shouldShowLoadingSpinner) {
+ return null;
}
- setShouldShowLoadingSpinner() {
- const shouldShowLoadingSpinner = this.props.reimbursementAccount.isLoading || false;
- if (shouldShowLoadingSpinner !== this.state.shouldShowLoadingSpinner) {
- this.setState({shouldShowLoadingSpinner});
- }
+ if (shouldShowLoadingSpinner) {
+ return (
+
+
+
+ );
}
- render() {
- const achState = lodashGet(this.props.reimbursementAccount, 'achData.state', '');
- const hasVBA = achState === BankAccount.STATE.OPEN;
- const reimburseReceiptsUrl = `reports?policyID=${this.props.policy.id}&from=all&type=expense&showStates=Archived&isAdvancedFilterMode=true`;
-
- if (this.props.network.isOffline) {
- return (
+ return (
+ <>
+ {hasVBA ? (
Link.openOldDotLink(reimburseReceiptsUrl),
+ icon: Expensicons.Bank,
+ shouldShowRightIcon: true,
+ iconRight: Expensicons.NewWindow,
+ wrapperStyle: [styles.cardMenuItem],
+ link: () => Link.buildOldDotURL(reimburseReceiptsUrl),
+ },
+ ]}
>
- {`${this.props.translate('common.youAppearToBeOffline')} ${this.props.translate('common.thisFeatureRequiresInternet')}`}
+ {props.translate('workspace.reimburse.fastReimbursementsVBACopy')}
- );
- }
-
- // If the reimbursementAccount is loading but not enough time has passed to show a spinner, then render nothing.
- if (this.props.reimbursementAccount.isLoading && !this.state.shouldShowLoadingSpinner) {
- return null;
- }
-
- if (this.state.shouldShowLoadingSpinner) {
- return (
-
-
+
+ {props.translate('workspace.reimburse.unlockNoVBACopy')}
+
+
-
- );
- }
-
- return (
- <>
- {hasVBA ? (
- Link.openOldDotLink(reimburseReceiptsUrl),
- icon: Expensicons.Bank,
- shouldShowRightIcon: true,
- iconRight: Expensicons.NewWindow,
- wrapperStyle: [styles.cardMenuItem],
- link: () => Link.buildOldDotURL(reimburseReceiptsUrl),
- },
- ]}
- >
-
- {this.props.translate('workspace.reimburse.fastReimbursementsVBACopy')}
-
-
- ) : (
-
-
- {this.props.translate('workspace.reimburse.unlockNoVBACopy')}
-
-
-
- )}
- >
- );
- }
+
+ )}
+ >
+ );
}
WorkspaceReimburseSection.propTypes = propTypes;
+WorkspaceReimburseSection.displayName = 'WorkspaceReimburseSection';
export default WorkspaceReimburseSection;