Skip to content

Commit 2f73358

Browse files
committed
chore: generate modal replaced with generic modal
1 parent 3ae3a6f commit 2f73358

File tree

4 files changed

+52
-49
lines changed

4 files changed

+52
-49
lines changed

src/Pages/GlobalConfigurations/Authorization/APITokens/CreateAPIToken.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,14 @@ const CreateAPIToken = ({
308308
buttonText="Generate token"
309309
disabled={isSaveDisabled}
310310
/>
311-
{showGenerateModal && (
312-
<GenerateModal
313-
close={handleGenerateTokenActionButton}
314-
token={tokenResponse.token}
315-
reload={reload}
316-
redirectToTokenList={redirectToTokenList}
317-
/>
318-
)}
311+
312+
<GenerateModal
313+
close={handleGenerateTokenActionButton}
314+
token={tokenResponse.token}
315+
reload={reload}
316+
redirectToTokenList={redirectToTokenList}
317+
open={showGenerateModal}
318+
/>
319319
</div>
320320
)
321321
}

src/Pages/GlobalConfigurations/Authorization/APITokens/GenerateModal.tsx

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,23 @@
1717
import { useState } from 'react'
1818

1919
import {
20-
Button,
21-
ButtonVariantType,
2220
ClipboardButton,
23-
ComponentSizeType,
2421
copyToClipboard,
25-
VisibleModal,
22+
GenericModal,
23+
InfoBlock,
24+
stopPropagation,
2625
} from '@devtron-labs/devtron-fe-common-lib'
2726

28-
import { ReactComponent as Close } from '../../../../assets/icons/ic-close.svg'
29-
import { ReactComponent as Key } from '../../../../assets/icons/ic-key-bulb.svg'
30-
import { ReactComponent as Success } from '../../../../assets/icons/ic-success-outline.svg'
3127
import { GenerateTokenModalType } from './apiToken.type'
3228

33-
const GenerateModal = ({ close, token, reload, redirectToTokenList, isRegenerationModal }: GenerateTokenModalType) => {
29+
const GenerateModal = ({
30+
close,
31+
token,
32+
reload,
33+
redirectToTokenList,
34+
isRegenerationModal,
35+
open,
36+
}: GenerateTokenModalType) => {
3437
const [copyToClipboardPromise, setCopyToClipboardPromise] = useState<ReturnType<typeof copyToClipboard>>(null)
3538
const modelType = isRegenerationModal ? 'regenerated' : 'generated'
3639
const handleCloseButton = () => {
@@ -40,45 +43,43 @@ const GenerateModal = ({ close, token, reload, redirectToTokenList, isRegenerati
4043
}
4144

4245
const handleCopyToClipboard = async (e?: React.MouseEvent) => {
43-
e?.stopPropagation()
44-
46+
stopPropagation(e)
4547
setCopyToClipboardPromise(copyToClipboard(token))
4648
}
4749

4850
return (
49-
<VisibleModal className="generate-token-modal">
50-
<div className="modal__body w-600 pl-20 pr-20 pt-20 pb-20 flex column dc__gap-16">
51-
<button
52-
type="button"
53-
data-testid={`${modelType}-token-modal-close`}
54-
className="w-100 flex right dc__transparent"
55-
onClick={handleCloseButton}
56-
aria-label="Close modal"
57-
>
58-
<Close className="icon-dim-24" />
59-
</button>
60-
<Success className="dc__vertical-align-middle" />
51+
<GenericModal
52+
name="create-ci-cd-pipeline-modal"
53+
open={open}
54+
width={600}
55+
onClose={handleCloseButton}
56+
onEscape={handleCloseButton}
57+
>
58+
<GenericModal.Header title={`API Token ${modelType}`} />
59+
<GenericModal.Body>
60+
<div className="flexbox-col dc__gap-20 p-20">
61+
<div>
62+
<h4 className="m-0">Copy and store this token safely, you won’t be able to view it again.</h4>
63+
<p className="cn-7 fs-12 lh-1-5 m-0">
64+
You can regenerate a token anytime. If you do, remember to update any scripts or
65+
applications using the old token.
66+
</p>
67+
</div>
6168

62-
<h2 className="modal__title fs-16">API token {modelType}</h2>
63-
<div
64-
className="flex top left bcg-1 br-4 eg-2 bw-1 pl-16 pr-16 pt-10 pb-10 dc__break-word"
65-
style={{ width: '560px' }}
66-
>
67-
<Key className="api-token-icon icon-dim-20 mr-10" />
68-
<span data-testid={`${modelType}-token`} className="api-token-text cn-9 fs-14">
69-
{token}
70-
</span>
69+
<InfoBlock description={token} variant="success" />
7170
</div>
72-
<Button
73-
dataTestId="copy-token"
74-
variant={ButtonVariantType.primary}
75-
size={ComponentSizeType.large}
76-
onClick={handleCopyToClipboard}
77-
startIcon={<ClipboardButton content={token} copyToClipboardPromise={copyToClipboardPromise} />}
78-
text="Copy token"
79-
/>
80-
</div>
81-
</VisibleModal>
71+
</GenericModal.Body>
72+
<GenericModal.Footer
73+
buttonConfig={{
74+
primaryButton: {
75+
dataTestId: 'copy-token',
76+
startIcon: <ClipboardButton content={token} copyToClipboardPromise={copyToClipboardPromise} />,
77+
text: 'Copy token',
78+
onClick: handleCopyToClipboard,
79+
},
80+
}}
81+
/>
82+
</GenericModal>
8283
)
8384
}
8485

src/Pages/GlobalConfigurations/Authorization/APITokens/RegenerateModal.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ const RegeneratedModal = ({
116116
reload={reload}
117117
redirectToTokenList={redirectToTokenList}
118118
isRegenerationModal
119+
open={showGenerateModal}
119120
/>
120121
) : (
121122
<VisibleModal className="regenerate-token-modal">

src/Pages/GlobalConfigurations/Authorization/APITokens/apiToken.type.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export interface GenerateTokenModalType {
7979
reload: () => void
8080
redirectToTokenList: () => void
8181
isRegenerationModal?: boolean
82+
open: boolean
8283
}
8384

8485
export interface APITokenListType {

0 commit comments

Comments
 (0)