-
Notifications
You must be signed in to change notification settings - Fork 21
/
attribute-mapping-delete-rule-modal.js
121 lines (112 loc) · 3.18 KB
/
attribute-mapping-delete-rule-modal.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
/**
* External dependencies
*/
import { __ } from '@wordpress/i18n';
import { noop } from 'lodash';
import { useState } from '@wordpress/element';
/**
* Internal dependencies
*/
import AppModal from '.~/components/app-modal';
import AppButton from '.~/components/app-button';
import { useAppDispatch } from '.~/data';
import { recordGlaEvent } from '.~/utils/tracks';
/**
* Deletes the rule successfully
*
* @event gla_attribute_mapping_delete_rule
* @property {string} context Indicates where this event happened
*/
/**
* Clicks on delete rule button
*
* @event gla_attribute_mapping_delete_rule_click
* @property {string} context Indicates where this event happened
*/
/**
* Renders a Modal to confirm Attribute Mapping Rule deletion
*
* @param {Object} props Component props
* @param {Function} props.onRequestClose Callback function when the modal is closed
* @param {Object} props.rule The rule to be deleted
* @fires gla_attribute_mapping_delete_rule When the rule is successfully deleted with `{ context: 'attribute-mapping-delete-rule-modal'}`
* @fires gla_attribute_mapping_delete_rule_click When user clicks on delete rule button with `{ context: 'attribute-mapping-delete-rule-modal' }`
*/
const AttributeMappingDeleteRuleModal = ( { onRequestClose = noop, rule } ) => {
const [ deleting, setDeleting ] = useState( false );
const { deleteMappingRule } = useAppDispatch();
const onDelete = async () => {
setDeleting( true );
try {
await deleteMappingRule( rule );
recordGlaEvent( 'gla_attribute_mapping_delete_rule', {
context: 'attribute-mapping-delete-rule-modal',
} );
onRequestClose( 'confirm' );
} catch ( error ) {
setDeleting( false );
}
};
const handleClose = () => {
if ( deleting ) {
return;
}
onRequestClose( 'dismiss' );
};
return (
<AppModal
onRequestClose={ handleClose }
title={ __( 'Delete attribute rule?', 'google-listings-and-ads' ) }
buttons={ [
<AppButton
disabled={ deleting }
key="cancel"
isLink
onClick={ handleClose }
>
{ __( 'Cancel', 'google-listings-and-ads' ) }
</AppButton>,
<AppButton
disabled={ deleting }
key="delete-rule"
isPrimary
text={
deleting
? __( 'Deleting…', 'google-listings-and-ads' )
: __(
'Delete attribute rule',
'google-listings-and-ads'
)
}
eventName="gla_attribute_mapping_delete_rule_click"
eventProps={ {
context: 'attribute-mapping-delete-rule-modal',
} }
onClick={ onDelete }
/>,
] }
>
<div>
<p>
{ __(
'Deleting a rule does’t affect any data that has already been submitted to Google.',
'google-listings-and-ads'
) }
</p>
<p>
{ __(
'Product data is re-submitted to Google every 30 days to ensure that the information in your product listings are up-to-date.',
'google-listings-and-ads'
) }
</p>
<p>
{ __(
'To ensure your products continue to be approved and promoted by Google, make sure that your product fields include all the required information.',
'google-listings-and-ads'
) }
</p>
</div>
</AppModal>
);
};
export default AttributeMappingDeleteRuleModal;