-
Notifications
You must be signed in to change notification settings - Fork 407
[Website] Add error notices and delete confirmation modal to site management #3454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bgrgicak
wants to merge
10
commits into
trunk
Choose a base branch
from
update/sites-api-feedback
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d8530d4
Inline getActiveSiteOrThrow
bgrgicak 3fd14d9
Improve error messages to be context-neutral for both UI and MCP cons…
bgrgicak ad1937c
Add JSDoc comments to PlaygroundSitesAPI
bgrgicak 0b0a92a
Make persistTemporarySite throw on directory picker cancellation
bgrgicak f7c675e
Add rename error UI notice
bgrgicak a7a8cd6
Add delete site confirmation modal to replace window.confirm
bgrgicak e3ebe12
Add save error UI notice
bgrgicak 6dd8960
Use Notice component in save modal
bgrgicak 96fd729
Clean up modal state when delete site target is missing
bgrgicak a5e67b3
Exclude delete-site and rename-site modals from URL initialization
bgrgicak File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
83 changes: 83 additions & 0 deletions
83
packages/playground/website/src/components/delete-site-modal/index.tsx
This file contains hidden or 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,83 @@ | ||
| import { useState } from 'react'; | ||
| import { Notice, __experimentalText as Text } from '@wordpress/components'; | ||
| import { useAppDispatch, useAppSelector } from '../../lib/state/redux/store'; | ||
| import { | ||
| setActiveModal, | ||
| setSiteSlugToDelete, | ||
| } from '../../lib/state/redux/slice-ui'; | ||
| import { useSitesAPI } from '../../lib/state/redux/site-management-api-middleware'; | ||
| import { Modal } from '../modal'; | ||
| import ModalButtons from '../modal/modal-buttons'; | ||
| import css from '../modal/style.module.css'; | ||
|
|
||
| export function DeleteSiteModal() { | ||
| const dispatch = useAppDispatch(); | ||
| const sitesAPI = useSitesAPI(); | ||
| const siteSlugToDelete = useAppSelector( | ||
| (state) => state.ui.siteSlugToDelete | ||
| ); | ||
| const site = useAppSelector((state) => | ||
| siteSlugToDelete ? state.sites.entities[siteSlugToDelete] : undefined | ||
| ); | ||
|
|
||
| const [isSubmitting, setIsSubmitting] = useState(false); | ||
| const [error, setError] = useState<string | null>(null); | ||
|
|
||
| if (!site) { | ||
| return null; | ||
| } | ||
|
|
||
| const closeModal = () => { | ||
| dispatch(setActiveModal(null)); | ||
| dispatch(setSiteSlugToDelete(undefined)); | ||
| }; | ||
|
|
||
| const handleSubmit = async () => { | ||
| try { | ||
| setIsSubmitting(true); | ||
| setError(null); | ||
| await sitesAPI.delete(site.slug); | ||
| closeModal(); | ||
| } catch (e) { | ||
| setError( | ||
| e instanceof Error | ||
| ? e.message | ||
| : 'Deleting failed. Please try again.' | ||
| ); | ||
| } finally { | ||
| setIsSubmitting(false); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <Modal | ||
| title="Delete Playground" | ||
| contentLabel='This is a dialog window which overlays the main content of the page. The modal begins with a heading 2 called "Delete Playground". Pressing the Close button will close the modal and bring you back to where you were on the page.' | ||
| onRequestClose={closeModal} | ||
| small | ||
| > | ||
| <form | ||
| className={css.modalForm} | ||
| onSubmit={(e) => { | ||
| e.preventDefault(); | ||
| handleSubmit(); | ||
| }} | ||
| > | ||
| <Text> | ||
| Are you sure you want to delete the site “ | ||
| {site.metadata.name}”? This action cannot be undone. | ||
| </Text> | ||
| {error ? ( | ||
| <Notice status="error" isDismissible={false}> | ||
| {error} | ||
| </Notice> | ||
| ) : null} | ||
| <ModalButtons | ||
| submitText="Delete" | ||
| areBusy={isSubmitting} | ||
| onCancel={closeModal} | ||
| /> | ||
| </form> | ||
| </Modal> | ||
| ); | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.