From 41827f0fe08994fba5d45a65e3b187d8ff242d40 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matilda=20Landstr=C3=B6m?= Date: Thu, 29 Aug 2024 14:36:26 +0200 Subject: [PATCH] feat(SW-312): fix "2-for-1-breakfast" only unlocked for level 5 --- .../OverviewTable/BenefitCard/index.tsx | 2 +- .../OverviewTable/BenefitList/index.tsx | 45 +++++++++---------- .../OverviewTable/BenefitValue/index.tsx | 2 +- .../LargeTable/DesktopHeader/index.tsx | 2 +- .../OverviewTable/LargeTable/index.tsx | 45 +++++++++---------- .../OverviewTable/LevelSummary/index.tsx | 2 +- .../DynamicContent/OverviewTable/data/DA.json | 4 +- .../DynamicContent/OverviewTable/data/DE.json | 4 +- .../DynamicContent/OverviewTable/data/EN.json | 18 ++++---- .../DynamicContent/OverviewTable/data/FI.json | 4 +- .../DynamicContent/OverviewTable/data/NO.json | 4 +- .../DynamicContent/OverviewTable/data/SV.json | 4 +- .../DynamicContent/OverviewTable/index.tsx | 4 +- types/components/loyalty/blocks.ts | 22 ++++----- utils/loyaltyTable.ts | 28 +++++++----- 15 files changed, 97 insertions(+), 93 deletions(-) diff --git a/components/Loyalty/Blocks/DynamicContent/OverviewTable/BenefitCard/index.tsx b/components/Loyalty/Blocks/DynamicContent/OverviewTable/BenefitCard/index.tsx index fe701f085..ee02753a7 100644 --- a/components/Loyalty/Blocks/DynamicContent/OverviewTable/BenefitCard/index.tsx +++ b/components/Loyalty/Blocks/DynamicContent/OverviewTable/BenefitCard/index.tsx @@ -6,7 +6,7 @@ import BenefitValue from "../BenefitValue" import styles from "./benefitCard.module.css" -import { BenefitCardProps } from "@/types/components/loyalty/blocks" +import type { BenefitCardProps } from "@/types/components/loyalty/blocks" export default function BenefitCard({ comparedValues, diff --git a/components/Loyalty/Blocks/DynamicContent/OverviewTable/BenefitList/index.tsx b/components/Loyalty/Blocks/DynamicContent/OverviewTable/BenefitList/index.tsx index a1a8ec7be..dc947bfe0 100644 --- a/components/Loyalty/Blocks/DynamicContent/OverviewTable/BenefitList/index.tsx +++ b/components/Loyalty/Blocks/DynamicContent/OverviewTable/BenefitList/index.tsx @@ -1,32 +1,31 @@ -import { getHighestLevel } from "@/utils/loyaltyTable" +import { findBenefit, getUnlockedBenefits } from "@/utils/loyaltyTable" import BenefitCard from "../BenefitCard" import styles from "./benefitList.module.css" -import { BenefitListProps } from "@/types/components/loyalty/blocks" +import type { BenefitListProps } from "@/types/components/loyalty/blocks" export default function BenefitList({ levels }: BenefitListProps) { - const highestLevel = getHighestLevel(levels) - return highestLevel?.benefits - .filter((benefit) => benefit.unlocked) - .map((benefit, idx) => { - const levelBenefits = levels.map((level) => level.benefits[idx]) - return ( -
- { - return { - key: `${benefit.name}-${idx}`, - value: benefit.value, - unlocked: benefit.unlocked, - valueDetails: benefit.valueDetails, - } - })} - /> -
- ) + return getUnlockedBenefits(levels).map((benefit) => { + const levelBenefits = levels.map((level) => { + return findBenefit(benefit, level) }) + return ( +
+ { + return { + key: `${benefit.name}-${idx}`, + value: benefit.value, + unlocked: benefit.unlocked, + valueDetails: benefit.valueDetails, + } + })} + /> +
+ ) + }) } diff --git a/components/Loyalty/Blocks/DynamicContent/OverviewTable/BenefitValue/index.tsx b/components/Loyalty/Blocks/DynamicContent/OverviewTable/BenefitValue/index.tsx index 052c80dca..e22b8f70e 100644 --- a/components/Loyalty/Blocks/DynamicContent/OverviewTable/BenefitValue/index.tsx +++ b/components/Loyalty/Blocks/DynamicContent/OverviewTable/BenefitValue/index.tsx @@ -4,7 +4,7 @@ import CheckCircle from "@/components/Icons/CheckCircle" import styles from "./benefitValue.module.css" -import { BenefitValueProps } from "@/types/components/loyalty/blocks" +import type { BenefitValueProps } from "@/types/components/loyalty/blocks" export default function BenefitValue({ benefit }: BenefitValueProps) { if (!benefit.unlocked) { diff --git a/components/Loyalty/Blocks/DynamicContent/OverviewTable/LargeTable/DesktopHeader/index.tsx b/components/Loyalty/Blocks/DynamicContent/OverviewTable/LargeTable/DesktopHeader/index.tsx index e4eb196fb..edb176eba 100644 --- a/components/Loyalty/Blocks/DynamicContent/OverviewTable/LargeTable/DesktopHeader/index.tsx +++ b/components/Loyalty/Blocks/DynamicContent/OverviewTable/LargeTable/DesktopHeader/index.tsx @@ -5,7 +5,7 @@ import YourLevel from "../../YourLevelScript" import styles from "./desktopHeader.module.css" -import { +import type { DesktopSelectColumns, LargeTableProps, } from "@/types/components/loyalty/blocks" diff --git a/components/Loyalty/Blocks/DynamicContent/OverviewTable/LargeTable/index.tsx b/components/Loyalty/Blocks/DynamicContent/OverviewTable/LargeTable/index.tsx index 69c53783b..5c3566cd8 100644 --- a/components/Loyalty/Blocks/DynamicContent/OverviewTable/LargeTable/index.tsx +++ b/components/Loyalty/Blocks/DynamicContent/OverviewTable/LargeTable/index.tsx @@ -1,14 +1,14 @@ import { ChevronDown } from "react-feather" import Title from "@/components/TempDesignSystem/Text/Title" -import { getHighestLevel } from "@/utils/loyaltyTable" +import { findBenefit, getUnlockedBenefits } from "@/utils/loyaltyTable" import BenefitValue from "../BenefitValue" import DesktopHeader from "./DesktopHeader" import styles from "./largeTable.module.css" -import { +import type { BenefitTableHeaderProps, LargeTableProps, } from "@/types/components/loyalty/blocks" @@ -18,7 +18,6 @@ export default function LargeTable({ activeLevel, Select, }: LargeTableProps) { - const highestLevel = getHighestLevel(levels) return ( - {highestLevel?.benefits - .filter((benefit) => benefit.unlocked) - .map((benefit, index) => { - return ( - - - {levels.map((level, idx) => { - return ( - - ) - })} - - ) - })} + {getUnlockedBenefits(levels).map((benefit) => { + return ( + + + {levels.map((level, idx) => { + return ( + + ) + })} + + ) + })}
- - - -
+ + + +
) diff --git a/components/Loyalty/Blocks/DynamicContent/OverviewTable/LevelSummary/index.tsx b/components/Loyalty/Blocks/DynamicContent/OverviewTable/LevelSummary/index.tsx index 122e2fd2b..153ba1f11 100644 --- a/components/Loyalty/Blocks/DynamicContent/OverviewTable/LevelSummary/index.tsx +++ b/components/Loyalty/Blocks/DynamicContent/OverviewTable/LevelSummary/index.tsx @@ -1,6 +1,6 @@ import styles from "./levelSummary.module.css" -import { LevelSummaryProps } from "@/types/components/loyalty/blocks" +import type { LevelSummaryProps } from "@/types/components/loyalty/blocks" export default function LevelSummary({ level, diff --git a/components/Loyalty/Blocks/DynamicContent/OverviewTable/data/DA.json b/components/Loyalty/Blocks/DynamicContent/OverviewTable/data/DA.json index 8c10a14fc..551d46b58 100644 --- a/components/Loyalty/Blocks/DynamicContent/OverviewTable/data/DA.json +++ b/components/Loyalty/Blocks/DynamicContent/OverviewTable/data/DA.json @@ -433,7 +433,7 @@ { "name": "2-for-1 morgenmad", "description": "Uanset om du overnatter hos os eller ej, kan du invitere en ven på morgenmad, for I kan spise for to personer og kun betale for én! Men husk, at tjekke detaljerne først, så alt er klar til et hyggeligt morgenmøde.", - "unlocked": true + "unlocked": false }, { "name": "48-timers værelsesgaranti", @@ -510,7 +510,7 @@ { "name": "2-for-1 morgenmad", "description": "Uanset om du overnatter hos os eller ej, kan du invitere en ven på morgenmad, for I kan spise for to personer og kun betale for én! Men husk, at tjekke detaljerne først, så alt er klar til et hyggeligt morgenmøde.", - "unlocked": true + "unlocked": false }, { "name": "48-timers værelsesgaranti", diff --git a/components/Loyalty/Blocks/DynamicContent/OverviewTable/data/DE.json b/components/Loyalty/Blocks/DynamicContent/OverviewTable/data/DE.json index 820c6d38c..5d11c6a36 100644 --- a/components/Loyalty/Blocks/DynamicContent/OverviewTable/data/DE.json +++ b/components/Loyalty/Blocks/DynamicContent/OverviewTable/data/DE.json @@ -433,7 +433,7 @@ { "name": "Frühstück für zwei zum Preis von einem", "description": "Wenn das kein delikater Deal ist: Egal, ob Sie bei uns übernachten oder nicht, schnappen Sie sich einen Frühstückspartner, denn jetzt können Sie zu zweit zum Preis von einem bei uns essen! Informieren Sie sich einfach vorher über alle Details und genießen Sie ein gemütliches Frühstück zu zweit.", - "unlocked": true + "unlocked": false }, { "name": "48-Stunden-Zimmergarantie", @@ -510,7 +510,7 @@ { "name": "Frühstück für zwei zum Preis von einem", "description": "Wenn das kein delikater Deal ist: Egal, ob Sie bei uns übernachten oder nicht, schnappen Sie sich einen Frühstückspartner, denn jetzt können Sie zu zweit zum Preis von einem bei uns essen! Informieren Sie sich einfach vorher über alle Details und genießen Sie ein gemütliches Frühstück zu zweit.", - "unlocked": true + "unlocked": false }, { "name": "48-Stunden-Zimmergarantie", diff --git a/components/Loyalty/Blocks/DynamicContent/OverviewTable/data/EN.json b/components/Loyalty/Blocks/DynamicContent/OverviewTable/data/EN.json index 475477999..b791a6e60 100644 --- a/components/Loyalty/Blocks/DynamicContent/OverviewTable/data/EN.json +++ b/components/Loyalty/Blocks/DynamicContent/OverviewTable/data/EN.json @@ -35,7 +35,7 @@ }, { "name": "Friendship point boost", - "description": "Now here’s something pretty sweet: every time you get a boost of friendship points, you get 25% or 50% extra – a boost on the boost! So you know, start racking up those points on stays, meals and more and you’ll get a free night in no time.", + "description": "Now here’s something pretty sweet: every time you get a boost of friendship points, you get 25% or 50% extra – a boost! So you know, start racking up those points on stays, meals and more and you’ll get a free night in no time.", "unlocked": false }, { @@ -110,7 +110,7 @@ }, { "name": "Friendship point boost", - "description": "Now here’s something pretty sweet: every time you get a boost of friendship points, you get 25% or 50% extra – a boost on the boost! So you know, start racking up those points on stays, meals and more and you’ll get a free night in no time.", + "description": "Now here’s something pretty sweet: every time you get a boost of friendship points, you get 25% or 50% extra – a boost! So you know, start racking up those points on stays, meals and more and you’ll get a free night in no time.", "unlocked": false }, { @@ -186,7 +186,7 @@ }, { "name": "Friendship point boost", - "description": "Now here’s something pretty sweet: every time you get a boost of friendship points, you get 25% or 50% extra – a boost on the boost! So you know, start racking up those points on stays, meals and more and you’ll get a free night in no time.", + "description": "Now here’s something pretty sweet: every time you get a boost of friendship points, you get 25% or 50% extra – a boost! So you know, start racking up those points on stays, meals and more and you’ll get a free night in no time.", "unlocked": false }, { @@ -262,7 +262,7 @@ }, { "name": "Friendship point boost", - "description": "Now here’s something pretty sweet: every time you get a boost of friendship points, you get 25% or 50% extra – a boost on the boost! So you know, start racking up those points on stays, meals and more and you’ll get a free night in no time.", + "description": "Now here’s something pretty sweet: every time you get a boost of friendship points, you get 25% or 50% extra – a boost! So you know, start racking up those points on stays, meals and more and you’ll get a free night in no time.", "unlocked": true, "value": "+25%" }, @@ -339,7 +339,7 @@ }, { "name": "Friendship point boost", - "description": "Now here’s something pretty sweet: every time you get a boost of friendship points, you get 25% or 50% extra – a boost on the boost! So you know, start racking up those points on stays, meals and more and you’ll get a free night in no time.", + "description": "Now here’s something pretty sweet: every time you get a boost of friendship points, you get 25% or 50% extra – a boost! So you know, start racking up those points on stays, meals and more and you’ll get a free night in no time.", "unlocked": true, "value": "+25%" }, @@ -416,7 +416,7 @@ }, { "name": "Friendship point boost", - "description": "Now here’s something pretty sweet: every time you get a boost of friendship points, you get 25% or 50% extra – a boost on the boost! So you know, start racking up those points on stays, meals and more and you’ll get a free night in no time.", + "description": "Now here’s something pretty sweet: every time you get a boost of friendship points, you get 25% or 50% extra – a boost! So you know, start racking up those points on stays, meals and more and you’ll get a free night in no time.", "unlocked": true, "value": "+50%" }, @@ -433,7 +433,7 @@ { "name": "2-for-1 breakfast", "description": "Now, this is a delicious deal: regardless if you’re staying with us or not, go grab a breakfast buddy because you're eating two for the price of one! Just make sure to check the details first so everything is in place for your yummy get-together.", - "unlocked": true + "unlocked": false }, { "name": "48hr room guarantee", @@ -493,7 +493,7 @@ }, { "name": "Friendship point boost", - "description": "Now here’s something pretty sweet: every time you get a boost of friendship points, you get 25% or 50% extra – a boost on the boost! So you know, start racking up those points on stays, meals and more and you’ll get a free night in no time.", + "description": "Now here’s something pretty sweet: every time you get a boost of friendship points, you get 25% or 50% extra – a boost! So you know, start racking up those points on stays, meals and more and you’ll get a free night in no time.", "unlocked": true, "value": "+50%" }, @@ -510,7 +510,7 @@ { "name": "2-for-1 breakfast", "description": "Now, this is a delicious deal: regardless if you’re staying with us or not, go grab a breakfast buddy because you're eating two for the price of one! Just make sure to check the details first so everything is in place for your yummy get-together.", - "unlocked": true + "unlocked": false }, { "name": "48hr room guarantee", diff --git a/components/Loyalty/Blocks/DynamicContent/OverviewTable/data/FI.json b/components/Loyalty/Blocks/DynamicContent/OverviewTable/data/FI.json index 11df9e8ff..d1aa3ee98 100644 --- a/components/Loyalty/Blocks/DynamicContent/OverviewTable/data/FI.json +++ b/components/Loyalty/Blocks/DynamicContent/OverviewTable/data/FI.json @@ -433,7 +433,7 @@ { "name": "Aamiainen – kaksi yhden hinnalla", "description": "Saat kaksi aamiaista yhden hinnalla, majoitut meillä tai et.", - "unlocked": true + "unlocked": false }, { "name": "48 tunnin huonetakuu", @@ -510,7 +510,7 @@ { "name": "Aamiainen – kaksi yhden hinnalla", "description": "Saat kaksi aamiaista yhden hinnalla, majoitut meillä tai et.", - "unlocked": true + "unlocked": false }, { "name": "48 tunnin huonetakuu", diff --git a/components/Loyalty/Blocks/DynamicContent/OverviewTable/data/NO.json b/components/Loyalty/Blocks/DynamicContent/OverviewTable/data/NO.json index 52cfdc49a..fbe79e466 100644 --- a/components/Loyalty/Blocks/DynamicContent/OverviewTable/data/NO.json +++ b/components/Loyalty/Blocks/DynamicContent/OverviewTable/data/NO.json @@ -433,7 +433,7 @@ { "name": "2-for-1 frokost", "description": "Dette er virkelig et deilig tilbud: Uavhengig om du bor hos oss eller ikke, finn deg en frokostkompis, og dere kan spise for prisen av én! Bare sørg for å sjekke detaljene først, slik at alt er på plass for deres smakfulle sammenkomst.", - "unlocked": true + "unlocked": false }, { "name": "Romgaranti i 48 timer", @@ -510,7 +510,7 @@ { "name": "2-for-1 frokost", "description": "Dette er virkelig et deilig tilbud: Uavhengig om du bor hos oss eller ikke, finn deg en frokostkompis, og dere kan spise for prisen av én! Bare sørg for å sjekke detaljene først, slik at alt er på plass for deres smakfulle sammenkomst.", - "unlocked": true + "unlocked": false }, { "name": "Romgaranti i 48 timer", diff --git a/components/Loyalty/Blocks/DynamicContent/OverviewTable/data/SV.json b/components/Loyalty/Blocks/DynamicContent/OverviewTable/data/SV.json index e226f487a..7e7b10b35 100644 --- a/components/Loyalty/Blocks/DynamicContent/OverviewTable/data/SV.json +++ b/components/Loyalty/Blocks/DynamicContent/OverviewTable/data/SV.json @@ -433,7 +433,7 @@ { "name": "Frukost 2 för 1", "description": "Okej, nu snackar vi. Oavsett om du bor hos oss eller inte, ta med en frukostkompis eftersom du äter två frukostar till priset av en! Kom bara ihåg att dubbelkolla detaljerna först så att allt är i sin ordning för en maxad frukost.", - "unlocked": true + "unlocked": false }, { "name": "48 timmars rumsgaranti", @@ -510,7 +510,7 @@ { "name": "Frukost 2 för 1", "description": "Okej, nu snackar vi. Oavsett om du bor hos oss eller inte, ta med en frukostkompis eftersom du äter två frukostar till priset av en! Kom bara ihåg att dubbelkolla detaljerna först så att allt är i sin ordning för en maxad frukost.", - "unlocked": true + "unlocked": false }, { "name": "48 timmars rumsgaranti", diff --git a/components/Loyalty/Blocks/DynamicContent/OverviewTable/index.tsx b/components/Loyalty/Blocks/DynamicContent/OverviewTable/index.tsx index 48c20bc6e..044043b08 100644 --- a/components/Loyalty/Blocks/DynamicContent/OverviewTable/index.tsx +++ b/components/Loyalty/Blocks/DynamicContent/OverviewTable/index.tsx @@ -29,9 +29,9 @@ import type { Key } from "react-aria-components" import { ComparisonLevel, DesktopSelectColumns, - MobileColumnHeaderProps, + type MobileColumnHeaderProps, overviewTableActionsEnum, - OverviewTableProps, + type OverviewTableProps, OverviewTableReducerAction, } from "@/types/components/loyalty/blocks" import type { User } from "@/types/user" diff --git a/types/components/loyalty/blocks.ts b/types/components/loyalty/blocks.ts index c8db57354..f0664b6ed 100644 --- a/types/components/loyalty/blocks.ts +++ b/types/components/loyalty/blocks.ts @@ -30,7 +30,7 @@ export type CardsGridProps = Pick & { export type Content = { content: RteBlockContent["content"]["content"] } -type Benefit = { title: string } +type BenefitTitle = { title: string } export type OverviewTableProps = { activeMembership: MembershipLevel | null } @@ -39,7 +39,7 @@ export type Level = { name: string requiredPoints: number requiredNights?: number - benefits: Benefit[] + benefits: BenefitTitle[] } export type LevelCardProps = { @@ -54,15 +54,15 @@ export type ComparisonLevel = { description: string requirement: string icon: string - benefits: [ - { - name: string - description: string - unlocked: boolean - value?: string - valueDetails?: string - }, - ] + benefits: Benefit[] +} + +export type Benefit = { + name: string + description: string + unlocked: boolean + value?: string + valueDetails?: string } export type LevelSummaryProps = { diff --git a/utils/loyaltyTable.ts b/utils/loyaltyTable.ts index f8c4fed04..996a2a7a4 100644 --- a/utils/loyaltyTable.ts +++ b/utils/loyaltyTable.ts @@ -1,13 +1,21 @@ -import { ComparisonLevel } from "@/types/components/loyalty/blocks" +import type { + Benefit, + ComparisonLevel, +} from "@/types/components/loyalty/blocks" -export function getHighestLevel(levels: ComparisonLevel[]) { - return levels.reduce( - (acc: ComparisonLevel | null, level: ComparisonLevel) => { - if (!acc) { - return level - } - return level.level > acc.level ? level : acc - }, - null +export function getUnlockedBenefits(levels: ComparisonLevel[]) { + const allBenefits = levels + .map((level) => { + return level.benefits.filter((benefit) => benefit.unlocked) + }) + .flat() + + /* Remove duplicate benefits based on the name property */ + return Array.from( + new Map(allBenefits.map((benefit) => [benefit.name, benefit])).values() ) } + +export function findBenefit(benefit: Benefit, level: ComparisonLevel) { + return level.benefits.find((b) => b.name === benefit.name) as Benefit +}