diff --git a/browser/ui/webui/brave_webui_source.cc b/browser/ui/webui/brave_webui_source.cc index de1d8e46f90c..a237b6d574c9 100644 --- a/browser/ui/webui/brave_webui_source.cc +++ b/browser/ui/webui/brave_webui_source.cc @@ -445,6 +445,7 @@ void CustomizeWebUIHTMLSource(const std::string &name, content::WebUIDataSource* { "wordCount", IDS_BRAVE_SYNC_SHARED_WORD_COUNT_TEXT }, { "ok", IDS_BRAVE_SYNC_SHARED_OK_BUTTON }, { "cancel", IDS_BRAVE_SYNC_SHARED_CANCEL_BUTTON }, + { "cancelDeviceSyncing", IDS_BRAVE_SYNC_SHARED_CANCEL_SYNCING }, { "thisSyncChain", IDS_BRAVE_SYNC_SHARED_FROM_THIS_CHAIN_PARTIAL }, { "lookingForDevice", IDS_BRAVE_SYNC_SCAN_CODE_LOOKING_FOR_DEVICE_BUTTON }, { "viewSyncCode", IDS_BRAVE_SYNC_ENABLED_VIEW_CODE_BUTTON }, diff --git a/components/brave_sync/ui/components/commonDialogs/cancelDeviceSyncing.tsx b/components/brave_sync/ui/components/commonDialogs/cancelDeviceSyncing.tsx new file mode 100644 index 000000000000..251478bc1a19 --- /dev/null +++ b/components/brave_sync/ui/components/commonDialogs/cancelDeviceSyncing.tsx @@ -0,0 +1,36 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this file, + * You can obtain one at http://mozilla.org/MPL/2.0/. */ + +import * as React from 'react' + +// Components +import { AlertBox } from 'brave-ui' + +// Feature-specific components +import { Title, Paragraph } from 'brave-ui/features/sync' + +// Utils +import { getLocale } from '../../../../common/locale' + +interface Props { + onClickOk: () => void + onClickCancel: () => void +} + +export default class AreYouSure extends React.PureComponent { + render () { + const { onClickOk, onClickCancel } = this.props + return ( + + {getLocale('areYouSure')} + {getLocale('cancelDeviceSyncing')} + + ) + } +} diff --git a/components/brave_sync/ui/components/modals/scanCode.tsx b/components/brave_sync/ui/components/modals/scanCode.tsx index a3e3c66c9bef..6ddc3de6392e 100644 --- a/components/brave_sync/ui/components/modals/scanCode.tsx +++ b/components/brave_sync/ui/components/modals/scanCode.tsx @@ -19,6 +19,9 @@ import { Link } from 'brave-ui/features/sync' +// Dialogs +import CancelDeviceSyncingDialog from '../commonDialogs/cancelDeviceSyncing' + // Utils import { getLocale } from '../../../../common/locale' @@ -30,7 +33,16 @@ interface Props { actions: any } -export default class ScanCodeModal extends React.PureComponent { +interface State { + willCancelScanCode: boolean +} + +export default class ScanCodeModal extends React.PureComponent { + constructor (props: Props) { + super(props) + this.state = { willCancelScanCode: false } + } + componentDidMount () { const { scanCode, deviceType } = this.props.syncData.modalsOpen if (scanCode) { @@ -46,6 +58,19 @@ export default class ScanCodeModal extends React.PureComponent { } onDismissModal = () => { + const { devices, isSyncConfigured } = this.props.syncData + // if user is still trying to build a sync chain, + // open the confirmation modal. otherwise close it + isSyncConfigured && devices.length < 2 + ? this.setState({ willCancelScanCode: true }) + : this.props.actions.maybeOpenSyncModal('scanCode', false) + } + + onDismissDialog = () => { + this.setState({ willCancelScanCode: false }) + } + + onConfirmDismissModal = () => { const { devices, isSyncConfigured } = this.props.syncData // sync is enabled when at least 2 devices are in the chain. // this modal works both with sync enabled and disabled states. @@ -54,14 +79,20 @@ export default class ScanCodeModal extends React.PureComponent { if (isSyncConfigured && devices.length < 2) { this.props.actions.onSyncReset() } + this.setState({ willCancelScanCode: false }) this.props.actions.maybeOpenSyncModal('scanCode', false) } render () { const { syncData } = this.props + const { willCancelScanCode } = this.state return ( + { + willCancelScanCode && + + }
{getLocale('scanThisCode')} diff --git a/components/brave_sync/ui/components/modals/viewSyncCode.tsx b/components/brave_sync/ui/components/modals/viewSyncCode.tsx index 5593a64d1dbe..5f2b1b85a504 100644 --- a/components/brave_sync/ui/components/modals/viewSyncCode.tsx +++ b/components/brave_sync/ui/components/modals/viewSyncCode.tsx @@ -18,6 +18,9 @@ import { Link } from 'brave-ui/features/sync' +// Dialogs +import CancelDeviceSyncingDialog from '../commonDialogs/cancelDeviceSyncing' + // Utils import { getLocale } from '../../../../common/locale' @@ -26,7 +29,16 @@ interface Props { actions: any } -export default class ViewSyncCodeModal extends React.PureComponent { +interface State { + willCancelViewCode: boolean +} + +export default class ViewSyncCodeModal extends React.PureComponent { + constructor (props: Props) { + super(props) + this.state = { willCancelViewCode: false } + } + componentDidMount () { const { scanCode, deviceType } = this.props.syncData.modalsOpen if (scanCode) { @@ -42,6 +54,19 @@ export default class ViewSyncCodeModal extends React.PureComponent { } onDismissModal = () => { + const { devices, isSyncConfigured } = this.props.syncData + // if user is still trying to build a sync chain, + // open the confirmation modal. otherwise close it + isSyncConfigured && devices.length < 2 + ? this.setState({ willCancelViewCode: true }) + : this.props.actions.maybeOpenSyncModal('viewSyncCode', false) + } + + onDismissDialog = () => { + this.setState({ willCancelViewCode: false }) + } + + onConfirmDismissModal = () => { const { devices, isSyncConfigured } = this.props.syncData // sync is enabled when at least 2 devices are in the chain. // this modal works both with sync enabled and disabled states. @@ -50,14 +75,20 @@ export default class ViewSyncCodeModal extends React.PureComponent { if (isSyncConfigured && devices.length < 2) { this.props.actions.onSyncReset() } + this.setState({ willCancelViewCode: false }) this.props.actions.maybeOpenSyncModal('viewSyncCode', false) } render () { const { syncData } = this.props + const { willCancelViewCode } = this.state return ( + { + willCancelViewCode && + + }
{getLocale('chainCode')} diff --git a/components/resources/brave_components_strings.grd b/components/resources/brave_components_strings.grd index c447e3257aca..5cc5dc80e35e 100644 --- a/components/resources/brave_components_strings.grd +++ b/components/resources/brave_components_strings.grd @@ -454,6 +454,7 @@ Word Count: Ok Cancel + Cancelling this modal will reset the current chain and the devices looking for this code would not be able to sync with this computer. from this sync chain View Code Words Looking for device