Skip to content

Commit fcaa59e

Browse files
committed
refactor(units): handle item list share
see #250
1 parent 0478a5c commit fcaa59e

File tree

1 file changed

+36
-36
lines changed

1 file changed

+36
-36
lines changed

src/Units/index.js

+36-36
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { Connect, reduxActions } from '@codetanzania/ewea-api-states';
55
import { Modal, Col } from 'antd';
66
import { PlusOutlined } from '@ant-design/icons';
77
import get from 'lodash/get';
8-
import isArray from 'lodash/isArray';
98
import Topbar from '../components/Topbar';
109
import UnitForm from './Form';
1110
import NotificationForm from '../components/NotificationForm';
@@ -181,6 +180,37 @@ class UnitList extends Component {
181180
);
182181
};
183182

183+
/**
184+
* @function handleListShare
185+
* @name handleListShare
186+
* @description Handle list sharing
187+
* @param {object[]} items List of items
188+
* @version 0.1.0
189+
* @since 0.1.0
190+
*/
191+
handleListShare = (items) => {
192+
const itemList = [].concat(items);
193+
194+
const notificationSubject = 'List of Units';
195+
const notificationBody = itemList
196+
.map((item) => {
197+
const itemName = get(item, 'strings.name.en', 'N/A');
198+
const itemAbbreviation = get(item, 'strings.abbreviation.en', 'N/A');
199+
const itemSymbol = get(item, 'strings.symbol', 'N/A');
200+
const itemDescription = get(item, 'strings.description.en', 'N/A');
201+
const body = `Name: ${itemName}\nAbbreviation: ${itemAbbreviation}\nSymbol: ${itemSymbol}\nDescription: ${itemDescription}\n`;
202+
return body;
203+
})
204+
.join('\n');
205+
const showNotificationForm = true;
206+
207+
this.setState({
208+
notificationSubject,
209+
notificationBody,
210+
showNotificationForm,
211+
});
212+
};
213+
184214
/**
185215
* @function handleItemEdit
186216
* @name handleItemEdit
@@ -223,52 +253,22 @@ class UnitList extends Component {
223253
});
224254
};
225255

226-
/**
227-
* @function
228-
* @name handleListShare
229-
* @description Handle share multiple event Indicators
230-
*
231-
* @param {object[]| object} units event Indicators list to be shared
232-
*
233-
* @version 0.1.0
234-
* @since 0.1.0
235-
*/
236-
handleListShare = (units) => {
237-
let message = '';
238-
if (isArray(units)) {
239-
const unitList = units.map(
240-
(unit) =>
241-
`Name: ${unit.strings.name.en}\nDescription: ${
242-
// eslint-disable-line
243-
unit.strings.description.en
244-
}\n`
245-
);
246-
247-
message = unitList.join('\n\n\n');
248-
} else {
249-
message = `Name: ${units.strings.name.en}\nDescription: ${
250-
// eslint-disable-line
251-
units.strings.description.en
252-
}\n`;
253-
}
254-
255-
this.setState({ notificationBody: message, showNotificationForm: true });
256-
};
257-
258256
/**
259257
* @function handleItemShare
260258
* @name handleItemShare
261-
* @description Handle list item edit
259+
* @description Handle list item sharing
262260
* @param {object} item List item
263261
* @version 0.1.0
264262
* @since 0.1.0
265263
*/
266264
handleItemShare = (item) => {
267265
const itemName = get(item, 'strings.name.en', 'N/A');
266+
const itemAbbreviation = get(item, 'strings.abbreviation.en', 'N/A');
267+
const itemSymbol = get(item, 'strings.symbol', 'N/A');
268268
const itemDescription = get(item, 'strings.description.en', 'N/A');
269269

270-
const notificationSubject = 'Unit Details';
271-
const notificationBody = `Name: ${itemName}\nDescription: ${itemDescription}\n`;
270+
const notificationSubject = 'List of Units';
271+
const notificationBody = `Name: ${itemName}\nAbbreviation: ${itemAbbreviation}\nSymbol: ${itemSymbol}\nDescription: ${itemDescription}\n`;
272272
const showNotificationForm = true;
273273

274274
this.setState({

0 commit comments

Comments
 (0)