Skip to content

Commit 3883b53

Browse files
authored
Merge branch 'trunk' into fix/content-distribution-editor-outgoing-post
2 parents a21e1e9 + f36bb28 commit 3883b53

File tree

1 file changed

+54
-34
lines changed
  • src/content-distribution/incoming-post

1 file changed

+54
-34
lines changed

src/content-distribution/incoming-post/index.js

Lines changed: 54 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import apiFetch from '@wordpress/api-fetch';
77
import { __, sprintf } from '@wordpress/i18n';
88
import { useEffect, useState } from '@wordpress/element';
99
import { useDispatch, useSelect } from '@wordpress/data';
10-
import { Button } from '@wordpress/components';
10+
import { Button, __experimentalConfirmDialog as ConfirmDialog } from '@wordpress/components';
1111
import { globe } from '@wordpress/icons';
1212
import { registerPlugin } from '@wordpress/plugins';
1313

@@ -28,6 +28,7 @@ function IncomingPost() {
2828
const [ isUnLinkedToggling, setIsUnLinkedToggling ] = useState( false );
2929
const [ isUnLinked, setIsUnLinked ] = useState( false );
3030
const [ hasInitializedSidebar, setHasInitializedSidebar ] = useState( false );
31+
const [ showConfirmDialog, setShowConfirmDialog ] = useState( false );
3132

3233
const { postId, areMetaBoxesInitialized } = useSelect( select => {
3334
const {
@@ -79,7 +80,7 @@ function IncomingPost() {
7980
}, [ isUnLinked ] );
8081

8182
const toggleUnlinkedState = async ( unlinked ) => {
82-
apiFetch( {
83+
return apiFetch( {
8384
path: `newspack-network/v1/content-distribution/unlink/${ postId }`,
8485
method: 'POST',
8586
data: {
@@ -103,6 +104,7 @@ function IncomingPost() {
103104
toggleUnlinkedState( unlinked )
104105
.then( () => {
105106
setIsUnLinkedToggling( false );
107+
setIsUnLinked( false );
106108
window.location.reload();
107109
} ); // Reload to get the origin post content.
108110
} );
@@ -121,38 +123,56 @@ function IncomingPost() {
121123
};
122124

123125
return (
124-
<ContentDistributionPanel
125-
header={
126-
isUnLinked ? __(
127-
'This post has been unlinked from the origin post. Edits to the origin post will not update this version.',
128-
'newspack-network'
129-
)
130-
: __(
131-
'This post is linked to the origin post. Edits to the origin post will update this version.',
132-
'newspack-network'
133-
)
134-
}
135-
buttons={
136-
<>
137-
<Button
138-
variant="secondary"
139-
target="_blank"
140-
href={ originalUrl }
141-
>
142-
{ __( 'View origin post', 'newspack-network' ) }
143-
</Button>
144-
<Button
145-
variant={ isUnLinked ? 'primary' : 'secondary' }
146-
isDestructive={ !isUnLinked }
147-
disabled={ isUnLinkedToggling }
148-
onClick={ () => {
149-
toggleUnlinkedClicked( !isUnLinked );
150-
} }
151-
>
152-
{ isUnLinkedToggling ? (isUnLinked ? __( 'Relinking...', 'newspack-network' ) : __( 'Unlinking...', 'newspack-network' )) : (!isUnLinked ? __( 'Unlink from origin post', 'newspack-network' ) : __( 'Relink to origin post', 'newspack-network' )) }
153-
</Button>
154-
</>
155-
}/>
126+
<>
127+
<ContentDistributionPanel
128+
header={
129+
isUnLinked ? __(
130+
'This post has been unlinked from its origin. Edits to the origin post will not update this version.',
131+
'newspack-network'
132+
)
133+
: __(
134+
'This post is linked to its origin. Edits to the origin post will update this version.',
135+
'newspack-network'
136+
)
137+
}
138+
buttons={
139+
<>
140+
<Button
141+
variant="secondary"
142+
target="_blank"
143+
href={ originalUrl }
144+
>
145+
{ __( 'View origin post', 'newspack-network' ) }
146+
</Button>
147+
<Button
148+
variant={ isUnLinked ? 'primary' : 'secondary' }
149+
isDestructive={ !isUnLinked }
150+
disabled={ isUnLinkedToggling }
151+
onClick={ () => {
152+
setShowConfirmDialog( true );
153+
} }
154+
>
155+
{ isUnLinkedToggling ? (isUnLinked ? __( 'Relinking...', 'newspack-network' ) : __( 'Unlinking...', 'newspack-network' )) : (!isUnLinked ? __( 'Unlink from origin post', 'newspack-network' ) : __( 'Relink to origin post', 'newspack-network' )) }
156+
</Button>
157+
</>
158+
}
159+
/>
160+
<ConfirmDialog
161+
isOpen={ showConfirmDialog }
162+
onConfirm={ () => {
163+
toggleUnlinkedClicked( !isUnLinked );
164+
setShowConfirmDialog( false );
165+
} }
166+
onCancel={ () => setShowConfirmDialog( false ) }
167+
confirmButtonText={ isUnLinked ? __( 'Relink', 'newspack-network' ) : __( 'Unlink', 'newspack-network' ) }
168+
size="small"
169+
>
170+
{ isUnLinked ?
171+
__( 'Are you sure you want to relink this post to its origin? Any changes you\'ve made will be lost.', 'newspack-network' ) :
172+
__( 'Are you sure you want to unlink this post from its origin?', 'newspack-network' )
173+
}
174+
</ConfirmDialog>
175+
</>
156176
);
157177
}
158178

0 commit comments

Comments
 (0)