-
Notifications
You must be signed in to change notification settings - Fork 51
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Initial version of Disconnect button
- Loading branch information
1 parent
3c5c348
commit 91c8bda
Showing
3 changed files
with
94 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
...gs/resources/js/Components/Screens/Settings/Components/Settings/Parts/DisconnectButton.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
import { __ } from '@wordpress/i18n'; | ||
import { Button, Modal } from '@wordpress/components'; | ||
import { useCallback, useState } from '@wordpress/element'; | ||
|
||
import { CommonHooks } from '../../../../../../data'; | ||
import { HStack } from '../../../../../ReusableComponents/Stack'; | ||
|
||
const DisconnectButton = () => { | ||
const [ isOpen, setIsOpen ] = useState( false ); | ||
const { disconnectMerchant } = CommonHooks.useDisconnectMerchant(); | ||
|
||
const handleOpen = useCallback( () => { | ||
setIsOpen( true ); | ||
}, [] ); | ||
|
||
const handleCancel = useCallback( () => { | ||
setIsOpen( false ); | ||
}, [] ); | ||
|
||
const handleConfirm = useCallback( async () => { | ||
await disconnectMerchant(); | ||
window.location.reload(); | ||
}, [ disconnectMerchant ] ); | ||
|
||
const confirmationTitle = __( | ||
'Disconnect from PayPal?', | ||
'woocommerce-paypal-payments' | ||
); | ||
|
||
return ( | ||
<> | ||
<Button | ||
variant="tertiary" | ||
isDestructive={ true } | ||
onClick={ handleOpen } | ||
> | ||
{ __( 'Disconnect', 'woocommerce-paypal-payments' ) } | ||
</Button> | ||
|
||
{ isOpen && ( | ||
<Modal | ||
size="small" | ||
title={ confirmationTitle } | ||
onRequestClose={ handleCancel } | ||
> | ||
<p> | ||
{ __( | ||
'Disconnecting your account will restart the connection wizard. Are you sure you want to disconnect from your PayPal account?', | ||
'woocommerce-paypal-payments' | ||
) } | ||
</p> | ||
<HStack> | ||
<Button variant="tertiary" onClick={ handleCancel }> | ||
{ __( 'Cancel', 'woocommerce-paypal-payments' ) } | ||
</Button> | ||
<Button | ||
variant="primary" | ||
isDestructive={ true } | ||
onClick={ handleConfirm } | ||
> | ||
{ __( | ||
'Disconnect', | ||
'woocommerce-paypal-payments' | ||
) } | ||
</Button> | ||
</HStack> | ||
</Modal> | ||
) } | ||
</> | ||
); | ||
}; | ||
|
||
export default DisconnectButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters