Studio: Add failed state when the preview site fails to update - #977
Conversation
sejas
left a comment
There was a problem hiding this comment.
The implementation works as expected, although it seems we have two states representing the same thing.
| } ); | ||
| return response; | ||
| } catch ( error ) { | ||
| setErrorSites( ( prev ) => new Set( prev ).add( snapshot.atomicSiteId ) ); |
There was a problem hiding this comment.
I believe we only add sites to errorSites and never remove them. Is that correct?
There was a problem hiding this comment.
I think the state should be cleared by itself when the component unmounts. And the UI should be reset after 1 minute timeout:
const timeoutId = setTimeout( () => {
setShowUpdatedMessage( false );
setShowFailedMessage( false );
}, UPDATED_MESSAGE_DURATION_MS );
In any case, I added some clean up when we attemp another update: https://github.com/Automattic/studio/pull/977/commits/69c4b08f0e6ecfc1bd493fdf35a377d288d91d76k
Let me know what you think.
| const hasError = hasDemoSiteError( snapshot.atomicSiteId ); | ||
| const { formatRelativeTime } = useFormatLocalizedTimestamps(); | ||
| const [ showUpdatedMessage, setShowUpdatedMessage ] = useState( false ); | ||
| const [ showFailedMessage, setShowFailedMessage ] = useState( false ); |
There was a problem hiding this comment.
Would be possible to use only one state to represent the error message? For example removing hasDemoSiteError and using just hasDemoSiteError ?
There was a problem hiding this comment.
I made some changes in 3f8cd26
Let me know what you think!
There was a problem hiding this comment.
@katinthehatsite , everything works as expected and I'm able to see the errors.
Thanks for removing the "duplicated" state and handling the errors just in one place.
I left a suggestion about when removing the errors.
Otherwise it works as expected and I confirm I see the alert and error message:

| setTimeout( () => { | ||
| setErrorSites( ( prev ) => { | ||
| const next = new Set( prev ); | ||
| next.delete( snapshot.atomicSiteId ); | ||
| return next; | ||
| } ); | ||
| }, UPDATED_MESSAGE_DURATION_MS ); |
There was a problem hiding this comment.
Let's avoid removing the error automatically and instead clear it when the user retries the udpate on line 37.
| setTimeout( () => { | |
| setErrorSites( ( prev ) => { | |
| const next = new Set( prev ); | |
| next.delete( snapshot.atomicSiteId ); | |
| return next; | |
| } ); | |
| }, UPDATED_MESSAGE_DURATION_MS ); |
…led-state-to-preview-update
Related issues
Closes https://github.com/Automattic/dotcom-forge/issues/10384
Proposed Changes
This PR adds a failed state for when an update to a preview site fails due to an error. Currently it displays the
Updatedstate / wording even when update fails due to an error:Testing Instructions
Updatebutton by a preview site in the preview actions menuPre-merge Checklist