3 * Copyright (C) 2009-2024 SonarSource SA
4 * mailto:info AT sonarsource DOT com
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.
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.
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.
29 } from 'design-system';
30 import React from 'react';
31 import { FormattedMessage } from 'react-intl';
32 import { translate } from '../../../../helpers/l10n';
33 import { AlmSettingsInstance } from '../../../../types/alm-settings';
34 import { usePersonalAccessToken } from '../usePersonalAccessToken';
37 almSetting: AlmSettingsInstance;
39 onPersonalAccessTokenCreated: () => void;
42 export default function BitbucketServerPersonalAccessTokenForm({
45 onPersonalAccessTokenCreated,
53 validationErrorMessage,
57 } = usePersonalAccessToken(almSetting, resetPat, onPersonalAccessTokenCreated);
60 return <Spinner className="sw-ml-2" loading />;
63 const { url } = almSetting;
64 const isInvalid = validationFailed && !touched;
65 const canSubmit = Boolean(password);
66 const submitButtonDiabled = isInvalid || submitting || !canSubmit;
69 validationErrorMessage ?? translate('onboarding.create_project.pat_incorrect.bitbucket');
72 <form className="sw-mt-3 sw-w-[50%]" onSubmit={handleSubmit}>
73 <LightPrimary as="h2" className="sw-heading-md">
74 {translate('onboarding.create_project.pat_form.title')}
76 <LightPrimary as="p" className="sw-mt-2 sw-mb-4 sw-body-sm">
77 {translate('onboarding.create_project.pat_form.help.bitbucket')}
82 <FlagMessage variant="error" className="sw-mb-4">
88 {!firstConnection && (
89 <FlagMessage variant="warning">
91 {translate('onboarding.create_project.pat.expired.info_message')}{' '}
92 {translate('onboarding.create_project.pat.expired.info_message_contact')}
98 htmlFor="personal_access_token_validation"
99 className="sw-mt-6 sw-mb-3"
100 label={translate('onboarding.create_project.enter_pat')}
107 id="personal_access_token_validation"
110 onChange={handlePasswordChange}
112 isInvalid={isInvalid}
114 {isInvalid && <FlagErrorIcon className="sw-ml-2" />}
118 <div className="sw-mb-6">
119 <FlagMessage variant="info">
122 id="onboarding.create_project.pat_help.instructions.bitbucket_server"
123 defaultMessage={translate(
124 'onboarding.create_project.pat_help.instructions.bitbucket_server',
128 <Link to={`${url.replace(/\/$/, '')}/account`}>
130 'onboarding.create_project.pat_help.instructions.bitbucket_server.link',
134 translate('onboarding.create_project.pat_help.instructions.bitbucket_server.link')
142 <ButtonPrimary type="submit" disabled={submitButtonDiabled} className="sw-mb-6">
145 <Spinner className="sw-ml-2" loading={submitting} />