From 82dda9ba223080b2c8b8adff741ba6754b9b621c Mon Sep 17 00:00:00 2001 From: iamsivin Date: Fri, 15 Mar 2024 19:38:24 +0530 Subject: [PATCH] chore: Review fix --- .../dashboard/helper/snoozeHelpers.js | 24 ++++++++++++------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/app/javascript/dashboard/helper/snoozeHelpers.js b/app/javascript/dashboard/helper/snoozeHelpers.js index 76010b868..e51ef63e6 100644 --- a/app/javascript/dashboard/helper/snoozeHelpers.js +++ b/app/javascript/dashboard/helper/snoozeHelpers.js @@ -73,16 +73,22 @@ export const shortenSnoozeTime = snoozedUntil => { if (!snoozedUntil) { return null; } + const unitMap = { + minutes: 'm', + minute: 'm', + hours: 'h', + hour: 'h', + days: 'd', + day: 'd', + months: 'mo', + month: 'mo', + years: 'y', + year: 'y', + }; const shortenTime = snoozedUntil.replace( - /( minutes?| hours?| days?| months?| years?)/g, - (match, unitMatch) => { - if (unitMatch === ' minutes' || unitMatch === ' minute') return 'm'; - if (unitMatch === ' hours' || unitMatch === ' hour') return 'h'; - if (unitMatch === ' days' || unitMatch === ' day') return 'd'; - if (unitMatch === ' months' || unitMatch === ' month') return 'mo'; - if (unitMatch === ' years' || unitMatch === ' year') return 'y'; - return match; - } + /\s(minute|hour|day|month|year)s?\b/gi, + (match, unit) => unitMap[unit.toLowerCase()] || match ); + return shortenTime; };