← All changes
|
backend/views/components/Main/utilities/utilities.js
+29
-4
1.3.50
→
1.4.19
View file →
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | import { __ } from '@wordpress/i18n'; |
| 2 | -import moment from 'moment'; | |
| 2 | +import { format } from 'date-fns'; | |
| 3 | 3 | import { toast } from 'react-toastify'; |
| 4 | 4 | |
| 5 | 5 | export const getSelectedFilterData = (items, current) => { |
| 6 | 6 | let value = {}; |
| @@ -13,13 +13,13 @@ | ||
| 13 | 13 | return value; |
| 14 | 14 | }; |
| 15 | 15 | |
| 16 | 16 | export const dateTimeFormatter = (datetime) => { |
| 17 | - if (datetime) { | |
| 18 | - return moment(datetime).format('Do MMM, YYYY h:mm A'); | |
| 19 | - } else { | |
| 17 | + if (!datetime) { | |
| 20 | 18 | return '-'; |
| 21 | 19 | } |
| 20 | + | |
| 21 | + return format(new Date(datetime), 'do MMM, yyyy h:mm a'); | |
| 22 | 22 | }; |
| 23 | 23 | |
| 24 | 24 | export const dateStringToTimestamp = (dateString) => { |
| 25 | 25 | const date = new Date(dateString); |
| @@ -336,4 +336,29 @@ | ||
| 336 | 336 | return str.slice(0, maxLength) + '...'; |
| 337 | 337 | } |
| 338 | 338 | return str; |
| 339 | 339 | } |
| 340 | + | |
| 341 | +/** | |
| 342 | + * | |
| 343 | + * @param {String} rawText | |
| 344 | + * @returns {String} | |
| 345 | + */ | |
| 346 | +export const renderBadgeText = (rawText) => { | |
| 347 | + const text = typeof rawText === 'string' ? rawText : ''; | |
| 348 | + return text | |
| 349 | + .replace(/\[discounted_percentage\]/g, '20%') | |
| 350 | + .replace(/\[discounted_amount\]/g, '$10') | |
| 351 | + .replace(/\[remaining_quantity\]/g, '5') | |
| 352 | + .replace(/\[remaining_amount\]/g, '$50') | |
| 353 | + .replace(/\[remaining_cart_items\]/g, '2'); | |
| 354 | +}; | |
| 355 | + | |
| 356 | +/** | |
| 357 | + * | |
| 358 | + * @param {Object} radius | |
| 359 | + * @returns {String} | |
| 360 | + */ | |
| 361 | +export const getBorderRadius = (radius) => { | |
| 362 | + if (!radius) return undefined; | |
| 363 | + return `${radius['top-left'] || '0px'} ${radius['top-right'] || '0px'} ${radius['bottom-right'] || '0px'} ${radius['bottom-left'] || '0px'}`; | |
| 364 | +}; | |