@@ -2,13 +2,15 @@ import React from "react"
22import Flex from "src/components/templates/flex"
33import { Button } from "src/components/button"
44import { Text } from "src/components/typography"
5+ import useToggle from "react-use/lib/useToggle"
56import { Actions , Body , CloseButton , Content , Dialog , Header , Title , TitleIcon } from "./styled"
67
78const BodyMessage = ( { children, ...rest } ) =>
89 typeof children === "object" ? children : < Text { ...rest } > { children } </ Text >
910
1011const ConfirmationDialog = ( {
1112 confirmLabel = "Yes, remove" ,
13+ confirmLoadingLabel = "Loading..." ,
1214 confirmWidth = "128px" ,
1315 "data-ga" : dataGA = "confirmation-dialog" ,
1416 "data-testid" : dataTestId = "confirmationDialog" ,
@@ -22,7 +24,16 @@ const ConfirmationDialog = ({
2224 isConfirmPositive,
2325 message,
2426 title,
27+ showConfirmLoading,
28+ disableConfirmOnLoading,
2529} ) => {
30+ const [ loading , toggleLoading ] = useToggle ( false )
31+
32+ const onConfirm = e => {
33+ if ( showConfirmLoading ) toggleLoading ( )
34+ handleConfirm ( e , toggleLoading )
35+ }
36+
2637 return (
2738 < Dialog onEsc = { handleDecline } >
2839 < Content data-testid = { dataTestId } >
@@ -53,10 +64,11 @@ const ConfirmationDialog = ({
5364 data-ga = { `${ dataGA } -::click-confirm::global-view` }
5465 data-testid = { `${ dataTestId } -confirmAction` }
5566 danger = { ! isConfirmPositive && true }
56- disabled = { isConfirmDisabled }
57- label = { confirmLabel }
58- onClick = { handleConfirm }
67+ disabled = { isConfirmDisabled || ( disableConfirmOnLoading && loading ) }
68+ label = { loading ? confirmLoadingLabel : confirmLabel }
69+ onClick = { onConfirm }
5970 width = { confirmWidth }
71+ isLoading = { loading }
6072 />
6173 </ Actions >
6274 </ Content >
0 commit comments