Hook up “remind me later” button.
Update the admin note status and date_reminder fields.
This commit is contained in:
parent
738ce59e4d
commit
276a6e6744
|
@ -10,6 +10,7 @@ import interpolateComponents from 'interpolate-components';
|
|||
import { compose } from '@wordpress/compose';
|
||||
import { noop } from 'lodash';
|
||||
import { withDispatch } from '@wordpress/data';
|
||||
import moment from 'moment';
|
||||
|
||||
/**
|
||||
* WooCommerce dependencies
|
||||
|
@ -63,9 +64,10 @@ class StoreAlerts extends Component {
|
|||
}
|
||||
|
||||
renderActions( alert ) {
|
||||
const { updateNote } = this.props;
|
||||
const actions = alert.actions.map( action => {
|
||||
const markStatus = () => {
|
||||
this.props.updateNote( alert.id, { status: action.status } );
|
||||
updateNote( alert.id, { status: action.status } );
|
||||
};
|
||||
return (
|
||||
<Button
|
||||
|
@ -79,29 +81,50 @@ class StoreAlerts extends Component {
|
|||
);
|
||||
} );
|
||||
|
||||
// TODO: should "next X" be the start, or exactly 1X from the current date?
|
||||
const snoozeOptions = [
|
||||
{
|
||||
value: 0,
|
||||
newDate: moment()
|
||||
.add( 4, 'hours' )
|
||||
.unix(),
|
||||
label: __( 'Later Today', 'woocommerce-admin' ),
|
||||
},
|
||||
{
|
||||
value: 1,
|
||||
newDate: moment()
|
||||
.add( 1, 'day' )
|
||||
.hour( 9 )
|
||||
.minute( 0 )
|
||||
.second( 0 )
|
||||
.millisecond( 0 )
|
||||
.unix(),
|
||||
label: __( 'Tomorrow', 'woocommerce-admin' ),
|
||||
},
|
||||
{
|
||||
value: 2,
|
||||
newDate: moment()
|
||||
.add( 1, 'week' )
|
||||
.hour( 9 )
|
||||
.minute( 0 )
|
||||
.second( 0 )
|
||||
.millisecond( 0 )
|
||||
.unix(),
|
||||
label: __( 'Next Week', 'woocommerce-admin' ),
|
||||
},
|
||||
{
|
||||
value: 3,
|
||||
newDate: moment()
|
||||
.add( 1, 'month' )
|
||||
.hour( 9 )
|
||||
.minute( 0 )
|
||||
.second( 0 )
|
||||
.millisecond( 0 )
|
||||
.unix(),
|
||||
label: __( 'Next Month', 'woocommerce-admin' ),
|
||||
},
|
||||
];
|
||||
|
||||
const onNavigate = ( key, onClose ) => {
|
||||
const setReminderDate = ( newDate, onClose ) => {
|
||||
return () => {
|
||||
onClose();
|
||||
console.log( 'onNavigate', snoozeOptions[ key ] );
|
||||
updateNote( alert.id, { status: 'snoozed', date_reminder: newDate } );
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -122,7 +145,7 @@ class StoreAlerts extends Component {
|
|||
<Button
|
||||
className="components-dropdown-menu__menu-item"
|
||||
key={ idx }
|
||||
onClick={ onNavigate( idx, onClose ) }
|
||||
onClick={ setReminderDate( option.newDate, onClose ) }
|
||||
>
|
||||
{ option.label }
|
||||
</Button>
|
||||
|
|
|
@ -202,6 +202,11 @@ class WC_Admin_REST_Admin_Notes_Controller extends WC_REST_CRUD_Controller {
|
|||
$note_changed = true;
|
||||
}
|
||||
|
||||
if ( ! is_null( $request->get_param( 'date_reminder' ) ) ) {
|
||||
$note->set_date_reminder( $request->get_param( 'date_reminder' ) );
|
||||
$note_changed = true;
|
||||
}
|
||||
|
||||
if ( $note_changed ) {
|
||||
$note->save();
|
||||
}
|
||||
|
|
|
@ -23,6 +23,7 @@ class WC_Admin_Note extends WC_Data {
|
|||
// Note status codes.
|
||||
const E_WC_ADMIN_NOTE_UNACTIONED = 'unactioned'; // the note has not yet been actioned by a user.
|
||||
const E_WC_ADMIN_NOTE_ACTIONED = 'actioned'; // the note has had its action completed by a user.
|
||||
const E_WC_ADMIN_NOTE_SNOOZED = 'snoozed'; // the note has been snoozed by a user.
|
||||
|
||||
/**
|
||||
* This is the name of this object type.
|
||||
|
@ -119,6 +120,7 @@ class WC_Admin_Note extends WC_Data {
|
|||
$allowed_statuses = array(
|
||||
self::E_WC_ADMIN_NOTE_ACTIONED,
|
||||
self::E_WC_ADMIN_NOTE_UNACTIONED,
|
||||
self::E_WC_ADMIN_NOTE_SNOOZED,
|
||||
);
|
||||
|
||||
return apply_filters( 'woocommerce_admin_note_statuses', $allowed_statuses );
|
||||
|
|
Loading…
Reference in New Issue