Skip to content

Commit 80d4dab

Browse files
Add snackbar notices for page creation in Navigation block (#72627)
* Add snackbar notices for page creation in Navigation block * Apply suggestion from @scruffian * Apply suggestion from @scruffian * Apply suggestion from @scruffian * Apply suggestion from @scruffian * Apply suggestion from @scruffian --------- Co-authored-by: Ben Dwyer <ben@scruffian.com>
1 parent 6f1d4e2 commit 80d4dab

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

packages/block-library/src/navigation-link/link-ui/page-creator.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ import {
99
__experimentalVStack as VStack,
1010
__experimentalHStack as HStack,
1111
} from '@wordpress/components';
12-
import { __ } from '@wordpress/i18n';
12+
import { __, sprintf } from '@wordpress/i18n';
1313
import { useSelect, useDispatch } from '@wordpress/data';
1414
import { store as coreStore } from '@wordpress/core-data';
15+
import { store as noticesStore } from '@wordpress/notices';
1516
import { decodeEntities } from '@wordpress/html-entities';
1617
import { useState } from '@wordpress/element';
1718

@@ -57,6 +58,8 @@ export function LinkUIPageCreator( {
5758
);
5859

5960
const { saveEntityRecord } = useDispatch( coreStore );
61+
const { createSuccessNotice, createErrorNotice } =
62+
useDispatch( noticesStore );
6063

6164
async function createPage( event ) {
6265
event.preventDefault();
@@ -85,10 +88,30 @@ export function LinkUIPageCreator( {
8588
kind: 'post-type',
8689
};
8790

91+
// Show success notice
92+
createSuccessNotice(
93+
sprintf(
94+
// translators: %s: the name of the new page being created.
95+
__( '%s page created successfully.' ),
96+
decodeEntities( savedRecord.title.rendered )
97+
),
98+
{
99+
type: 'snackbar',
100+
id: 'page-created-success',
101+
}
102+
);
103+
88104
onPageCreated( pageLink );
89105
}
90106
} catch ( error ) {
91-
// Error handling is done via the data store selectors
107+
// Show error notice
108+
createErrorNotice(
109+
__( 'Failed to create page. Please try again.' ),
110+
{
111+
type: 'snackbar',
112+
id: 'page-created-error',
113+
}
114+
);
92115
}
93116
}
94117

0 commit comments

Comments
 (0)