import { useState } from 'react'; import { weSAccountPost, weSErrorMessage } from '../../data/ajax'; interface Args { toggle: Function; /** Every product active on this domain, from the connect hook */ products: string[]; /** Re-read connect/status once the cloud has been told */ onDisconnected: () => void; } /** How a list of product slugs reads in a sentence */ const PRODUCT_NAMES: { [ key: string ]: string } = { graph: 'Graph', sentry: 'Sentry', }; /** * The ACCOUNT-level disconnect. * * This is not "stop using Sentry" — that is what deactivating or uninstalling * the plugin does, automatically, through Captcha::deprovision(). This posts * the shared library's own `goodbye` route, which drops the site token every * Web-Engine product on this domain depends on, so where another product is * active the user is told before confirming. * * @param root0 * @param root0.toggle * @param root0.products * @param root0.onDisconnected */ export default function Disconnect( { toggle, products, onDisconnected, }: Args ) { const [ busy, setBusy ] = useState( false ); const [ error, setError ] = useState( '' ); const others = products .filter( ( product ) => product !== 'sentry' ) .map( ( product ) => PRODUCT_NAMES[ product ] || product ); const confirm = () => { setBusy( true ); setError( '' ); weSAccountPost< { success: boolean } >( 'goodbye' ).then( () => { // The server's own view is the answer, not this response — // connect/status decides what the UI shows next. onDisconnected(); toggle( false ); }, ( reason ) => { // The cloud did not hear (or could not be reached), and the // route now says so (Redmine #25049). The site's own token // has still been dropped, so the status is re-read as well: // if it has gone, the chrome moves on and this dialog with it. setBusy( false ); setError( weSErrorMessage( reason ) ); onDisconnected(); } ); }; return (
Are you sure?
This will disconnect this site from{ ' ' }
Web-Engine cloud{ ' ' }
entirely, and sign out everyone who signed in to the
cloud from this site.
Disconnecting will also disconnect{ ' ' } { others.join( ', ' ) }. If you only want to stop using Sentry, deactivate or uninstall this plugin from the Plugins page instead.
) } { error !== '' && ({ error }
) }