11import React from 'react' ;
22
33import { CircleXmarkFill , TriangleExclamationFill } from '@gravity-ui/icons' ;
4- import { Dialog , Icon } from '@gravity-ui/uikit' ;
4+ import { Checkbox , Dialog , Icon } from '@gravity-ui/uikit' ;
55
66import type { IResponseError } from '../../types/api/error' ;
77import { cn } from '../../utils/cn' ;
@@ -29,6 +29,7 @@ interface CriticalActionDialogProps<T> {
2929 text ?: string ;
3030 withRetry ?: boolean ;
3131 retryButtonText ?: string ;
32+ withCheckBox ?: boolean ;
3233 onClose : VoidFunction ;
3334 onConfirm : ( isRetry ?: boolean ) => Promise < T > ;
3435 onConfirmActionSuccess : VoidFunction ;
@@ -41,13 +42,15 @@ export function CriticalActionDialog<T>({
4142 text,
4243 withRetry,
4344 retryButtonText,
45+ withCheckBox,
4446 onClose,
4547 onConfirm,
4648 onConfirmActionSuccess,
4749 onConfirmActionError,
4850} : CriticalActionDialogProps < T > ) {
4951 const [ isLoading , setIsLoading ] = React . useState ( false ) ;
5052 const [ error , setError ] = React . useState < IResponseError > ( ) ;
53+ const [ checkBoxChecked , setCheckBoxChecked ] = React . useState < boolean > ( false ) ;
5154
5255 const onApply = async ( isRetry ?: boolean ) => {
5356 setIsLoading ( true ) ;
@@ -68,6 +71,19 @@ export function CriticalActionDialog<T>({
6871
6972 const handleTransitionExited = ( ) => {
7073 setError ( undefined ) ;
74+ setCheckBoxChecked ( false ) ;
75+ } ;
76+
77+ const renderCheckBox = ( ) => {
78+ if ( withCheckBox ) {
79+ return (
80+ < Checkbox checked = { checkBoxChecked } onUpdate = { setCheckBoxChecked } >
81+ { criticalActionDialogKeyset ( 'checkbox-text' ) }
82+ </ Checkbox >
83+ ) ;
84+ }
85+
86+ return null ;
7187 } ;
7288
7389 const renderDialogContent = ( ) => {
@@ -111,14 +127,16 @@ export function CriticalActionDialog<T>({
111127 </ span >
112128 { text }
113129 </ div >
130+
131+ { renderCheckBox ( ) }
114132 </ Dialog . Body >
115133
116134 < Dialog . Footer
117135 loading = { isLoading }
118136 preset = "default"
119137 textButtonApply = { criticalActionDialogKeyset ( 'button-confirm' ) }
120138 textButtonCancel = { criticalActionDialogKeyset ( 'button-cancel' ) }
121- propsButtonApply = { { type : 'submit' } }
139+ propsButtonApply = { { type : 'submit' , disabled : withCheckBox && ! checkBoxChecked } }
122140 onClickButtonCancel = { onClose }
123141 onClickButtonApply = { ( ) => onApply ( ) }
124142 />
0 commit comments