File size: 7,906 Bytes
1e92f2d | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 | import { isFreePlanProduct } from '@automattic/calypso-products';
import page from '@automattic/calypso-router';
import { Button } from '@automattic/components';
import { localize, translate } from 'i18n-calypso';
import PropTypes from 'prop-types';
import { Component } from 'react';
import { connect } from 'react-redux';
import QuerySitePurchases from 'calypso/components/data/query-site-purchases';
import FormTextInput from 'calypso/components/forms/form-text-input';
import InlineSupportLink from 'calypso/components/inline-support-link';
import NavigationHeader from 'calypso/components/navigation-header';
import { Panel, PanelCard, PanelCardHeading } from 'calypso/components/panel';
import withP2HubP2Count from 'calypso/data/p2/with-p2-hub-p2-count';
import { recordTracksEvent } from 'calypso/lib/analytics/tracks';
import { resetBreadcrumbs, updateBreadcrumbs } from 'calypso/state/breadcrumb/actions';
import { hasLoadedSitePurchasesFromServer } from 'calypso/state/purchases/selectors';
import hasCancelableSitePurchases from 'calypso/state/selectors/has-cancelable-site-purchases';
import isSiteAutomatedTransfer from 'calypso/state/selectors/is-site-automated-transfer';
import { deleteSite } from 'calypso/state/sites/actions';
import { isTrialSite } from 'calypso/state/sites/plans/selectors';
import { getSite, getSiteDomain } from 'calypso/state/sites/selectors';
import { hasSitesAsLandingPage } from 'calypso/state/sites/selectors/has-sites-as-landing-page';
import { setSelectedSiteId } from 'calypso/state/ui/actions';
import { getSelectedSiteId, getSelectedSiteSlug } from 'calypso/state/ui/selectors';
import { FeatureBreadcrumb } from '../../../../hooks/breadcrumbs/use-set-feature-breadcrumb';
import ExportNotice from '../export-notice';
import DeleteSiteWarnings from './delete-site-warnings';
import './style.scss';
class DeleteSite extends Component {
static propTypes = {
deleteSite: PropTypes.func.isRequired,
hasLoadedSitePurchasesFromServer: PropTypes.bool,
siteDomain: PropTypes.string,
siteExists: PropTypes.bool,
siteId: PropTypes.number,
siteSlug: PropTypes.string,
translate: PropTypes.func.isRequired,
isTrialSite: PropTypes.bool,
};
state = {
confirmDomain: '',
isDeletingSite: false,
};
renderNotice() {
const { siteDomain, siteId } = this.props;
if ( ! siteDomain ) {
return null;
}
return (
<ExportNotice
siteSlug={ this.props.siteSlug }
siteId={ siteId }
warningText={ translate(
'Before deleting your site, consider exporting your content as a backup.'
) }
/>
);
}
renderDeleteSiteCTA() {
const { isAtomic, isFreePlan, siteDomain } = this.props;
const deleteDisabled =
typeof this.state.confirmDomain !== 'string' ||
this.state.confirmDomain.replace( /\s/g, '' ) !== siteDomain;
const isAtomicRemovalInProgress = isFreePlan && isAtomic;
return (
<>
<p>
{ translate(
'Type {{strong}}%(siteDomain)s{{/strong}} below to confirm you want to delete the site:',
{
components: {
strong: <strong />,
},
args: {
siteDomain: this.props.siteDomain,
},
}
) }
</p>
<>
<FormTextInput
autoCapitalize="off"
className="delete-site__confirm-input"
onChange={ this.onConfirmDomainChange }
value={ this.state.confirmDomain }
aria-required="true"
/>
<Button
primary
scary
busy={ this.state.isDeletingSite }
disabled={
deleteDisabled ||
! this.props.siteId ||
! this.props.hasLoadedSitePurchasesFromServer ||
isAtomicRemovalInProgress
}
onClick={ this.handleDeleteSiteClick }
>
{ translate( 'Delete site' ) }
</Button>
</>
</>
);
}
renderBody() {
return (
<>
<div>
<p>
{ translate(
'Deletion is {{strong}}irreversible and will permanently remove all site content{{/strong}} — posts, pages, media, users, authors, domains, purchased upgrades, and premium themes.',
{
components: {
strong: <strong />,
},
}
) }
</p>
<p>
{ translate(
'Once deleted, your domain {{strong}}%(siteDomain)s{{/strong}} will also become unavailable.',
{
components: {
strong: <strong />,
},
args: {
siteDomain: this.props.siteDomain,
},
}
) }
</p>
</div>
</>
);
}
handleDeleteSiteClick = async () => {
if ( ! this.props.hasLoadedSitePurchasesFromServer ) {
return;
}
recordTracksEvent( 'calypso_settings_delete_site_options', {
option: 'delete-site',
} );
try {
this.setState( { isDeletingSite: true } );
await this.props.deleteSite( this.props.siteId );
page.redirect( '/sites' );
} finally {
this.setState( { isDeletingSite: false } );
}
};
_goBack = () => {
const { siteSlug } = this.props;
page( `/sites/settings/site/${ siteSlug }` );
};
componentDidUpdate( prevProps ) {
const { siteId, siteExists, useSitesAsLandingPage } = this.props;
if ( siteId && prevProps.siteExists && ! siteExists ) {
this.props.setSelectedSiteId( null );
if ( useSitesAsLandingPage ) {
page.redirect( '/sites' );
} else {
page.redirect( '/' );
}
}
}
onConfirmDomainChange = ( event ) => {
this.setState( {
confirmDomain: event.target.value,
} );
};
render() {
const { isAtomic, isFreePlan, siteId, hasCancelablePurchases, p2HubP2Count } = this.props;
const isAtomicRemovalInProgress = isFreePlan && isAtomic;
const canDeleteSite =
! isAtomicRemovalInProgress && ! hasCancelablePurchases && p2HubP2Count === 0;
const strings = {
confirmDeleteSite: translate( 'Confirm delete site' ),
deleteSite: translate( 'Delete site' ),
exportContent: translate( 'Export content' ),
exportContentFirst: translate( 'Export content first' ),
};
return (
<Panel className="settings-administration__delete-site">
<FeatureBreadcrumb siteId={ siteId } title={ strings.deleteSite } />
<NavigationHeader
compactBreadcrumb={ false }
navigationItems={ [] }
mobileItem={ null }
title={ strings.deleteSite }
subtitle={ translate(
'Permanently delete your site and all of its content. {{learnMoreLink}}Learn more{{/learnMoreLink}}.',
{
components: {
learnMoreLink: (
<InlineSupportLink supportContext="delete_site" showIcon={ false } />
),
},
}
) }
></NavigationHeader>
{ siteId && <QuerySitePurchases siteId={ siteId } /> }
{ canDeleteSite ? (
<PanelCard>
<>
<PanelCardHeading>{ translate( 'Confirm site deletion' ) }</PanelCardHeading>
{ this.renderBody() }
{ this.renderNotice() }
</>
{ this.renderDeleteSiteCTA() }
</PanelCard>
) : (
<DeleteSiteWarnings
isAtomicRemovalInProgress={ isAtomicRemovalInProgress }
p2HubP2Count={ this.props.p2HubP2Count }
isTrialSite={ this.props.isTrialSite }
/>
) }
</Panel>
);
}
}
export default connect(
( state ) => {
const siteId = getSelectedSiteId( state );
const siteDomain = getSiteDomain( state, siteId );
const siteSlug = getSelectedSiteSlug( state );
const site = getSite( state, siteId );
return {
hasLoadedSitePurchasesFromServer: hasLoadedSitePurchasesFromServer( state ),
isAtomic: isSiteAutomatedTransfer( state, siteId ),
isFreePlan: isFreePlanProduct( site?.plan ),
siteDomain,
siteId,
siteSlug,
siteExists: !! getSite( state, siteId ),
hasCancelablePurchases: hasCancelableSitePurchases( state, siteId ),
useSitesAsLandingPage: hasSitesAsLandingPage( state ),
isTrialSite: isTrialSite( state, siteId ),
};
},
{
deleteSite,
setSelectedSiteId,
updateBreadcrumbs,
resetBreadcrumbs,
}
)( localize( withP2HubP2Count( DeleteSite ) ) );
|