Skip to content

Commit

Permalink
[Site Editor]: Add success notice upon template creation (#43430)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntsekouras authored Aug 22, 2022
1 parent d4a8898 commit d8c3786
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions packages/edit-site/src/components/add-new-template/new-template.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import {
tag,
layout as customGenericTemplateIcon,
} from '@wordpress/icons';
import { __ } from '@wordpress/i18n';
import { __, sprintf } from '@wordpress/i18n';
import { store as noticesStore } from '@wordpress/notices';

/**
Expand Down Expand Up @@ -88,7 +88,8 @@ export default function NewTemplate( { postType } ) {

const history = useHistory();
const { saveEntityRecord } = useDispatch( coreStore );
const { createErrorNotice } = useDispatch( noticesStore );
const { createErrorNotice, createSuccessNotice } =
useDispatch( noticesStore );
const { setTemplate } = useDispatch( editSiteStore );

async function createTemplate( template, isWPSuggestion = true ) {
Expand Down Expand Up @@ -130,8 +131,16 @@ export default function NewTemplate( { postType } ) {
postId: newTemplate.id,
postType: newTemplate.type,
} );

// TODO: Add a success notice?
createSuccessNotice(
sprintf(
// translators: %s: Title of the created template e.g: "Category".
__( '"%s" successfully created.' ),
title
),
{
type: 'snackbar',
}
);
} catch ( error ) {
const errorMessage =
error.message && error.code !== 'unknown_error'
Expand Down

0 comments on commit d8c3786

Please sign in to comment.