Skip to content

Commit

Permalink
Merge pull request #41 from the-collab-lab/ym-urgency-label-fix
Browse files Browse the repository at this point in the history
fix: address conditional logic to render inactive list items
  • Loading branch information
yiremorlans committed May 25, 2023
2 parents fe6136e + 43843fd commit 0a186c1
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions src/components/ListItem.jsx
Expand Up @@ -36,19 +36,31 @@ export function ListItem({ item, listId }) {
}, [checked, item.dateLastPurchased]);

const purchaseUrgencyMessage = (item) => {
const dateLastPurchased = item.dateLastPurchased
? item.dateLastPurchased
: item.dateCreated;

const itemDays = getDaysBetweenDates(
transformToJSDate(item.dateNextPurchased),
new Date(),
);
const dateLastPurchased = item.dateLastPurchased;

if (itemDays <= 7) {
const itemDaysSinceLastPurchased = getDaysBetweenDates(
transformToJSDate(dateLastPurchased),
new Date(),
);

if (
itemDays <= 7 ||
(transformToJSDate(item.dateNextPurchased) < new Date() &&
itemDaysSinceLastPurchased < 60)
) {
return 'S';
} else if (itemDays > 7 && itemDays < 30) {
return 'KS';
} else if (itemDays >= 30 && itemDays < 60) {
return 'NS';
} else if (itemDays > 60 && !dateLastPurchased) {
} else {
return 'I';
}
};
Expand Down

0 comments on commit 0a186c1

Please sign in to comment.