Skip to content

Commit

Permalink
Refactor adjust type definitions on Levels
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaHungDinh committed Apr 29, 2024
1 parent fccf425 commit 3a5fc46
Showing 1 changed file with 11 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,28 @@ import classNames from 'classnames';
type DonationAmountLevelsProps = {
name: string;
currency: string;
levels: {label: string; value: number}[];
levels: Level[];
onLevelClick?: (amount: number) => void;
};

type GroupedLevels = {
labeled: Level[];
unlabeled: Level[];
};

type Level = {label: string | null; value: number};

/**
* @unreleased add level descriptions.
* @since 3.0.0
*/
export default function DonationAmountLevels({
name,
currency,
levels,
onLevelClick,
}: DonationAmountLevelsProps) {
export default function DonationAmountLevels({name, currency, levels, onLevelClick}: DonationAmountLevelsProps) {
const {useWatch, useCurrencyFormatter} = window.givewp.form.hooks;
const amount = useWatch({name});
const formatter = useCurrencyFormatter(currency);

const groupedLevels = levels.reduce(
(acc, level) => {
const groupedLevels: GroupedLevels = levels.reduce(
(acc: GroupedLevels, level) => {
const key = level.label ? 'labeled' : 'unlabeled';
acc[key].push(level);
return acc;
Expand Down

0 comments on commit 3a5fc46

Please sign in to comment.