-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
A4A Dev Sites: Add Delete site action for agency dev sites (#94483)
* A4A Dev Sites: Add Delete site action for agency dev sites * Code clean up. * Add missing property to actionEventNames of jetpack-cloud
- Loading branch information
Showing
11 changed files
with
264 additions
and
36 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
28 changes: 19 additions & 9 deletions
28
client/a8c-for-agencies/components/a4a-confirmation-dialog/style.scss
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 |
---|---|---|
@@ -1,11 +1,21 @@ | ||
.a4a-confirmation-dialog__heading { | ||
padding-block-end: 16px; | ||
@include a4a-font-heading-lg; | ||
} | ||
|
||
.a4a-confirmation-dialog .dialog__action-buttons { | ||
display: flex; | ||
flex-direction: row; | ||
gap: 8px; | ||
justify-content: flex-end; | ||
.a4a-confirmation-dialog { | ||
&__heading { | ||
padding-bottom: 16px; | ||
@include a4a-font-heading-lg; | ||
} | ||
|
||
& .dialog__action-buttons { | ||
display: flex; | ||
flex-direction: row; | ||
gap: 8px; | ||
justify-content: flex-end; | ||
|
||
// Something is overriding the opacity of a disabled button, so we need to override it back here | ||
// Feel free to remove the .is-destructive class if you want to apply this to all buttons, | ||
// or to remove the styles entirely if the root issue was fixed | ||
button.components-button.is-destructive:disabled { | ||
opacity: 0.3; | ||
} | ||
} | ||
} |
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,40 @@ | ||
import { useMutation, UseMutationOptions } from '@tanstack/react-query'; | ||
import wpcom from 'calypso/lib/wp'; | ||
import { useSelector } from 'calypso/state'; | ||
import { getActiveAgencyId } from 'calypso/state/a8c-for-agencies/agency/selectors'; | ||
|
||
interface APIResponse { | ||
success: boolean; | ||
} | ||
|
||
interface APIRequestArgs { | ||
agencyId: number; | ||
siteId: number; | ||
} | ||
|
||
function mutationDeleteDevSite( { siteId, agencyId }: APIRequestArgs ): Promise< APIResponse > { | ||
if ( ! agencyId ) { | ||
throw new Error( 'Agency ID is required to assign a license' ); | ||
} | ||
|
||
return wpcom.req.post( { | ||
method: 'DELETE', | ||
apiNamespace: 'wpcom/v2', | ||
path: `/agency/${ agencyId }/sites/${ siteId }/delete-dev-site`, | ||
} ); | ||
} | ||
|
||
/** | ||
* Hook to remove a dev site from the agency dashboard, to revoke the dev license, and to delete the WPCOM site. | ||
*/ | ||
export default function useDeleteDevSiteMutation( siteId: number, options?: UseMutationOptions ) { | ||
const agencyId = useSelector( getActiveAgencyId ); | ||
if ( ! agencyId ) { | ||
throw new Error( 'Agency ID is required to delete a WPCOM dev site' ); | ||
} | ||
|
||
return useMutation( { | ||
...options, | ||
mutationFn: () => mutationDeleteDevSite( { agencyId, siteId } ), | ||
} ); | ||
} |
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
99 changes: 99 additions & 0 deletions
99
client/a8c-for-agencies/sections/sites/dev-site-delete-confirmation-dialog/index.tsx
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,99 @@ | ||
import { FormLabel } from '@automattic/components'; | ||
import { useTranslate } from 'i18n-calypso'; | ||
import { useState } from 'react'; | ||
import { A4AConfirmationDialog } from 'calypso/a8c-for-agencies/components/a4a-confirmation-dialog'; | ||
import useDeleteDevSiteMutation from 'calypso/a8c-for-agencies/data/sites/use-delete-dev-site'; | ||
import FormFieldset from 'calypso/components/forms/form-fieldset'; | ||
import FormTextInput from 'calypso/components/forms/form-text-input'; | ||
import { useDispatch } from 'calypso/state'; | ||
import { errorNotice } from 'calypso/state/notices/actions'; | ||
import './style.scss'; | ||
|
||
type Props = { | ||
siteId: number; | ||
siteDomain: string; | ||
onClose: () => void; | ||
onSiteDeleted?: () => void; | ||
busy?: boolean; | ||
}; | ||
|
||
export function DevSiteDeleteConfirmationDialog( { | ||
siteId, | ||
siteDomain, | ||
onSiteDeleted, | ||
onClose, | ||
busy, | ||
}: Props ) { | ||
const dispatch = useDispatch(); | ||
const translate = useTranslate(); | ||
const [ isDisabled, setIsDisabled ] = useState( true ); // Disabled by default - user needs to type the site name to enable the button | ||
const title = translate( 'Delete site' ); | ||
|
||
const { mutate: deleteDevSite, isPending: isDeleting } = useDeleteDevSiteMutation( siteId, { | ||
onSuccess: () => { | ||
onSiteDeleted?.(); | ||
}, | ||
onError: () => { | ||
dispatch( errorNotice( translate( 'An error occurred while deleting the site.' ) ) ); | ||
}, | ||
} ); | ||
|
||
const handleDeleteConfirmationInputChange = ( event: React.ChangeEvent< HTMLInputElement > ) => { | ||
const value = event.target.value; | ||
setIsDisabled( value !== siteDomain ); | ||
}; | ||
|
||
return ( | ||
<A4AConfirmationDialog | ||
className="dev-site-delete-confirmation-dialog" | ||
title={ title } | ||
onClose={ onClose } | ||
onConfirm={ deleteDevSite } | ||
ctaLabel={ translate( 'Delete site' ) } | ||
isLoading={ busy || isDeleting } | ||
isDisabled={ isDisabled } | ||
isDestructive | ||
> | ||
<p> | ||
{ translate( 'Are you sure you want to delete the site {{b}}%(siteDomain)s{{/b}}?', { | ||
args: { siteDomain }, | ||
components: { | ||
b: <b />, | ||
}, | ||
comment: '%(siteDomain)s is the site domain', | ||
} ) } | ||
</p> | ||
<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> | ||
|
||
<FormFieldset> | ||
<FormLabel htmlFor="site-delete-confirmation-input"> | ||
{ translate( | ||
'Type {{strong}}%(siteDomain)s{{/strong}} below to confirm you want to delete the site:', | ||
{ | ||
components: { | ||
strong: <strong />, | ||
}, | ||
args: { siteDomain }, | ||
comment: '%(siteDomain)s is the site domain', | ||
} | ||
) } | ||
</FormLabel> | ||
<FormTextInput | ||
name="site-delete-confirmation-input" | ||
autoCapitalize="off" | ||
aria-required="true" | ||
onChange={ handleDeleteConfirmationInputChange } | ||
/> | ||
</FormFieldset> | ||
</A4AConfirmationDialog> | ||
); | ||
} |
19 changes: 19 additions & 0 deletions
19
client/a8c-for-agencies/sections/sites/dev-site-delete-confirmation-dialog/style.scss
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,19 @@ | ||
.dev-site-delete-confirmation-dialog { | ||
&.dialog.card { | ||
max-width: 60%; | ||
} | ||
|
||
p { | ||
font-size: 1rem; | ||
margin-bottom: 1rem; | ||
} | ||
|
||
fieldset { | ||
margin-top: 2rem; | ||
|
||
label { | ||
font-size: 1rem; | ||
font-weight: 500; | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.