11// components/DeployItemModal.tsx
22import 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' ;
44import { messageInstance } from 'lowcoder-design/src/components/GlobalInstances' ;
55import { Environment } from '../types/environment.types' ;
66import { DeployableItemConfig } from '../types/deployable-item.types' ;
77import { useEnvironmentContext } from '../context/EnvironmentContext' ;
88import { getEnvironmentTagColor , formatEnvironmentType } from '../utils/environmentUtils' ;
9+ import { ExclamationCircleOutlined } from '@ant-design/icons' ;
910
1011interface DeployItemModalProps {
1112 visible : boolean ;
@@ -27,10 +28,12 @@ function DeployItemModal({
2728 const [ form ] = Form . useForm ( ) ;
2829 const { environments, isLoading } = useEnvironmentContext ( ) ;
2930 const [ deploying , setDeploying ] = useState ( false ) ;
31+ const [ credentialConfirmationStep , setCredentialConfirmationStep ] = useState ( 0 ) ; // 0: not started, 1: first confirmation, 2: confirmed
3032
3133 useEffect ( ( ) => {
3234 if ( visible ) {
3335 form . resetFields ( ) ;
36+ setCredentialConfirmationStep ( 0 ) ;
3437 }
3538 } , [ visible , form ] ) ;
3639
@@ -39,6 +42,76 @@ function DeployItemModal({
3942 ( env : Environment ) => env . environmentId !== sourceEnvironment . environmentId && env . isLicensed !== false
4043 ) ;
4144
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+
42115 const handleDeploy = async ( ) => {
43116 if ( ! config . deploy || ! item ) return ;
44117
@@ -50,6 +123,12 @@ function DeployItemModal({
50123 messageInstance . error ( 'Target environment not found' ) ;
51124 return ;
52125 }
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+ }
53132
54133 setDeploying ( true ) ;
55134
@@ -124,14 +203,32 @@ function DeployItemModal({
124203 { config . deploy ?. fields . map ( field => {
125204 switch ( field . type ) {
126205 case 'checkbox' :
206+ // Special handling for credential-related checkboxes
207+ const isCredentialField = field . name === 'deployCredential' ;
127208 return (
128209 < Form . Item
129210 key = { field . name }
130211 name = { field . name }
131212 valuePropName = "checked"
132213 initialValue = { field . defaultValue }
133214 >
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 >
135232 </ Form . Item >
136233 ) ;
137234 case 'select' :
0 commit comments