Skip to content

Commit 0478a5c

Browse files
committed
refactor(units): handle item share with subject
see #250
1 parent 165846c commit 0478a5c

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

src/Units/index.js

+32-14
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,10 @@ const headerLayout = [
5555
/* messages */
5656
const MESSAGE_LIST_REFRESH_SUCCESS = 'Units were refreshed successfully';
5757
const MESSAGE_LIST_REFRESH_ERROR =
58-
'An Error occurred while refreshing Units, please try again!';
58+
'An Error occurred while refreshing Units, Please try again!';
59+
const MESSAGE_ITEM_ARCHIVE_SUCCESS = 'Unit was archived successfully';
60+
const MESSAGE_ITEM_ARCHIVE_ERROR =
61+
'An error occurred while archiving Unit, Please try again!';
5962

6063
/**
6164
* @function UnitList
@@ -96,6 +99,7 @@ class UnitList extends Component {
9699
this.state = {
97100
isEditForm: false,
98101
showNotificationForm: false,
102+
notificationSubject: undefined,
99103
notificationBody: undefined,
100104
};
101105
}
@@ -202,19 +206,18 @@ class UnitList extends Component {
202206
*/
203207

204208
showArchiveConfirm = (item) => {
209+
const itemId = get(item, '_id');
210+
const itemName = get(item, 'strings.name.en', 'N/A');
205211
confirm({
206-
title: `Are you sure you want to archive ${item.strings.name.en} ?`,
212+
title: `Are you sure you want to archive ${itemName} ?`,
207213
okText: 'Yes',
208214
okType: 'danger',
209215
cancelText: 'No',
210216
onOk() {
211217
deleteUnit(
212-
item._id, // eslint-disable-line
213-
() => notifySuccess('Unit was archived successfully'),
214-
() =>
215-
notifyError(
216-
'An error occurred while archiving Unit, Please contact your system Administrator'
217-
)
218+
itemId,
219+
() => notifySuccess(MESSAGE_ITEM_ARCHIVE_SUCCESS),
220+
() => notifyError(MESSAGE_ITEM_ARCHIVE_ERROR)
218221
);
219222
},
220223
});
@@ -261,12 +264,18 @@ class UnitList extends Component {
261264
* @since 0.1.0
262265
*/
263266
handleItemShare = (item) => {
264-
const message = `Name: ${item.strings.name.en}\nDescription: ${
265-
// eslint-disable-line
266-
item.strings.description.en
267-
}\n`;
267+
const itemName = get(item, 'strings.name.en', 'N/A');
268+
const itemDescription = get(item, 'strings.description.en', 'N/A');
268269

269-
this.setState({ notificationBody: message, showNotificationForm: true });
270+
const notificationSubject = 'Unit Details';
271+
const notificationBody = `Name: ${itemName}\nDescription: ${itemDescription}\n`;
272+
const showNotificationForm = true;
273+
274+
this.setState({
275+
notificationSubject,
276+
notificationBody,
277+
showNotificationForm,
278+
});
270279
};
271280

272281
/**
@@ -291,6 +300,7 @@ class UnitList extends Component {
291300
* @since 0.1.0
292301
*/
293302
render() {
303+
// props
294304
const {
295305
units,
296306
loading,
@@ -301,7 +311,14 @@ class UnitList extends Component {
301311
searchQuery,
302312
total,
303313
} = this.props;
304-
const { isEditForm, showNotificationForm, notificationBody } = this.state;
314+
315+
// states
316+
const {
317+
isEditForm,
318+
showNotificationForm,
319+
notificationSubject,
320+
notificationBody,
321+
} = this.state;
305322

306323
return (
307324
<>
@@ -415,6 +432,7 @@ class UnitList extends Component {
415432
onSearchGroups={getPartyGroups}
416433
onSearchAgencies={getAgencies}
417434
onSearchRoles={getRoles}
435+
subject={notificationSubject}
418436
body={notificationBody}
419437
onCancel={this.handleNotificationFormClose}
420438
/>

0 commit comments

Comments
 (0)