Cleanup SaveEmailButton to work only with email
[MAILPOET-6342]
This commit is contained in:
committed by
Jan Lysý
parent
2e52419ffd
commit
4b761ac74d
@ -1,11 +1,4 @@
|
|||||||
import { useRef } from '@wordpress/element';
|
import { Button } from '@wordpress/components';
|
||||||
import { Button, Dropdown } from '@wordpress/components';
|
|
||||||
import {
|
|
||||||
// @ts-expect-error No types available for useEntitiesSavedStatesIsDirty
|
|
||||||
useEntitiesSavedStatesIsDirty,
|
|
||||||
// @ts-expect-error Our current version of packages doesn't have EntitiesSavedStates export
|
|
||||||
EntitiesSavedStates,
|
|
||||||
} from '@wordpress/editor';
|
|
||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
import { useDispatch, useSelect } from '@wordpress/data';
|
import { useDispatch, useSelect } from '@wordpress/data';
|
||||||
import { check, cloud, Icon } from '@wordpress/icons';
|
import { check, cloud, Icon } from '@wordpress/icons';
|
||||||
@ -14,8 +7,6 @@ import { storeName } from '../../store';
|
|||||||
export function SaveEmailButton() {
|
export function SaveEmailButton() {
|
||||||
const { saveEditedEmail } = useDispatch( storeName );
|
const { saveEditedEmail } = useDispatch( storeName );
|
||||||
|
|
||||||
const { dirtyEntityRecords } = useEntitiesSavedStatesIsDirty();
|
|
||||||
|
|
||||||
const { hasEdits, isEmpty, isSaving } = useSelect(
|
const { hasEdits, isEmpty, isSaving } = useSelect(
|
||||||
( select ) => ( {
|
( select ) => ( {
|
||||||
hasEdits: select( storeName ).hasEdits(),
|
hasEdits: select( storeName ).hasEdits(),
|
||||||
@ -25,12 +16,6 @@ export function SaveEmailButton() {
|
|||||||
[]
|
[]
|
||||||
);
|
);
|
||||||
|
|
||||||
const buttonRef = useRef( null );
|
|
||||||
|
|
||||||
const hasNonEmailEdits = dirtyEntityRecords.some(
|
|
||||||
( entity ) => entity.name !== 'mailpoet_email'
|
|
||||||
);
|
|
||||||
|
|
||||||
const isSaved = ! isEmpty && ! isSaving && ! hasEdits;
|
const isSaved = ! isEmpty && ! isSaving && ! hasEdits;
|
||||||
const isDisabled = isEmpty || isSaving || isSaved;
|
const isDisabled = isEmpty || isSaving || isSaved;
|
||||||
|
|
||||||
@ -41,27 +26,7 @@ export function SaveEmailButton() {
|
|||||||
label = __( 'Saving', 'mailpoet' );
|
label = __( 'Saving', 'mailpoet' );
|
||||||
}
|
}
|
||||||
|
|
||||||
return hasNonEmailEdits ? (
|
return (
|
||||||
<div ref={ buttonRef }>
|
|
||||||
<Dropdown
|
|
||||||
popoverProps={ {
|
|
||||||
placement: 'bottom',
|
|
||||||
anchor: buttonRef.current,
|
|
||||||
} }
|
|
||||||
contentClassName="mailpoet-email-editor-save-button__dropdown"
|
|
||||||
renderToggle={ ( { onToggle } ) => (
|
|
||||||
<Button onClick={ onToggle } variant="tertiary">
|
|
||||||
{ hasEdits
|
|
||||||
? __( 'Save email & template', 'mailpoet' )
|
|
||||||
: __( 'Save template', 'mailpoet' ) }
|
|
||||||
</Button>
|
|
||||||
) }
|
|
||||||
renderContent={ ( { onToggle } ) => (
|
|
||||||
<EntitiesSavedStates close={ onToggle } />
|
|
||||||
) }
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
) : (
|
|
||||||
<Button
|
<Button
|
||||||
variant="tertiary"
|
variant="tertiary"
|
||||||
disabled={ isDisabled }
|
disabled={ isDisabled }
|
||||||
|
Reference in New Issue
Block a user