Skip to content

Commit

Permalink
Check the if the button should be disabled with a state variable
Browse files Browse the repository at this point in the history
  • Loading branch information
WBerredo committed Jun 9, 2023
1 parent 4003926 commit d5079f5
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions client/my-sites/theme/main.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,12 @@ class ThemeSheet extends Component {
section: '',
};

/**
* Disabled button checks `isLoading` to determine if a the buttons should be disabled
* Its assigned to state to guarantee the initial state will be the same for SSR
*/
state = {
disabledButton: true,
showUnlockStyleUpgradeModal: false,
};

Expand All @@ -173,6 +178,11 @@ class ThemeSheet extends Component {
if ( this.props.themeId !== prevProps.themeId ) {
this.scrollToTop();
}

if ( this.state.disabledButton !== this.isLoading() ) {
// eslint-disable-next-line react/no-did-update-set-state
this.setState( { disabledButton: this.isLoading() } );
}
}

isLoaded = () => {
Expand Down Expand Up @@ -945,7 +955,7 @@ class ThemeSheet extends Component {
this.onButtonClick();
} }
primary
disabled={ this.isLoading() }
disabled={ this.state.disabledButton }
target={ isActive ? '_blank' : null }
>
{ this.isLoaded() ? label : placeholder }
Expand Down Expand Up @@ -1218,7 +1228,7 @@ class ThemeSheet extends Component {
}

const upsellNudgeClasses = classNames( 'theme__page-upsell-banner', {
'theme__page-upsell-disabled': this.isLoading(),
'theme__page-upsell-disabled': this.state.disabledButton,
} );

if ( hasWpComThemeUpsellBanner ) {
Expand Down

0 comments on commit d5079f5

Please sign in to comment.