From e92550b0465943cc1a77b839b000bb0363285db8 Mon Sep 17 00:00:00 2001 From: Casey Dyer Date: Mon, 16 Dec 2024 17:18:56 -0800 Subject: [PATCH 1/2] feat: use badge name with level in parenthesis throughout new experience --- .../MyKiva/BadgeModalContentJourney.vue | 9 +- src/components/MyKiva/EarnedBadgesSection.vue | 10 +- src/composables/useBadgeData.js | 8 +- .../Portfolio/LendingStats/BadgesList.vue | 9 +- .../specs/composables/useBadgeData.spec.js | 132 ++++++++++++++++-- 5 files changed, 142 insertions(+), 26 deletions(-) diff --git a/src/components/MyKiva/BadgeModalContentJourney.vue b/src/components/MyKiva/BadgeModalContentJourney.vue index 78678a0a88..6c1caab081 100644 --- a/src/components/MyKiva/BadgeModalContentJourney.vue +++ b/src/components/MyKiva/BadgeModalContentJourney.vue @@ -99,7 +99,7 @@ const props = defineProps({ }, }); -const { getBadgeWithVisibleTiers } = useBadgeData(); +const { getBadgeWithVisibleTiers, getTierBadgeDataByLevel } = useBadgeData(); const { isMobile } = useIsMobile(MOBILE_BREAKPOINT); @@ -145,11 +145,8 @@ const getBadgeStatus = index => { }; const getTierName = index => { - const contentfulData = badgeWithVisibleTiers.value.contentfulData[index]; - if (contentfulData.challengeName && contentfulData.levelName) { - return `${contentfulData.challengeName} ${contentfulData.levelName}`; - } - return `Level ${index + 1}`; + const levelData = getTierBadgeDataByLevel(badgeWithVisibleTiers.value, index + 1); + return levelData.tierName; }; const handleBadgeClick = index => { diff --git a/src/components/MyKiva/EarnedBadgesSection.vue b/src/components/MyKiva/EarnedBadgesSection.vue index 15331f5198..0623ed67ed 100644 --- a/src/components/MyKiva/EarnedBadgesSection.vue +++ b/src/components/MyKiva/EarnedBadgesSection.vue @@ -67,6 +67,7 @@ import { import { format } from 'date-fns'; import KvButton from '#kv-components/KvButton'; import MyKivaContainer from '#src/components/MyKiva/MyKivaContainer'; +import useBadgeData from '#src/composables/useBadgeData'; const $kvTrackEvent = inject('$kvTrackEvent'); @@ -84,6 +85,8 @@ const visibleOffset = ref(1); const { badgesData } = toRefs(props); +const { getTierBadgeDataByLevel } = useBadgeData(); + const completedBadges = computed(() => { const completedBadgesArr = []; @@ -123,11 +126,8 @@ const completedBadges = computed(() => { const visibleBadges = computed(() => completedBadges.value.slice(0, visibleLimit.value * visibleOffset.value)); const getBadgeTitle = badge => { - if (badge.level === 0) { - return badge?.contentfulData?.[0]?.challengeName ?? ''; - } - const badgeData = badge?.contentfulData?.find(data => data.level === badge.level); - return `${badgeData?.challengeName} ${badgeData?.levelName}` ?? ''; + const levelData = getTierBadgeDataByLevel(badge, badge.level); + return levelData.tierName; }; const getBadgeImgUrl = badge => { diff --git a/src/composables/useBadgeData.js b/src/composables/useBadgeData.js index 20efe5d328..4c604747b2 100644 --- a/src/composables/useBadgeData.js +++ b/src/composables/useBadgeData.js @@ -261,12 +261,18 @@ export default function useBadgeData() { const tierIndex = badge?.achievementData?.tiers?.findIndex(t => t?.level === level); const achievementData = badge?.achievementData?.tiers?.[tierIndex]; const contentfulData = badge?.contentfulData?.[tierIndex]; + const levelText = typeof contentfulData?.levelName !== 'undefined' + ? ` (level ${contentfulData?.levelName})` + : ''; return { ...badge, contentfulData, achievementData, - tierName: `${(contentfulData?.challengeName ?? '')} ${(contentfulData?.levelName ?? '')}` + // Handle both tiered and old badges (use challenge name for non-tiered) + tierName: contentfulData?.challengeName + ? `${(contentfulData.challengeName)}${levelText}` + : badge.challengeName, }; }; diff --git a/src/pages/Portfolio/LendingStats/BadgesList.vue b/src/pages/Portfolio/LendingStats/BadgesList.vue index d11ccbf87d..46156016c4 100644 --- a/src/pages/Portfolio/LendingStats/BadgesList.vue +++ b/src/pages/Portfolio/LendingStats/BadgesList.vue @@ -46,6 +46,7 @@