From 52b927b684ea4033fe7030e397de7d27e7480feb Mon Sep 17 00:00:00 2001 From: Arvid Norlin Date: Fri, 24 May 2024 15:23:29 +0200 Subject: [PATCH] extract BenefitCard component --- .../OverviewTable/BenefitCard.tsx | 64 +++++++++++++++ .../DynamicContent/OverviewTable/index.tsx | 81 +++---------------- 2 files changed, 76 insertions(+), 69 deletions(-) create mode 100644 components/Loyalty/Blocks/DynamicContent/OverviewTable/BenefitCard.tsx diff --git a/components/Loyalty/Blocks/DynamicContent/OverviewTable/BenefitCard.tsx b/components/Loyalty/Blocks/DynamicContent/OverviewTable/BenefitCard.tsx new file mode 100644 index 000000000..256f205d3 --- /dev/null +++ b/components/Loyalty/Blocks/DynamicContent/OverviewTable/BenefitCard.tsx @@ -0,0 +1,64 @@ +import { ChevronDown, Minus } from "react-feather" + +import CheckCircle from "@/components/Icons/CheckCircle" +import Title from "@/components/Title" + +import styles from "./overviewTable.module.css" + +import { + BenefitCardProps, + BenefitValueProps, +} from "@/types/components/loyalty/blocks" + +function BenefitValue({ benefit }: BenefitValueProps) { + if (!benefit.unlocked) { + return + } + if (!benefit.value) { + return + } + return ( +
+ {benefit.value} + {benefit.valueDetails && ( + + {benefit.valueDetails} + + )} +
+ ) +} + +export default function BenefitCard({ + comparedValues, + title, + description, +}: BenefitCardProps) { + return ( +
+
+
+ +
+ + {title} + + + + +
+
+

{description}

+
+
+
+
+ +
+
+ +
+
+
+ ) +} diff --git a/components/Loyalty/Blocks/DynamicContent/OverviewTable/index.tsx b/components/Loyalty/Blocks/DynamicContent/OverviewTable/index.tsx index 796733837..fbe937b7a 100644 --- a/components/Loyalty/Blocks/DynamicContent/OverviewTable/index.tsx +++ b/components/Loyalty/Blocks/DynamicContent/OverviewTable/index.tsx @@ -1,25 +1,21 @@ "use client" -import { Fragment, useState } from "react" +import { Dispatch, Fragment, SetStateAction, useState } from "react" import { type Key } from "react-aria-components" -import { Minus } from "react-feather" import { Lang } from "@/constants/languages" import { _ } from "@/lib/translation" -import CheckCircle from "@/components/Icons/CheckCircle" -import ChevronDown from "@/components/Icons/ChevronDown" import Image from "@/components/Image" import Select from "@/components/TempDesignSystem/Form/Select" import Title from "@/components/Title" import levelsData from "./data/EN.json" +import BenefitCard from "./BenefitCard" import styles from "./overviewTable.module.css" import { - BenefitCardProps, - BenefitValueProps, ComparisonLevel, LevelSummaryProps, OverviewTableTitleProps, @@ -115,18 +111,14 @@ export default function OverviewTable() { const [selectedLevelA, setSelectedLevelA] = useState(getLevelByTier(1)) const [selectedLevelB, setSelectedLevelB] = useState(getLevelByTier(2)) - // TODO Come up with a nice wat to make these two a single reusable function - function handleSelectChangeA(key: Key) { - if (typeof key === "number") { - const level = getLevelByTier(key) - setSelectedLevelA(level) - } - } - - function handleSelectChangeB(key: Key) { - if (typeof key === "number") { - const level = getLevelByTier(key) - setSelectedLevelB(level) + function handleSelectChange( + callback: Dispatch> + ) { + return (key: Key) => { + if (typeof key === "number") { + const level = getLevelByTier(key) + callback(level) + } } } @@ -157,7 +149,7 @@ export default function OverviewTable() { label={"Level"} items={levelOptions} defaultSelectedKey={selectedLevelA.tier} - onSelect={handleSelectChangeA} + onSelect={handleSelectChange(setSelectedLevelA)} /> ) } - -function BenefitCard({ comparedValues, title, description }: BenefitCardProps) { - return ( -
-
-
- -
- - {title} - - - - -
-
-

{description}

-
-
-
-
- -
-
- -
-
-
- ) -} - -function BenefitValue({ benefit }: BenefitValueProps) { - if (!benefit.unlocked) { - return - } - if (!benefit.value) { - return - } - return ( -
- {benefit.value} - {benefit.valueDetails && ( - - {benefit.valueDetails} - - )} -
- ) -}