@@ -11,7 +11,7 @@ import { store as noticesStore } from '@wordpress/notices';
1111import { useMemo , useState } from '@wordpress/element' ;
1212import { privateApis as patternsPrivateApis } from '@wordpress/patterns' ;
1313import { parse } from '@wordpress/blocks' ;
14-
14+ import { DataForm } from '@wordpress/dataviews' ;
1515import {
1616 Button ,
1717 TextControl ,
@@ -39,6 +39,21 @@ import { CreateTemplatePartModalContents } from '../create-template-part-modal';
3939const { PATTERN_TYPES , CreatePatternModalContents, useDuplicatePatternProps } =
4040 unlock ( patternsPrivateApis ) ;
4141
42+ // TODO: this should be shared with other components (page-pages).
43+ const fields = [
44+ {
45+ type : 'text' ,
46+ header : __ ( 'Title' ) ,
47+ id : 'title' ,
48+ placeholder : __ ( 'No title' ) ,
49+ getValue : ( { item } ) => item . title ,
50+ } ,
51+ ] ;
52+
53+ const form = {
54+ visibleFields : [ 'title' ] ,
55+ } ;
56+
4257/**
4358 * Check if a template is removable.
4459 *
@@ -649,16 +664,17 @@ const useDuplicatePostAction = ( postType ) => {
649664 return status !== 'trash' ;
650665 } ,
651666 RenderModal : ( { items, closeModal, onActionPerformed } ) => {
652- const [ item ] = items ;
667+ const [ item , setItem ] = useState ( {
668+ ...items [ 0 ] ,
669+ title : sprintf (
670+ /* translators: %s: Existing template title */
671+ __ ( '%s (Copy)' ) ,
672+ getItemTitle ( items [ 0 ] )
673+ ) ,
674+ } ) ;
675+
653676 const [ isCreatingPage , setIsCreatingPage ] =
654677 useState ( false ) ;
655- const [ title , setTitle ] = useState (
656- sprintf (
657- /* translators: %s: Existing item title */
658- __ ( '%s (Copy)' ) ,
659- getItemTitle ( item )
660- )
661- ) ;
662678
663679 const { saveEntityRecord } = useDispatch ( coreStore ) ;
664680 const { createSuccessNotice, createErrorNotice } =
@@ -673,8 +689,8 @@ const useDuplicatePostAction = ( postType ) => {
673689
674690 const newItemOject = {
675691 status : 'draft' ,
676- title,
677- slug : title || __ ( 'No title' ) ,
692+ title : item . title ,
693+ slug : item . title || __ ( 'No title' ) ,
678694 comment_status : item . comment_status ,
679695 content :
680696 typeof item . content === 'string'
@@ -725,7 +741,7 @@ const useDuplicatePostAction = ( postType ) => {
725741 // translators: %s: Title of the created template e.g: "Category".
726742 __ ( '"%s" successfully created.' ) ,
727743 decodeEntities (
728- newItem . title ?. rendered || title
744+ newItem . title ?. rendered || item . title
729745 )
730746 ) ,
731747 {
@@ -753,14 +769,15 @@ const useDuplicatePostAction = ( postType ) => {
753769 closeModal ( ) ;
754770 }
755771 }
772+
756773 return (
757774 < form onSubmit = { createPage } >
758775 < VStack spacing = { 3 } >
759- < TextControl
760- label = { __ ( 'Title' ) }
761- onChange = { setTitle }
762- placeholder = { __ ( 'No title' ) }
763- value = { title }
776+ < DataForm
777+ data = { item }
778+ fields = { fields }
779+ form = { form }
780+ onChange = { setItem }
764781 />
765782 < HStack spacing = { 2 } justify = "end" >
766783 < Button
0 commit comments