1
1
// components/DeployItemModal.tsx
2
2
import React , { useState , useEffect } from 'react' ;
3
- import { Modal , Form , Select , Checkbox , Button , Spin , Input , Tag , Space } from 'antd' ;
3
+ import { Modal , Form , Select , Checkbox , Button , Spin , Input , Tag , Space , Alert } from 'antd' ;
4
4
import { messageInstance } from 'lowcoder-design/src/components/GlobalInstances' ;
5
5
import { Environment } from '../types/environment.types' ;
6
6
import { DeployableItemConfig } from '../types/deployable-item.types' ;
7
7
import { useEnvironmentContext } from '../context/EnvironmentContext' ;
8
8
import { getEnvironmentTagColor , formatEnvironmentType } from '../utils/environmentUtils' ;
9
+ import { ExclamationCircleOutlined } from '@ant-design/icons' ;
9
10
10
11
interface DeployItemModalProps {
11
12
visible : boolean ;
@@ -27,10 +28,12 @@ function DeployItemModal({
27
28
const [ form ] = Form . useForm ( ) ;
28
29
const { environments, isLoading } = useEnvironmentContext ( ) ;
29
30
const [ deploying , setDeploying ] = useState ( false ) ;
31
+ const [ credentialConfirmationStep , setCredentialConfirmationStep ] = useState ( 0 ) ; // 0: not started, 1: first confirmation, 2: confirmed
30
32
31
33
useEffect ( ( ) => {
32
34
if ( visible ) {
33
35
form . resetFields ( ) ;
36
+ setCredentialConfirmationStep ( 0 ) ;
34
37
}
35
38
} , [ visible , form ] ) ;
36
39
@@ -39,6 +42,76 @@ function DeployItemModal({
39
42
( env : Environment ) => env . environmentId !== sourceEnvironment . environmentId && env . isLicensed !== false
40
43
) ;
41
44
45
+ // Handle credential checkbox change with double confirmation
46
+ const handleCredentialCheckboxChange = ( checked : boolean , fieldName : string ) => {
47
+ if ( ! checked ) {
48
+ // If unchecking, reset confirmation and update form
49
+ setCredentialConfirmationStep ( 0 ) ;
50
+ form . setFieldsValue ( { [ fieldName ] : false } ) ;
51
+ return ;
52
+ }
53
+
54
+ // First confirmation
55
+ if ( credentialConfirmationStep === 0 ) {
56
+ Modal . confirm ( {
57
+ title : 'Overwrite Credentials Warning' ,
58
+ icon : < ExclamationCircleOutlined /> ,
59
+ content : (
60
+ < div >
61
+ < Alert
62
+ message = "This action will overwrite existing credentials in the target environment."
63
+ description = "This is a serious operation that may affect other applications and users. Are you sure you want to proceed?"
64
+ type = "warning"
65
+ showIcon
66
+ style = { { marginBottom : 16 } }
67
+ />
68
+ </ div >
69
+ ) ,
70
+ okText : 'Continue' ,
71
+ cancelText : 'Cancel' ,
72
+ onOk : ( ) => {
73
+ setCredentialConfirmationStep ( 1 ) ;
74
+ // Show second confirmation immediately
75
+ showSecondConfirmation ( fieldName ) ;
76
+ } ,
77
+ onCancel : ( ) => {
78
+ setCredentialConfirmationStep ( 0 ) ;
79
+ form . setFieldsValue ( { [ fieldName ] : false } ) ;
80
+ }
81
+ } ) ;
82
+ }
83
+ } ;
84
+
85
+ const showSecondConfirmation = ( fieldName : string ) => {
86
+ Modal . confirm ( {
87
+ title : 'Final Confirmation Required' ,
88
+ icon : < ExclamationCircleOutlined /> ,
89
+ content : (
90
+ < div >
91
+ < Alert
92
+ message = "Final Warning: Credential Overwrite"
93
+ description = "You are about to overwrite credentials in the target environment. This action cannot be undone and may break existing integrations. Please confirm one more time."
94
+ type = "error"
95
+ showIcon
96
+ style = { { marginBottom : 16 } }
97
+ />
98
+ < p > < strong > Are you absolutely certain you want to overwrite the credentials?</ strong > </ p >
99
+ </ div >
100
+ ) ,
101
+ okText : 'Yes, Overwrite Credentials' ,
102
+ okType : 'danger' ,
103
+ cancelText : 'Cancel' ,
104
+ onOk : ( ) => {
105
+ setCredentialConfirmationStep ( 2 ) ;
106
+ form . setFieldsValue ( { [ fieldName ] : true } ) ;
107
+ } ,
108
+ onCancel : ( ) => {
109
+ setCredentialConfirmationStep ( 0 ) ;
110
+ form . setFieldsValue ( { [ fieldName ] : false } ) ;
111
+ }
112
+ } ) ;
113
+ } ;
114
+
42
115
const handleDeploy = async ( ) => {
43
116
if ( ! config . deploy || ! item ) return ;
44
117
@@ -50,6 +123,12 @@ function DeployItemModal({
50
123
messageInstance . error ( 'Target environment not found' ) ;
51
124
return ;
52
125
}
126
+
127
+ // Additional check for credential overwrite
128
+ if ( values . deployCredential && credentialConfirmationStep !== 2 ) {
129
+ messageInstance . error ( 'Please confirm credential overwrite before deploying' ) ;
130
+ return ;
131
+ }
53
132
54
133
setDeploying ( true ) ;
55
134
@@ -124,14 +203,32 @@ function DeployItemModal({
124
203
{ config . deploy ?. fields . map ( field => {
125
204
switch ( field . type ) {
126
205
case 'checkbox' :
206
+ // Special handling for credential-related checkboxes
207
+ const isCredentialField = field . name === 'deployCredential' ;
127
208
return (
128
209
< Form . Item
129
210
key = { field . name }
130
211
name = { field . name }
131
212
valuePropName = "checked"
132
213
initialValue = { field . defaultValue }
133
214
>
134
- < Checkbox > { field . label } </ Checkbox >
215
+ < Checkbox
216
+ onChange = { ( e ) => {
217
+ if ( isCredentialField ) {
218
+ handleCredentialCheckboxChange ( e . target . checked , field . name ) ;
219
+ } else {
220
+ // For non-credential checkboxes, handle normally
221
+ form . setFieldsValue ( { [ field . name ] : e . target . checked } ) ;
222
+ }
223
+ } }
224
+ >
225
+ { field . label }
226
+ { isCredentialField && credentialConfirmationStep === 2 && (
227
+ < Tag color = "orange" style = { { marginLeft : 8 } } >
228
+ Confirmed
229
+ </ Tag >
230
+ ) }
231
+ </ Checkbox >
135
232
</ Form . Item >
136
233
) ;
137
234
case 'select' :
0 commit comments