import * as classNames from 'classnames';
import { stringify } from 'querystring';
import { debounce } from 'lodash';
+import DeferredSpinner from '../../../components/common/DeferredSpinner';
import { omitNil } from '../../../helpers/request';
import { Edition, getFormData, getLicensePreview } from '../../../api/marketplace';
import { translate, translateWithParameters } from '../../../helpers/l10n';
interface State {
license: string;
licenseEdition?: Edition;
+ loading: boolean;
previewStatus?: string;
formData?: {
serverId?: string;
constructor(props: Props) {
super(props);
- this.state = { license: '' };
+ this.state = { license: '', loading: false };
this.fetchLicensePreview = debounce(this.fetchLicensePreview, 100);
}
this.mounted = false;
}
- fetchLicensePreview = (license: string) =>
+ fetchLicensePreview = (license: string) => {
+ this.setState({ loading: true });
getLicensePreview({ license }).then(
({ previewStatus, nextEditionKey }) => {
if (this.mounted) {
}
}
);
+ };
fetchFormData = () => {
getFormData().then(
this.setState({ formData });
}
},
- () => {}
+ () => { }
);
};
};
updateLicense = (license: string, licenseEdition?: Edition, previewStatus?: string) => {
- this.setState({ license, licenseEdition, previewStatus });
+ this.setState({ license, licenseEdition, loading: false, previewStatus });
this.props.updateLicense(license, previewStatus);
};
+ renderAlert() {
+ const { licenseEdition, previewStatus } = this.state;
+ if (!previewStatus) {
+ return undefined;
+ }
+ return (
+ <p
+ className={classNames('alert spacer-top', {
+ 'alert-warning': previewStatus === 'AUTOMATIC_INSTALL',
+ 'alert-success': previewStatus === 'NO_INSTALL',
+ 'alert-danger': previewStatus === 'MANUAL_INSTALL'
+ })}>
+ {translateWithParameters(
+ 'marketplace.license_preview_status.' + previewStatus,
+ licenseEdition ? licenseEdition.name : translate('marketplace.commercial_edition')
+ )}
+ </p>
+ );
+ }
+
render() {
const { className, edition } = this.props;
- const { license, licenseEdition, previewStatus } = this.state;
+ const { license, loading } = this.state;
return (
<div className={className}>
style={{ resize: 'none' }}
value={license}
/>
- {previewStatus && (
- <p
- className={classNames('alert spacer-top', {
- 'alert-warning': previewStatus === 'AUTOMATIC_INSTALL',
- 'alert-success': previewStatus === 'NO_INSTALL',
- 'alert-danger': previewStatus === 'MANUAL_INSTALL'
- })}>
- {translateWithParameters(
- 'marketplace.license_preview_status.' + previewStatus,
- licenseEdition ? licenseEdition.name : translate('marketplace.commercial_edition')
- )}
- </p>
- )}
+
+ <DeferredSpinner
+ className="spacer-top"
+ loading={loading}
+ customSpinner={
+ <p className="spacer-top">
+ <i className="spinner spacer-right text-bottom" />
+ {translate('marketplace.checking_license')}
+ </p>
+ }>
+ {this.renderAlert()}
+ </DeferredSpinner>
+
{edition && (
<a
className="display-inline-block spacer-top"