You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GenerateSecretKeyForm.tsx 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2018 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import * as React from 'react';
  21. import { FormattedMessage } from 'react-intl';
  22. import ClipboardButton from '../../../components/controls/ClipboardButton';
  23. import DeferredSpinner from '../../../components/common/DeferredSpinner';
  24. import { SubmitButton } from '../../../components/ui/buttons';
  25. import { translate } from '../../../helpers/l10n';
  26. interface Props {
  27. generateSecretKey: () => Promise<void>;
  28. secretKey?: string;
  29. }
  30. interface State {
  31. submitting: boolean;
  32. }
  33. export default class GenerateSecretKeyForm extends React.PureComponent<Props, State> {
  34. mounted = false;
  35. state: State = { submitting: false };
  36. componentDidMount() {
  37. this.mounted = true;
  38. }
  39. componentWillUnmount() {
  40. this.mounted = false;
  41. }
  42. handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
  43. event.preventDefault();
  44. this.setState({ submitting: true });
  45. this.props.generateSecretKey().then(this.stopSubmitting, this.stopSubmitting);
  46. };
  47. stopSubmitting = () => {
  48. if (this.mounted) {
  49. this.setState({ submitting: false });
  50. }
  51. };
  52. render() {
  53. const { secretKey } = this.props;
  54. const { submitting } = this.state;
  55. return (
  56. <div id="generate-secret-key-form-container">
  57. {secretKey ? (
  58. <>
  59. <div className="big-spacer-bottom">
  60. <h3 className="spacer-bottom">{translate('encryption.secret_key')}</h3>
  61. <input
  62. className="input-clear input-code input-large"
  63. id="secret-key"
  64. readOnly={true}
  65. type="text"
  66. value={secretKey}
  67. />
  68. <ClipboardButton className="little-spacer-left" copyValue={secretKey} />
  69. </div>
  70. <h3 className="spacer-bottom">{translate('encryption.how_to_use')}</h3>
  71. <div
  72. className="markdown"
  73. dangerouslySetInnerHTML={{ __html: translate('encryption.how_to_use.content') }}
  74. />
  75. </>
  76. ) : (
  77. <form id="generate-secret-key-form" onSubmit={this.handleSubmit}>
  78. <p className="spacer-bottom">
  79. <FormattedMessage
  80. defaultMessage={translate('encryption.secret_key_description')}
  81. id="encryption.secret_key_description"
  82. values={{
  83. moreInformationLink: (
  84. <a
  85. href="https://redirect.sonarsource.com/doc/settings-encryption.html"
  86. rel="noopener noreferrer"
  87. target="_blank">
  88. {translate('more_information')}
  89. </a>
  90. )
  91. }}
  92. />
  93. </p>
  94. <SubmitButton disabled={submitting}>
  95. {translate('encryption.generate_secret_key')}
  96. </SubmitButton>
  97. <DeferredSpinner className="spacer-left" loading={submitting} />
  98. </form>
  99. )}
  100. </div>
  101. );
  102. }
  103. }