/
navigation-menu-publish-button.js
57 lines (54 loc) · 1.41 KB
/
navigation-menu-publish-button.js
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
/**
* WordPress dependencies
*/
import { ToolbarButton } from '@wordpress/components';
import {
useEntityId,
useEntityProp,
store as coreStore,
} from '@wordpress/core-data';
import { useDispatch } from '@wordpress/data';
import { useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
import NavigationMenuNameModal from './navigation-menu-name-modal';
export default function NavigationMenuPublishButton() {
const [ isNameModalVisible, setIsNameModalVisible ] = useState( false );
const id = useEntityId( 'postType', 'wp_navigation' );
const [ navigationMenuTitle ] = useEntityProp(
'postType',
'wp_navigation',
'title'
);
const { editEntityRecord, saveEditedEntityRecord } = useDispatch(
coreStore
);
return (
<>
<ToolbarButton onClick={ () => setIsNameModalVisible( true ) }>
{ __( 'Save as' ) }
</ToolbarButton>
{ isNameModalVisible && (
<NavigationMenuNameModal
title={ __( 'Save your new navigation menu' ) }
value={ navigationMenuTitle }
onRequestClose={ () => setIsNameModalVisible( false ) }
finishButtonText={ __( 'Save' ) }
onFinish={ ( updatedTitle ) => {
editEntityRecord( 'postType', 'wp_navigation', id, {
title: updatedTitle,
status: 'publish',
} );
saveEditedEntityRecord(
'postType',
'wp_navigation',
id
);
} }
/>
) }
</>
);
}